Bug 1412205 - MediaCacheStream::Read() should update mStreamOffset before releasing the monitor. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 27 Oct 2017 13:56:46 +0800
changeset 690075 01a2e21576e6508ccc4518b202c2065d1fd7ad7d
parent 689820 ee21e5f7f1c1726e0ed2697eb45df54cdceedd36
child 738478 ccd88bf38084284545a4c38155fbabed897b3863
push id87200
push userjwwang@mozilla.com
push dateWed, 01 Nov 2017 13:32:05 +0000
bugs1412205
milestone58.0a1
Bug 1412205 - MediaCacheStream::Read() should update mStreamOffset before releasing the monitor. MediaCache::Update() depends on mStreamOffset to make decision whether to read streams or not. It is important to update mStreamOffset before releasing the monitor so Update() won't make wrong decisions based on the stale value. MozReview-Commit-ID: 40jUk5xd6GR
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2496,16 +2496,23 @@ MediaCacheStream::Read(char* aBuffer, ui
         if (mCurrentMode == MODE_METADATA) {
           streamWithPartialBlock->mMetadataInPartialBlockBuffer = true;
         }
         streamOffset += bytes;
         count = bytes;
         break;
       }
 
+      if (mStreamOffset != streamOffset) {
+        // Updat mStreamOffset before we drop the lock. We need to run
+        // Update() again since stream reading strategy might have changed.
+        mStreamOffset = streamOffset;
+        mMediaCache->QueueUpdate();
+      }
+
       // No data has been read yet, so block
       mon.Wait();
       if (mClosed) {
         // We may have successfully read some data, but let's just throw
         // that out.
         return NS_ERROR_FAILURE;
       }
       continue;