summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-03-08 16:02:16 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-08 16:02:16 -0800
commit147113ee54e18094d3a8829c37a1041ec0e9dd7c (patch)
tree1cf82d18047171167f8ec5a32cd19e4b4ffd2fba /media
parent156c43545529fb3d731ffdd9c4514d38758e3f06 (diff)
parentdc9927d4641066fc966c9c69856167b8410abf90 (diff)
downloadframeworks_base-147113ee54e18094d3a8829c37a1041ec0e9dd7c.zip
frameworks_base-147113ee54e18094d3a8829c37a1041ec0e9dd7c.tar.gz
frameworks_base-147113ee54e18094d3a8829c37a1041ec0e9dd7c.tar.bz2
Merge "The audio track was accidentally not participating in the prefetch since it wasn't started at the time prepare() was called. Also, properly report the cached duration even near the end when the source has no more data to fetch."
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/AudioPlayer.cpp11
-rw-r--r--media/libstagefright/AwesomePlayer.cpp11
-rw-r--r--media/libstagefright/Prefetcher.cpp15
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;
}