diff options
author | Andreas Huber <andih@google.com> | 2011-04-19 10:42:19 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-04-19 10:42:19 -0700 |
commit | 3114899e00710afbb1840619f54743157d55b5ea (patch) | |
tree | 5643267490497e7eabb4e393d5ac9e9b0938117d | |
parent | 25641ca1ac5b09727f86fe01389877332a00455d (diff) | |
parent | bb32a94fb40779bb3e02dcdefc1294e6d7a73faa (diff) | |
download | frameworks_base-3114899e00710afbb1840619f54743157d55b5ea.zip frameworks_base-3114899e00710afbb1840619f54743157d55b5ea.tar.gz frameworks_base-3114899e00710afbb1840619f54743157d55b5ea.tar.bz2 |
Merge "Make sure a read restarts the prefetcher if necessary."
-rw-r--r-- | media/libstagefright/NuCachedSource2.cpp | 24 | ||||
-rw-r--r-- | media/libstagefright/include/NuCachedSource2.h | 4 |
2 files changed, 21 insertions, 7 deletions
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp index c1aa46e..dc86885 100644 --- a/media/libstagefright/NuCachedSource2.cpp +++ b/media/libstagefright/NuCachedSource2.cpp @@ -323,25 +323,28 @@ void NuCachedSource2::onRead(const sp<AMessage> &msg) { } void NuCachedSource2::restartPrefetcherIfNecessary_l( - bool ignoreLowWaterThreshold) { + bool ignoreLowWaterThreshold, bool force) { static const size_t kGrayArea = 1024 * 1024; if (mFetching || mFinalStatus != OK) { return; } - if (!ignoreLowWaterThreshold + if (!ignoreLowWaterThreshold && !force && mCacheOffset + mCache->totalSize() - mLastAccessPos >= kLowWaterThreshold) { return; } size_t maxBytes = mLastAccessPos - mCacheOffset; - if (maxBytes < kGrayArea) { - return; - } - maxBytes -= kGrayArea; + if (!force) { + if (maxBytes < kGrayArea) { + return; + } + + maxBytes -= kGrayArea; + } size_t actualBytes = mCache->releaseFromStart(maxBytes); mCacheOffset += actualBytes; @@ -413,10 +416,19 @@ size_t NuCachedSource2::approxDataRemaining_l(status_t *finalStatus) { } ssize_t NuCachedSource2::readInternal(off64_t offset, void *data, size_t size) { + CHECK_LE(size, (size_t)kHighWaterThreshold); + LOGV("readInternal offset %lld size %d", offset, size); Mutex::Autolock autoLock(mLock); + if (!mFetching) { + mLastAccessPos = offset; + restartPrefetcherIfNecessary_l( + false, // ignoreLowWaterThreshold + true); // force + } + if (offset < mCacheOffset || offset >= (off64_t)(mCacheOffset + mCache->totalSize())) { static const off64_t kPadding = 256 * 1024; diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h index 2128682..ed3e265c 100644 --- a/media/libstagefright/include/NuCachedSource2.h +++ b/media/libstagefright/include/NuCachedSource2.h @@ -96,7 +96,9 @@ private: status_t seekInternal_l(off64_t offset); size_t approxDataRemaining_l(status_t *finalStatus); - void restartPrefetcherIfNecessary_l(bool ignoreLowWaterThreshold = false); + + void restartPrefetcherIfNecessary_l( + bool ignoreLowWaterThreshold = false, bool force = false); DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2); }; |