Bug 1401147 - part1 : empty track buffer content upon detach. draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 19 Sep 2017 14:44:59 +0200
changeset 668859 f529c6617b73710eb2d22364481d1e73054b82fb
parent 668025 47f7b6c64265bc7bdd22eef7ab71abc97cf3f8bf
child 668860 0c948a3346a2cbc1fa5c0f855ac2620f3f665ddf
push id81143
push useralwu@mozilla.com
push dateFri, 22 Sep 2017 04:02:12 +0000
bugs1401147
milestone57.0a1
Bug 1401147 - part1 : empty track buffer content upon detach. After detached the source buffer, we would reset all its resource and shutdown demuxer. MozReview-Commit-ID: FGEiYLcFd4h
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -206,16 +206,19 @@ TrackBuffersManager::ProcessTasks()
     case Type::Reset:
       CompleteResetParserState();
       break;
     case Type::Detach:
       mCurrentInputBuffer = nullptr;
       mTaskQueue = nullptr;
       MOZ_DIAGNOSTIC_ASSERT(mQueue.Length() == 0,
                             "Detach task must be the last");
+      mVideoTracks.Reset();
+      mAudioTracks.Reset();
+      ShutdownDemuxers();
       return;
     default:
       NS_WARNING("Invalid Task");
   }
   GetTaskQueue()->Dispatch(
     NewRunnableMethod("TrackBuffersManager::ProcessTasks",
                       this,
                       &TrackBuffersManager::ProcessTasks));
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -371,18 +371,30 @@ private:
     EvictionIndex mEvictionIndex;
 
     void ResetAppendState()
     {
       mLastDecodeTimestamp.reset();
       mLastFrameDuration.reset();
       mHighestEndTimestamp.reset();
       mNeedRandomAccessPoint = true;
+      mNextInsertionIndex.reset();
+    }
 
-      mNextInsertionIndex.reset();
+    void Reset()
+    {
+      ResetAppendState();
+      mEvictionIndex.Reset();
+      for (auto& buffer : mBuffers) {
+        buffer.Clear();
+      }
+      mSizeBuffer = 0;
+      mNextGetSampleIndex.reset();
+      mBufferedRanges.Clear();
+      mSanitizedBufferedRanges.Clear();
     }
 
     void AddSizeOfResources(MediaSourceDecoder::ResourceSizes* aSizes) const;
   };
 
   void CheckSequenceDiscontinuity(const media::TimeUnit& aPresentationTime);
   void ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData);
   media::TimeInterval PresentationInterval(const TrackBuffer& aSamples) const;