diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/AudioPlayer.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/Prefetcher.cpp | 15 |
3 files changed, 24 insertions, 13 deletions
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp index 5e6e0da..005c64a 100644 --- a/media/libstagefright/AudioPlayer.cpp +++ b/media/libstagefright/AudioPlayer.cpp @@ -55,14 +55,17 @@ void AudioPlayer::setSource(const sp<MediaSource> &source) { mSource = source; } -status_t AudioPlayer::start() { +status_t AudioPlayer::start(bool sourceAlreadyStarted) { CHECK(!mStarted); CHECK(mSource != NULL); - status_t err = mSource->start(); + status_t err; + if (!sourceAlreadyStarted) { + err = mSource->start(); - if (err != OK) { - return err; + if (err != OK) { + return err; + } } sp<MetaData> format = mSource->getFormat(); diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index b8a50bf..e00ba47 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -410,6 +410,9 @@ void AwesomePlayer::onBufferingUpdate() { if (mDurationUs >= 0) { int64_t cachedDurationUs = mPrefetcher->getCachedDurationUs(); + + LOGV("cache holds %.2f secs worth of data.", cachedDurationUs / 1E6); + int64_t positionUs = 0; if (mVideoSource != NULL) { positionUs = mVideoTimeUs; @@ -486,7 +489,11 @@ status_t AwesomePlayer::play_l() { if (mAudioSink != NULL) { mAudioPlayer = new AudioPlayer(mAudioSink); mAudioPlayer->setSource(mAudioSource); - status_t err = mAudioPlayer->start(); + + // We've already started the MediaSource in order to enable + // the prefetcher to read its data. + status_t err = mAudioPlayer->start( + true /* sourceAlreadyStarted */); if (err != OK) { delete mAudioPlayer; @@ -734,6 +741,8 @@ status_t AwesomePlayer::initAudioDecoder() { } } + mAudioSource->start(); + return mAudioSource != NULL ? OK : UNKNOWN_ERROR; } diff --git a/media/libstagefright/Prefetcher.cpp b/media/libstagefright/Prefetcher.cpp index 493570a..debb60d 100644 --- a/media/libstagefright/Prefetcher.cpp +++ b/media/libstagefright/Prefetcher.cpp @@ -195,6 +195,7 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) { int64_t minCacheDurationUs = -1; ssize_t minIndex = -1; + bool anySourceActive = false; for (size_t i = 0; i < mSources.size(); ++i) { int64_t cacheDurationUs; sp<PrefetchedSource> source = mSources[i].promote(); @@ -202,8 +203,8 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) { continue; } - if (!source->getCacheDurationUs(&cacheDurationUs)) { - continue; + if (source->getCacheDurationUs(&cacheDurationUs)) { + anySourceActive = true; } if (minIndex < 0 || cacheDurationUs < minCacheDurationUs) { @@ -213,7 +214,7 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) { } if (noMoreData) { - *noMoreData = minCacheDurationUs < 0; + *noMoreData = !anySourceActive; } return minCacheDurationUs < 0 ? 0 : minCacheDurationUs; @@ -226,7 +227,7 @@ status_t Prefetcher::prepare() { bool noMoreData; do { duration = getCachedDurationUs(&noMoreData); - } while (!noMoreData && duration < kMaxCacheDurationUs); + } while (!noMoreData && duration < 2000000ll); return OK; } @@ -326,14 +327,12 @@ sp<MetaData> PrefetchedSource::getFormat() { bool PrefetchedSource::getCacheDurationUs(int64_t *durationUs) { Mutex::Autolock autoLock(mLock); - if (!mStarted || mReachedEOS) { - *durationUs = 0; + *durationUs = mCacheDurationUs; + if (!mStarted || mReachedEOS) { return false; } - *durationUs = mCacheDurationUs; - return true; } |