Make sure a read restarts the prefetcher if necessary.

Change-Id: I87cac0e61e4dce7987ddf29c32f51e1672d1bbed
related-to-bug: 4286618
This commit is contained in:
Andreas Huber
2011-04-19 10:04:08 -07:00
parent 7f9968c2ef
commit bb32a94fb4
2 changed files with 21 additions and 7 deletions

View File

@@ -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;

View File

@@ -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);
};