Skip to content

Commit f0f1cee

Browse files
committed
DO NOT MERGE: Make sure we restart the prefetcher immediately when trying to satisfy a read.
Change-Id: I27c2b5d20ae577e71936d32522f70f6ba08cc247 related-to-bug: 4286618
1 parent 71a556f commit f0f1cee

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

media/libstagefright/AwesomePlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ void AwesomePlayer::finishSeekIfNecessary(int64_t videoTimeUs) {
11271127
}
11281128

11291129
if (mAudioPlayer != NULL) {
1130-
LOGV("seeking audio to %lld us (%.2f secs).", timeUs, timeUs / 1E6);
1130+
LOGV("seeking audio to %lld us (%.2f secs).", videoTimeUs, videoTimeUs / 1E6);
11311131

11321132
// If we don't have a video time, seek audio to the originally
11331133
// requested seek time instead.

media/libstagefright/NuCachedSource2.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,24 +326,31 @@ void NuCachedSource2::onRead(const sp<AMessage> &msg) {
326326
mCondition.signal();
327327
}
328328

329-
void NuCachedSource2::restartPrefetcherIfNecessary_l() {
329+
void NuCachedSource2::restartPrefetcherIfNecessary_l(bool force) {
330330
static const size_t kGrayArea = 256 * 1024;
331331

332332
if (mFetching || mFinalStatus != OK) {
333333
return;
334334
}
335335

336-
if (mCacheOffset + mCache->totalSize() - mLastAccessPos
337-
>= kLowWaterThreshold) {
338-
return;
339-
}
336+
size_t maxBytes;
340337

341-
size_t maxBytes = mLastAccessPos - mCacheOffset;
342-
if (maxBytes < kGrayArea) {
343-
return;
344-
}
338+
if (!force) {
339+
if (mCacheOffset + mCache->totalSize() - mLastAccessPos
340+
>= kLowWaterThreshold) {
341+
return;
342+
}
343+
344+
maxBytes = mLastAccessPos - mCacheOffset;
345+
if (maxBytes < kGrayArea) {
346+
return;
347+
}
345348

346-
maxBytes -= kGrayArea;
349+
maxBytes -= kGrayArea;
350+
} else {
351+
// Empty it all out.
352+
maxBytes = mLastAccessPos - mCacheOffset;
353+
}
347354

348355
size_t actualBytes = mCache->releaseFromStart(maxBytes);
349356
mCacheOffset += actualBytes;
@@ -415,10 +422,17 @@ size_t NuCachedSource2::approxDataRemaining_l(bool *eos) {
415422
}
416423

417424
ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) {
425+
CHECK(size <= kHighWaterThreshold);
426+
418427
LOGV("readInternal offset %ld size %d", offset, size);
419428

420429
Mutex::Autolock autoLock(mLock);
421430

431+
if (!mFetching) {
432+
mLastAccessPos = offset;
433+
restartPrefetcherIfNecessary_l(true /* force */);
434+
}
435+
422436
if (offset < mCacheOffset
423437
|| offset >= (off_t)(mCacheOffset + mCache->totalSize())) {
424438
static const off_t kPadding = 32768;

media/libstagefright/include/NuCachedSource2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct NuCachedSource2 : public DataSource {
9494
status_t seekInternal_l(off_t offset);
9595

9696
size_t approxDataRemaining_l(bool *eos);
97-
void restartPrefetcherIfNecessary_l();
97+
void restartPrefetcherIfNecessary_l(bool force = false);
9898

9999
DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2);
100100
};

0 commit comments

Comments
 (0)