Skip to content

Commit 65d39ee

Browse files
Dave SparksAndroid (Google) Code Review
authored andcommitted
Merge "DO NOT MERGE: Prefill the cache before trying to instantiate the media extractor." into gingerbread
2 parents 822d4ce + a2ab9aa commit 65d39ee

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

media/libstagefright/AwesomePlayer.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace android {
5353

5454
static int64_t kLowWaterMarkUs = 2000000ll; // 2secs
5555
static int64_t kHighWaterMarkUs = 10000000ll; // 10secs
56+
static const size_t kLowWaterMarkBytes = 40000;
57+
static const size_t kHighWaterMarkBytes = 200000;
5658

5759
struct AwesomeEvent : public TimedEventQueue::Event {
5860
AwesomeEvent(
@@ -589,9 +591,6 @@ void AwesomePlayer::onBufferingUpdate() {
589591
// We don't know the bitrate of the stream, use absolute size
590592
// limits to maintain the cache.
591593

592-
const size_t kLowWaterMarkBytes = 40000;
593-
const size_t kHighWaterMarkBytes = 200000;
594-
595594
if ((mFlags & PLAYING) && !eos
596595
&& (cachedDataRemaining < kLowWaterMarkBytes)) {
597596
LOGI("cache is running low (< %d) , pausing.",
@@ -1478,6 +1477,34 @@ status_t AwesomePlayer::finishSetDataSource_l() {
14781477
mConnectingDataSource.clear();
14791478

14801479
dataSource = mCachedSource;
1480+
1481+
// We're going to prefill the cache before trying to instantiate
1482+
// the extractor below, as the latter is an operation that otherwise
1483+
// could block on the datasource for a significant amount of time.
1484+
// During that time we'd be unable to abort the preparation phase
1485+
// without this prefill.
1486+
1487+
mLock.unlock();
1488+
1489+
for (;;) {
1490+
bool eos;
1491+
size_t cachedDataRemaining =
1492+
mCachedSource->approxDataRemaining(&eos);
1493+
1494+
if (eos || cachedDataRemaining >= kHighWaterMarkBytes
1495+
|| (mFlags & PREPARE_CANCELLED)) {
1496+
break;
1497+
}
1498+
1499+
usleep(200000);
1500+
}
1501+
1502+
mLock.lock();
1503+
1504+
if (mFlags & PREPARE_CANCELLED) {
1505+
LOGI("Prepare cancelled while waiting for initial cache fill.");
1506+
return UNKNOWN_ERROR;
1507+
}
14811508
} else if (!strncasecmp(mUri.string(), "httplive://", 11)) {
14821509
String8 uri("http://");
14831510
uri.append(mUri.string() + 11);

media/libstagefright/NuCachedSource2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
//#define LOG_NDEBUG 0
1718
#define LOG_TAG "NuCachedSource2"
1819
#include <utils/Log.h>
1920

0 commit comments

Comments
 (0)