DO NOT MERGE: Make sure we restart the prefetcher immediately when trying to satisfy a read.

Change-Id: I27c2b5d20ae577e71936d32522f70f6ba08cc247
related-to-bug: 4286618
This commit is contained in:
Andreas Huber
2011-04-14 10:01:41 -07:00
parent 71a556f24e
commit f0f1ceeb51
3 changed files with 26 additions and 12 deletions

View File

@@ -1127,7 +1127,7 @@ void AwesomePlayer::finishSeekIfNecessary(int64_t videoTimeUs) {
} }
if (mAudioPlayer != NULL) { if (mAudioPlayer != NULL) {
LOGV("seeking audio to %lld us (%.2f secs).", timeUs, timeUs / 1E6); LOGV("seeking audio to %lld us (%.2f secs).", videoTimeUs, videoTimeUs / 1E6);
// If we don't have a video time, seek audio to the originally // If we don't have a video time, seek audio to the originally
// requested seek time instead. // requested seek time instead.

View File

@@ -326,24 +326,31 @@ void NuCachedSource2::onRead(const sp<AMessage> &msg) {
mCondition.signal(); mCondition.signal();
} }
void NuCachedSource2::restartPrefetcherIfNecessary_l() { void NuCachedSource2::restartPrefetcherIfNecessary_l(bool force) {
static const size_t kGrayArea = 256 * 1024; static const size_t kGrayArea = 256 * 1024;
if (mFetching || mFinalStatus != OK) { if (mFetching || mFinalStatus != OK) {
return; return;
} }
if (mCacheOffset + mCache->totalSize() - mLastAccessPos size_t maxBytes;
>= kLowWaterThreshold) {
return;
}
size_t maxBytes = mLastAccessPos - mCacheOffset; if (!force) {
if (maxBytes < kGrayArea) { if (mCacheOffset + mCache->totalSize() - mLastAccessPos
return; >= kLowWaterThreshold) {
} return;
}
maxBytes -= kGrayArea; maxBytes = mLastAccessPos - mCacheOffset;
if (maxBytes < kGrayArea) {
return;
}
maxBytes -= kGrayArea;
} else {
// Empty it all out.
maxBytes = mLastAccessPos - mCacheOffset;
}
size_t actualBytes = mCache->releaseFromStart(maxBytes); size_t actualBytes = mCache->releaseFromStart(maxBytes);
mCacheOffset += actualBytes; mCacheOffset += actualBytes;
@@ -415,10 +422,17 @@ size_t NuCachedSource2::approxDataRemaining_l(bool *eos) {
} }
ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) { ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) {
CHECK(size <= kHighWaterThreshold);
LOGV("readInternal offset %ld size %d", offset, size); LOGV("readInternal offset %ld size %d", offset, size);
Mutex::Autolock autoLock(mLock); Mutex::Autolock autoLock(mLock);
if (!mFetching) {
mLastAccessPos = offset;
restartPrefetcherIfNecessary_l(true /* force */);
}
if (offset < mCacheOffset if (offset < mCacheOffset
|| offset >= (off_t)(mCacheOffset + mCache->totalSize())) { || offset >= (off_t)(mCacheOffset + mCache->totalSize())) {
static const off_t kPadding = 32768; static const off_t kPadding = 32768;

View File

@@ -94,7 +94,7 @@ private:
status_t seekInternal_l(off_t offset); status_t seekInternal_l(off_t offset);
size_t approxDataRemaining_l(bool *eos); size_t approxDataRemaining_l(bool *eos);
void restartPrefetcherIfNecessary_l(); void restartPrefetcherIfNecessary_l(bool force = false);
DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2); DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2);
}; };