@@ -53,6 +53,8 @@ namespace android {
5353
5454static int64_t kLowWaterMarkUs = 2000000ll ; // 2secs
5555static int64_t kHighWaterMarkUs = 10000000ll ; // 10secs
56+ static const size_t kLowWaterMarkBytes = 40000 ;
57+ static const size_t kHighWaterMarkBytes = 200000 ;
5658
5759struct 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 );
0 commit comments