Bug 1357040 - Part 2: Don't rely on NotifyDataArrived to resolve MSE init promise. r=gerald, a=gchang
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 27 Apr 2017 19:53:53 +0200
changeset 393932 4dc1982e436eb154ba3154f6df29585c41e47d22
parent 393931 82aba3466ff1fbe40d30e6a74267a59da4106a71
child 393933 1511c3039be28f44f404aaa80d81a7dce9da3bb5
push id7307
push userryanvm@gmail.com
push dateFri, 12 May 2017 16:56:21 +0000
treeherdermozilla-beta@1511c3039be2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, gchang
bugs1357040
milestone54.0
Bug 1357040 - Part 2: Don't rely on NotifyDataArrived to resolve MSE init promise. r=gerald, a=gchang MozReview-Commit-ID: KUxVqfU9umw
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/MediaSourceDecoder.h
dom/media/mediasource/MediaSourceDemuxer.cpp
dom/media/mediasource/MediaSourceDemuxer.h
dom/media/mediasource/SourceBuffer.cpp
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -351,12 +351,22 @@ MediaSourceDecoder::ClampIntervalToEnd(c
   if (duration < aInterval.mStart) {
     return aInterval;
   }
   return TimeInterval(aInterval.mStart,
                       std::min(aInterval.mEnd, duration),
                       aInterval.mFuzz);
 }
 
+void
+MediaSourceDecoder::NotifyInitDataArrived()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (mDemuxer) {
+    mDemuxer->NotifyInitDataArrived();
+  }
+}
+
 #undef MSE_DEBUG
 #undef MSE_DEBUGV
 
 } // namespace mozilla
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -73,16 +73,18 @@ public:
   bool CanPlayThrough() override;
 
   void NotifyWaitingForKey() override;
 
   MediaEventSource<void>* WaitingForKeyEvent() override;
 
   bool IsMSE() const override { return true; }
 
+  void NotifyInitDataArrived();
+
 private:
   void DoSetMediaSourceDuration(double aDuration);
   media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval);
 
   // The owning MediaSource holds a strong reference to this decoder, and
   // calls Attach/DetachMediaSource on this decoder to set and clear
   // mMediaSource.
   dom::MediaSource* mMediaSource;
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -61,28 +61,27 @@ MediaSourceDemuxer::AddSizeOfResources(M
       for (TrackBuffersManager* manager : self->mSourceBuffers) {
         manager->AddSizeOfResources(sizes);
       }
     });
 
   GetTaskQueue()->Dispatch(task.forget());
 }
 
-void MediaSourceDemuxer::NotifyDataArrived()
+void MediaSourceDemuxer::NotifyInitDataArrived()
 {
   RefPtr<MediaSourceDemuxer> self = this;
-  nsCOMPtr<nsIRunnable> task =
-    NS_NewRunnableFunction([self] () {
-      if (self->mInitPromise.IsEmpty()) {
-        return;
-      }
-      if (self->ScanSourceBuffersForContent()) {
-        self->mInitPromise.ResolveIfExists(NS_OK, __func__);
-      }
-    });
+  nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([self]() {
+    if (self->mInitPromise.IsEmpty()) {
+      return;
+    }
+    if (self->ScanSourceBuffersForContent()) {
+      self->mInitPromise.ResolveIfExists(NS_OK, __func__);
+    }
+  });
   GetTaskQueue()->Dispatch(task.forget());
 }
 
 bool
 MediaSourceDemuxer::ScanSourceBuffersForContent()
 {
   MOZ_ASSERT(OnTaskQueue());
 
--- a/dom/media/mediasource/MediaSourceDemuxer.h
+++ b/dom/media/mediasource/MediaSourceDemuxer.h
@@ -39,22 +39,21 @@ public:
   GetTrackDemuxer(TrackInfo::TrackType aType, uint32_t aTrackNumber) override;
 
   bool IsSeekable() const override;
 
   UniquePtr<EncryptionInfo> GetCrypto() override;
 
   bool ShouldComputeStartTime() const override { return false; }
 
-  void NotifyDataArrived() override;
-
   /* interface for TrackBuffersManager */
   void AttachSourceBuffer(TrackBuffersManager* aSourceBuffer);
   void DetachSourceBuffer(TrackBuffersManager* aSourceBuffer);
   AutoTaskQueue* GetTaskQueue() { return mTaskQueue; }
+  void NotifyInitDataArrived();
 
   // Returns a string describing the state of the MediaSource internal
   // buffered data. Used for debugging purposes.
   void GetMozDebugReaderData(nsACString& aString);
 
   void AddSizeOfResources(MediaSourceDecoder::ResourceSizes* aSizes);
 
   // Gap allowed between frames.
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -429,16 +429,17 @@ SourceBuffer::AppendDataCompletedWithSuc
 {
   MOZ_ASSERT(mUpdating);
   mPendingAppend.Complete();
 
   if (aResult.first()) {
     if (!mActive) {
       mActive = true;
       mMediaSource->SourceBufferIsActive(this);
+      mMediaSource->GetDecoder()->NotifyInitDataArrived();
     }
   }
   if (mActive) {
     // Tell our parent decoder that we have received new data.
     mMediaSource->GetDecoder()->NotifyDataArrived();
     // Send progress event.
     mMediaSource->GetDecoder()->NotifyBytesDownloaded();
   }