summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/Prefetcher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/Prefetcher.cpp')
-rw-r--r--media/libstagefright/Prefetcher.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/media/libstagefright/Prefetcher.cpp b/media/libstagefright/Prefetcher.cpp
index 862998a..835e167 100644
--- a/media/libstagefright/Prefetcher.cpp
+++ b/media/libstagefright/Prefetcher.cpp
@@ -171,7 +171,7 @@ void Prefetcher::threadFunc() {
}
}
-int64_t Prefetcher::getCachedDurationUs() {
+int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) {
Mutex::Autolock autoLock(mLock);
int64_t minCacheDurationUs = -1;
@@ -197,9 +197,25 @@ int64_t Prefetcher::getCachedDurationUs() {
}
}
+ if (noMoreData) {
+ *noMoreData = minCacheDurationUs < 0;
+ }
+
return minCacheDurationUs < 0 ? 0 : minCacheDurationUs;
}
+status_t Prefetcher::prepare() {
+ // Buffer about 2 secs worth of data on prepare.
+
+ int64_t duration;
+ bool noMoreData;
+ do {
+ duration = getCachedDurationUs(&noMoreData);
+ } while (!noMoreData && duration < 2000000);
+
+ return OK;
+}
+
////////////////////////////////////////////////////////////////////////////////
PrefetchedSource::PrefetchedSource(
@@ -232,15 +248,6 @@ status_t PrefetchedSource::start(MetaData *params) {
mStarted = true;
- for (;;) {
- // Buffer 2 secs on startup.
- if (mReachedEOS || mCacheDurationUs > 2000000) {
- break;
- }
-
- mCondition.wait(mLock);
- }
-
return OK;
}