Bug 1128069 - [MSE] P6. Call NotifyDataArrived from MediaDecoder. r=gerald, a=lizzard
☠☠ backed out by e441403ef6a8 ☠ ☠
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 08 Aug 2016 13:56:38 +1000
changeset 340441 3ab8087d6442cb205e1eafae625a842062a8ae73
parent 340440 59249959e5918499c190bea0f9984bd32a617caa
child 340442 dcdb0d847056e6c461801e6c5cbd833139462f3a
push id6337
push userryanvm@gmail.com
push dateThu, 25 Aug 2016 03:33:50 +0000
treeherdermozilla-beta@901d8d3d4597 [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)