Bug 1128069: [MSE] P6. Call NotifyDataArrived from MediaDecoder. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 08 Aug 2016 13:56:38 +1000
changeset 397768 78ee6cb120cdbc03a5304caf11ccdda8ab04b44c
parent 397767 48268c8af35bd3ccd8a209c61d439ccae89a2bd1
child 397769 f75d10acb764b4cd118fbd52a241c4ff8d459e7d
push id25391
push userbmo:jyavenard@mozilla.com
push dateMon, 08 Aug 2016 09:33:44 +0000
reviewersgerald
bugs1128069
milestone51.0a1
Bug 1128069: [MSE] P6. Call NotifyDataArrived from MediaDecoder. r?gerald Calling NotifyDataArrived from each sourcebuffer will cause multiple unnecessary NotifyDataArrived to the MediaFormatReader when it could only be done once. Additionally, it ensures that the media duration is updated prior to the reader actioning on the notification. Extra: mEnded is only ever accessed on the main thread, there's no need to make it atomic. MozReview-Commit-ID: IKq7IRBbWic
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/MediaSourceDecoder.h
dom/media/mediasource/SourceBuffer.cpp
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -187,17 +187,22 @@ MediaSourceDecoder::DetachMediaSource()
   mMediaSource = nullptr;
 }
 
 void
 MediaSourceDecoder::Ended(bool aEnded)
 {
   MOZ_ASSERT(NS_IsMainThread());
   static_cast<MediaSourceResource*>(GetResource())->SetEnded(aEnded);
-  mEnded = true;
+  if (aEnded) {
+    // We want the MediaSourceReader to refresh its buffered range as it may
+    // have been modified (end lined up).
+    NotifyDataArrived();
+  }
+  mEnded = aEnded;
 }
 
 void
 MediaSourceDecoder::AddSizeOfResources(ResourceSizes* aSizes)
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (GetDemuxer()) {
     GetDemuxer()->AddSizeOfResources(aSizes);
@@ -305,16 +310,18 @@ MediaSourceDecoder::CanPlayThrough()
                         timeAhead,
                         MediaSourceDemuxer::EOS_FUZZ);
   return GetBuffered().Contains(ClampIntervalToEnd(interval));
 }
 
 TimeInterval
 MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
 {
+  MOZ_ASSERT(NS_IsMainThread());
+
   if (!mEnded) {
     return aInterval;
   }
   TimeInterval interval(TimeUnit(), TimeUnit::FromSeconds(GetDuration()));
   return aInterval.Intersection(interval);
 }
 
 #undef MSE_DEBUG
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -86,14 +86,14 @@ private:
 
   // 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;
   RefPtr<MediaSourceDemuxer> mDemuxer;
   RefPtr<MediaFormatReader> mReader;
 
-  Atomic<bool> mEnded;
+  bool mEnded;
 };
 
 } // namespace mozilla
 
 #endif /* MOZILLA_MEDIASOURCEDECODER_H_ */
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -284,19 +284,16 @@ SourceBuffer::Detach()
 
 void
 SourceBuffer::Ended()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(IsAttached());
   MSE_DEBUG("Ended");
   mTrackBuffersManager->Ended();
-  // We want the MediaSourceReader to refresh its buffered range as it may
-  // have been modified (end lined up).
-  mMediaSource->GetDecoder()->NotifyDataArrived();
 }
 
 SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
   : DOMEventTargetHelper(aMediaSource->GetParentObject())
   , mMediaSource(aMediaSource)
   , mCurrentAttributes(aType.LowerCaseEqualsLiteral("audio/mpeg") ||
                        aType.LowerCaseEqualsLiteral("audio/aac"))
   , mUpdating(false)