Bug 1401471. P3 - store the seek target in StreamAction so we won't need to read mChannelOffset outside the cache monitor. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 20 Sep 2017 16:20:56 +0800
changeset 668975 b2cdc28c84e7fba347a1514617034d524fd0ed65
parent 668974 955887fe04b5ded1b75923572c6b39ff455679f4
child 668976 ff8a8163d26136c810e6f98113135ad6d44e3fa3
push id81174
push userjwwang@mozilla.com
push dateFri, 22 Sep 2017 09:08:50 +0000
bugs1401471
milestone57.0a1
Bug 1401471. P3 - store the seek target in StreamAction so we won't need to read mChannelOffset outside the cache monitor. MozReview-Commit-ID: Kkbs3WbSBVm
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -1134,16 +1134,17 @@ MediaCache::Update()
     {
       NONE,
       SEEK,
       RESUME,
       SUSPEND
     } mTag = NONE;
     // Members for 'SEEK' only.
     bool mResume = false;
+    int64_t mSeekTarget = -1;
   };
 
   // The action to use for each stream. We store these so we can make
   // decisions while holding the cache lock but implement those decisions
   // without holding the cache lock, since we need to call out to
   // stream, decoder and element code.
   AutoTArray<StreamAction,10> actions;
 
@@ -1396,16 +1397,17 @@ MediaCache::Update()
                      "Trying to seek in a non-seekable stream!");
         // Round seek offset down to the start of the block. This is essential
         // because we don't want to think we have part of a block already
         // in mPartialBlockBuffer.
         stream->mChannelOffset =
           OffsetToBlockIndexUnchecked(desiredOffset) * BLOCK_SIZE;
         actions[i].mTag = StreamAction::SEEK;
         actions[i].mResume = stream->mCacheSuspended;
+        actions[i].mSeekTarget = stream->mChannelOffset;
         // mChannelOffset is updated to a new position. We don't want data from
         // the old channel to be written to the wrong position. 0 is a sentinel
         // value which will not match any ID passed to NotifyDataReceived().
         stream->mLoadID = 0;
       } else if (enableReading && stream->mCacheSuspended) {
         actions[i].mTag = StreamAction::RESUME;
       } else if (!enableReading && !stream->mCacheSuspended) {
         actions[i].mTag = StreamAction::SUSPEND;
@@ -1447,19 +1449,19 @@ MediaCache::Update()
 
   for (uint32_t i = 0; i < mStreams.Length(); ++i) {
     MediaCacheStream* stream = mStreams[i];
     nsresult rv;
     switch (actions[i].mTag) {
       case StreamAction::SEEK:
         LOG("Stream %p CacheSeek to %" PRId64 " (resume=%d)",
             stream,
-            stream->mChannelOffset,
+            actions[i].mSeekTarget,
             actions[i].mResume);
-        rv = stream->mClient->CacheClientSeek(stream->mChannelOffset,
+        rv = stream->mClient->CacheClientSeek(actions[i].mSeekTarget,
                                               actions[i].mResume);
         break;
       case StreamAction::RESUME:
         LOG("Stream %p Resumed", stream);
         rv = stream->mClient->CacheClientResume();
         QueueSuspendedStatusUpdate(stream->mResourceID);
         break;
       case StreamAction::SUSPEND: