Do not hold onto the master lock while reading data from the datasource. This would prevent consumers from reading cached data immediately if it is available.
related-to-bug: 2295438
diff --git a/media/libstagefright/Prefetcher.cpp b/media/libstagefright/Prefetcher.cpp
index 93e3fdc..862998a 100644
--- a/media/libstagefright/Prefetcher.cpp
+++ b/media/libstagefright/Prefetcher.cpp
@@ -308,21 +308,26 @@
}
void PrefetchedSource::cacheMore() {
- Mutex::Autolock autoLock(mLock);
+ MediaSource::ReadOptions options;
- if (!mStarted) {
- return;
+ {
+ Mutex::Autolock autoLock(mLock);
+
+ if (!mStarted) {
+ return;
+ }
+
+ if (mSeekTimeUs >= 0) {
+ options.setSeekTo(mSeekTimeUs);
+ mSeekTimeUs = -1;
+ }
}
MediaBuffer *buffer;
- MediaSource::ReadOptions options;
- if (mSeekTimeUs >= 0) {
- options.setSeekTo(mSeekTimeUs);
- mSeekTimeUs = -1;
- }
-
status_t err = mSource->read(&buffer, &options);
+ Mutex::Autolock autoLock(mLock);
+
if (err != OK) {
mReachedEOS = true;
mCondition.signal();