Bug 1189588: [MSE] Remove MediaSourceDemuxer::NotifyTimeRangesChanged. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 31 Jul 2015 13:42:56 +1000
changeset 287237 8e247a5f9f976ae6749b255d1a71a4b74abc62d7
parent 287236 525bb2034be22ff987ddc87cfeff8407ea2689e5
child 287238 52758787f3249f4e9c7331f8056ec139750070c9
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1189588, 1174981
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1189588: [MSE] Remove MediaSourceDemuxer::NotifyTimeRangesChanged. r=cpearce This was an optimisation added to prevent recalculating our buffered ranges unnecessarily, but it became totally unnecessary with bug 1174981. Additionally, it appears that there's a race in its use ; which I can't identify.
dom/media/mediasource/MediaSourceDemuxer.cpp
dom/media/mediasource/MediaSourceDemuxer.h
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -133,25 +133,16 @@ MediaSourceDemuxer::GetCrypto()
 {
   MonitorAutoLock mon(mMonitor);
   auto crypto = MakeUnique<EncryptionInfo>();
   *crypto = mInfo.mCrypto;
   return crypto;
 }
 
 void
-MediaSourceDemuxer::NotifyTimeRangesChanged()
-{
-  MOZ_ASSERT(OnTaskQueue());
-  for (uint32_t i = 0; i < mDemuxers.Length(); i++) {
-    mDemuxers[i]->NotifyTimeRangesChanged();
-  }
-}
-
-void
 MediaSourceDemuxer::AttachSourceBuffer(TrackBuffersManager* aSourceBuffer)
 {
   nsCOMPtr<nsIRunnable> task =
     NS_NewRunnableMethodWithArg<TrackBuffersManager*>(
       this, &MediaSourceDemuxer::DoAttachSourceBuffer,
       aSourceBuffer);
   GetTaskQueue()->Dispatch(task.forget());
 }
@@ -264,23 +255,16 @@ MediaSourceDemuxer::GetMozDebugReaderDat
 MediaSourceTrackDemuxer::MediaSourceTrackDemuxer(MediaSourceDemuxer* aParent,
                                                  TrackInfo::TrackType aType,
                                                  TrackBuffersManager* aManager)
   : mParent(aParent)
   , mManager(aManager)
   , mType(aType)
   , mMonitor("MediaSourceTrackDemuxer")
 {
-  // Force refresh of our buffered ranges.
-  nsRefPtr<MediaSourceTrackDemuxer> self = this;
-  nsCOMPtr<nsIRunnable> task =
-    NS_NewRunnableFunction([self] () {
-      self->NotifyTimeRangesChanged();
-    });
-  mParent->GetTaskQueue()->Dispatch(task.forget());
 }
 
 UniquePtr<TrackInfo>
 MediaSourceTrackDemuxer::GetInfo() const
 {
   return mParent->GetTrackInfo(mType)->Clone();
 }
 
@@ -356,17 +340,20 @@ MediaSourceTrackDemuxer::BreakCycles()
       self->mManager = nullptr;
     } );
   mParent->GetTaskQueue()->Dispatch(task.forget());
 }
 
 nsRefPtr<MediaSourceTrackDemuxer::SeekPromise>
 MediaSourceTrackDemuxer::DoSeek(media::TimeUnit aTime)
 {
-  if (!mBufferedRanges.Contains(aTime)) {
+  TimeIntervals buffered = mManager->Buffered(mType);
+  buffered.SetFuzz(TimeUnit::FromMicroseconds(EOS_FUZZ_US));
+
+  if (!buffered.Contains(aTime)) {
     // We don't have the data to seek to.
     return SeekPromise::CreateAndReject(DemuxerFailureReason::WAITING_FOR_DATA,
                                         __func__);
   }
   TimeUnit seekTime = mManager->Seek(mType, aTime);
   {
     MonitorAutoLock mon(mMonitor);
     mNextRandomAccessPoint = mManager->GetNextRandomAccessPoint(mType);
@@ -408,20 +395,9 @@ MediaSourceTrackDemuxer::DoSkipToNextRan
     return SkipAccessPointPromise::CreateAndResolve(parsed, __func__);
   }
   SkipFailureHolder holder(
     mManager->IsEnded() ? DemuxerFailureReason::END_OF_STREAM :
                           DemuxerFailureReason::WAITING_FOR_DATA, parsed);
   return SkipAccessPointPromise::CreateAndReject(holder, __func__);
 }
 
-void
-MediaSourceTrackDemuxer::NotifyTimeRangesChanged()
-{
-  if (!mParent) {
-    return;
-  }
-  MOZ_ASSERT(mParent->OnTaskQueue());
-  mBufferedRanges = mManager->Buffered(mType);
-  mBufferedRanges.SetFuzz(TimeUnit::FromMicroseconds(EOS_FUZZ_US));
-}
-
 } // namespace mozilla
--- a/dom/media/mediasource/MediaSourceDemuxer.h
+++ b/dom/media/mediasource/MediaSourceDemuxer.h
@@ -49,17 +49,16 @@ public:
   UniquePtr<EncryptionInfo> GetCrypto() override;
 
   bool ShouldComputeStartTime() const override { return false; }
 
   /* interface for TrackBuffersManager */
   void AttachSourceBuffer(TrackBuffersManager* aSourceBuffer);
   void DetachSourceBuffer(TrackBuffersManager* aSourceBuffer);
   TaskQueue* GetTaskQueue() { return mTaskQueue; }
-  void NotifyTimeRangesChanged();
 
   // Returns a string describing the state of the MediaSource internal
   // buffered data. Used for debugging purposes.
   void GetMozDebugReaderData(nsAString& aString);
 
 private:
   ~MediaSourceDemuxer();
   friend class MediaSourceTrackDemuxer;
@@ -112,32 +111,27 @@ public:
 
   void BreakCycles() override;
 
   bool GetSamplesMayBlock() const override
   {
     return false;
   }
 
-  // Called by TrackBuffersManager to indicate that new frames were added or
-  // removed.
-  void NotifyTimeRangesChanged();
-
 private:
   nsRefPtr<SeekPromise> DoSeek(media::TimeUnit aTime);
   nsRefPtr<SamplesPromise> DoGetSamples(int32_t aNumSamples);
   nsRefPtr<SkipAccessPointPromise> DoSkipToNextRandomAccessPoint(media::TimeUnit aTimeThreadshold);
   already_AddRefed<MediaRawData> GetSample(DemuxerFailureReason& aFailure);
   // Return the timestamp of the next keyframe after mLastSampleIndex.
   media::TimeUnit GetNextRandomAccessPoint();
 
   nsRefPtr<MediaSourceDemuxer> mParent;
   nsRefPtr<TrackBuffersManager> mManager;
   TrackInfo::TrackType mType;
-  media::TimeIntervals mBufferedRanges;
   // Monitor protecting members below accessed from multiple threads.
   Monitor mMonitor;
   media::TimeUnit mNextRandomAccessPoint;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -576,19 +576,16 @@ TrackBuffersManager::UpdateBufferedRange
   }
   if (HasAudio()) {
     MSE_DEBUG("after audio ranges=%s",
               DumpTimeRanges(mAudioTracks.mBufferedRanges).get());
   }
 #endif
 
   mOfficialGroupEndTimestamp = mGroupEndTimestamp;
-
-  // Tell our demuxer that data was removed or added.
-  mMediaSourceDemuxer->NotifyTimeRangesChanged();
 }
 
 nsRefPtr<TrackBuffersManager::AppendPromise>
 TrackBuffersManager::InitSegmentParserLoop()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   MOZ_ASSERT(mAppendPromise.IsEmpty() && !mAppendRunning);