Bug 1128069 - [MSE] P6. Call NotifyDataArrived from MediaDecoder. r=gerald, a=lizzard
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 08 Aug 2016 13:56:38 +1000
changeset 342515 648de888965df29e719ec58d70479a638b072f68
parent 342514 2b74ae0b004a7ae96e24087647e810937e15f205
child 342516 a9ea5a5e86bc2fd6b33b30b8f0efafe84405154d
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, lizzard
bugs1128069
milestone49.0
Bug 1128069 - [MSE] P6. Call NotifyDataArrived from MediaDecoder. r=gerald, a=lizzard 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
@@ -176,17 +176,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
@@ -87,14 +87,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
@@ -276,19 +276,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)