Fix a race condition in the prefetcher, the source may be shutdown while we're reading data from it.
related-to-bug: 2453414
diff --git a/media/libstagefright/Prefetcher.cpp b/media/libstagefright/Prefetcher.cpp
index 76ca77b..363e121 100644
--- a/media/libstagefright/Prefetcher.cpp
+++ b/media/libstagefright/Prefetcher.cpp
@@ -337,24 +337,20 @@
void PrefetchedSource::cacheMore() {
MediaSource::ReadOptions options;
- {
- Mutex::Autolock autoLock(mLock);
+ Mutex::Autolock autoLock(mLock);
- if (!mStarted) {
- return;
- }
+ if (!mStarted) {
+ return;
+ }
- if (mSeekTimeUs >= 0) {
- options.setSeekTo(mSeekTimeUs);
- mSeekTimeUs = -1;
- }
+ if (mSeekTimeUs >= 0) {
+ options.setSeekTo(mSeekTimeUs);
+ mSeekTimeUs = -1;
}
MediaBuffer *buffer;
status_t err = mSource->read(&buffer, &options);
- Mutex::Autolock autoLock(mLock);
-
if (err != OK) {
mReachedEOS = true;
mCondition.signal();