Bug 1320258. Part 2 - remove MediaDecoderReader::UpdateBufferedWithPromise(). r=jya
authorJW Wang <jwwang@mozilla.com>
Fri, 25 Nov 2016 16:22:55 +0800
changeset 324615 cd9a0b0df8a32c3caef445bc8c0ef4fd984331ab
parent 324614 08264c30352ddcb6c2c98b5def210fbfac6fc983
child 324616 5bb030f09be53e66f8cf397e3a51e1eabee8d7a6
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjya
bugs1320258, 1313635, 1251460
milestone53.0a1
Bug 1320258. Part 2 - remove MediaDecoderReader::UpdateBufferedWithPromise(). r=jya Bug 1313635 ensures buffer ranges are updated before resolving metadata. So we can revert the changes in bug 1251460. MozReview-Commit-ID: Ek0sgPpv92s
dom/media/MediaDecoderReader.h
dom/media/MediaDecoderReaderWrapper.cpp
dom/media/MediaDecoderReaderWrapper.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaDecoderReader.h
+++ b/dom/media/MediaDecoderReader.h
@@ -74,18 +74,16 @@ public:
 
   // Note that, conceptually, WaitForData makes sense in a non-exclusive sense.
   // But in the current architecture it's only ever used exclusively (by MDSM),
   // so we mark it that way to verify our assumptions. If you have a use-case
   // for multiple WaitForData consumers, feel free to flip the exclusivity here.
   using WaitForDataPromise =
     MozPromise<MediaData::Type, WaitForDataRejectValue, IsExclusive>;
 
-  using BufferedUpdatePromise = MozPromise<bool, bool, IsExclusive>;
-
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderReader)
 
   // The caller must ensure that Shutdown() is called before aDecoder is
   // destroyed.
   explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder);
 
   // Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
   // on failure.
@@ -199,26 +197,16 @@ public:
   void NotifyDataArrived()
   {
     MOZ_ASSERT(OnTaskQueue());
     NS_ENSURE_TRUE_VOID(!mShutdown);
     NotifyDataArrivedInternal();
     UpdateBuffered();
   }
 
-  // Update the buffered ranges and upon doing so return a promise
-  // to indicate success. Overrides may need to do extra work to ensure
-  // buffered is up to date.
-  virtual RefPtr<BufferedUpdatePromise> UpdateBufferedWithPromise()
-  {
-    MOZ_ASSERT(OnTaskQueue());
-    UpdateBuffered();
-    return BufferedUpdatePromise::CreateAndResolve(true, __func__);
-  }
-
   virtual MediaQueue<AudioData>& AudioQueue() { return mAudioQueue; }
   virtual MediaQueue<VideoData>& VideoQueue() { return mVideoQueue; }
 
   AbstractCanonical<media::TimeIntervals>* CanonicalBuffered()
   {
     return &mBuffered;
   }
 
--- a/dom/media/MediaDecoderReaderWrapper.cpp
+++ b/dom/media/MediaDecoderReaderWrapper.cpp
@@ -163,24 +163,16 @@ MediaDecoderReaderWrapper::WaitCallbackR
 
 MozPromiseRequestHolder<MediaDecoderReader::WaitForDataPromise>&
 MediaDecoderReaderWrapper::WaitRequestRef(MediaData::Type aType)
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   return aType == MediaData::AUDIO_DATA ? mAudioWaitRequest : mVideoWaitRequest;
 }
 
-RefPtr<MediaDecoderReaderWrapper::BufferedUpdatePromise>
-MediaDecoderReaderWrapper::UpdateBufferedWithPromise()
-{
-  MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
-  return InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__,
-                     &MediaDecoderReader::UpdateBufferedWithPromise);
-}
-
 void
 MediaDecoderReaderWrapper::ReleaseResources()
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod(mReader, &MediaDecoderReader::ReleaseResources);
   mReader->OwnerThread()->Dispatch(r.forget());
 }
--- a/dom/media/MediaDecoderReaderWrapper.h
+++ b/dom/media/MediaDecoderReaderWrapper.h
@@ -29,17 +29,16 @@ typedef Variant<MediaData::Type, WaitFor
  * It also adjusts the seek target passed to Seek() to ensure correct seek time
  * is passed to the underlying reader.
  */
 class MediaDecoderReaderWrapper {
   typedef MediaDecoderReader::MetadataPromise MetadataPromise;
   typedef MediaDecoderReader::MediaDataPromise MediaDataPromise;
   typedef MediaDecoderReader::SeekPromise SeekPromise;
   typedef MediaDecoderReader::WaitForDataPromise WaitForDataPromise;
-  typedef MediaDecoderReader::BufferedUpdatePromise BufferedUpdatePromise;
   typedef MediaDecoderReader::TrackSet TrackSet;
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderReaderWrapper);
 
 private:
   MediaCallbackExc<AudioCallbackData> mAudioCallback;
   MediaCallbackExc<VideoCallbackData> mVideoCallback;
   MediaCallbackExc<WaitCallbackData> mAudioWaitCallback;
   MediaCallbackExc<WaitCallbackData> mVideoWaitCallback;
@@ -65,17 +64,16 @@ public:
 
   bool IsRequestingAudioData() const;
   bool IsRequestingVideoData() const;
   bool IsWaitingAudioData() const;
   bool IsWaitingVideoData() const;
 
   RefPtr<SeekPromise> Seek(const SeekTarget& aTarget,
                            const media::TimeUnit& aEndTime);
-  RefPtr<BufferedUpdatePromise> UpdateBufferedWithPromise();
   RefPtr<ShutdownPromise> Shutdown();
 
   void ReleaseResources();
   void ResetDecode(TrackSet aTracks);
 
   nsresult Init() { return mReader->Init(); }
   bool IsWaitForDataSupported() const { return mReader->IsWaitForDataSupported(); }
   bool IsAsync() const { return mReader->IsAsync(); }
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1567,17 +1567,16 @@ BufferingState::HandleEndOfStream()
 RefPtr<ShutdownPromise>
 MediaDecoderStateMachine::
 ShutdownState::Enter()
 {
   auto master = mMaster;
 
   master->mIsShutdown = true;
   master->mDelayedScheduler.Reset();
-  master->mBufferedUpdateRequest.DisconnectIfExists();
 
   // Shutdown happens while decode timer is active, we need to disconnect and
   // dispose of the timer.
   master->mVideoDecodeSuspendTimer.Reset();
 
   master->mCDMProxyPromise.DisconnectIfExists();
 
   if (master->IsPlaying()) {
@@ -2698,32 +2697,21 @@ MediaDecoderStateMachine::EnqueueLoadedM
 
 void
 MediaDecoderStateMachine::EnqueueFirstFrameLoadedEvent()
 {
   MOZ_ASSERT(OnTaskQueue());
   // Track value of mSentFirstFrameLoadedEvent from before updating it
   bool firstFrameBeenLoaded = mSentFirstFrameLoadedEvent;
   mSentFirstFrameLoadedEvent = true;
-  RefPtr<MediaDecoderStateMachine> self = this;
-  mBufferedUpdateRequest.Begin(
-    mReader->UpdateBufferedWithPromise()
-    ->Then(OwnerThread(),
-    __func__,
-    // Resolve
-    [self, firstFrameBeenLoaded]() {
-      self->mBufferedUpdateRequest.Complete();
-      MediaDecoderEventVisibility visibility =
-        firstFrameBeenLoaded ? MediaDecoderEventVisibility::Suppressed
-                             : MediaDecoderEventVisibility::Observable;
-      self->mFirstFrameLoadedEvent.Notify(
-        nsAutoPtr<MediaInfo>(new MediaInfo(self->Info())), visibility);
-    },
-    // Reject
-    []() { MOZ_CRASH("Should not reach"); }));
+  MediaDecoderEventVisibility visibility =
+    firstFrameBeenLoaded ? MediaDecoderEventVisibility::Suppressed
+                         : MediaDecoderEventVisibility::Observable;
+  mFirstFrameLoadedEvent.Notify(
+    nsAutoPtr<MediaInfo>(new MediaInfo(Info())), visibility);
 }
 
 void
 MediaDecoderStateMachine::FinishDecodeFirstFrame()
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(!mSentFirstFrameLoadedEvent);
   DECODER_LOG("FinishDecodeFirstFrame");
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -686,19 +686,16 @@ private:
 
   // Stores presentation info required for playback.
   Maybe<MediaInfo> mInfo;
 
   nsAutoPtr<MetadataTags> mMetadataTags;
 
   mozilla::MediaMetadataManager mMetadataManager;
 
-  // Track our request to update the buffered ranges
-  MozPromiseRequestHolder<MediaDecoderReader::BufferedUpdatePromise> mBufferedUpdateRequest;
-
   // True if we are back from DECODER_STATE_DORMANT state and
   // LoadedMetadataEvent was already sent.
   bool mSentLoadedMetadataEvent;
 
   // True if we've decoded first frames (thus having the start time) and
   // notified the FirstFrameLoaded event. Note we can't initiate seek until the
   // start time is known which happens when the first frames are decoded or we
   // are playing an MSE stream (the start time is always assumed 0).
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -2208,30 +2208,16 @@ MediaFormatReader::GetBuffered()
   if (!intervals.Length() ||
       intervals.GetStart() == media::TimeUnit::FromMicroseconds(0)) {
     // IntervalSet already starts at 0 or is empty, nothing to shift.
     return intervals;
   }
   return intervals.Shift(media::TimeUnit() - mInfo.mStartTime);
 }
 
-// For the MediaFormatReader override we need to force an update to the
-// buffered ranges, so we call NotifyDataArrive
-RefPtr<MediaDecoderReader::BufferedUpdatePromise>
-MediaFormatReader::UpdateBufferedWithPromise() {
-  MOZ_ASSERT(OnTaskQueue());
-  // Call NotifyDataArrive to force a recalculation of the buffered
-  // ranges. UpdateBuffered alone will not force a recalculation, so we
-  // use NotifyDataArrived which sets flags to force this recalculation.
-  // See MediaFormatReader::UpdateReceivedNewData for an example of where
-  // the new data flag is used.
-  NotifyDataArrived();
-  return BufferedUpdatePromise::CreateAndResolve(true, __func__);
-}
-
 void MediaFormatReader::ReleaseResources()
 {
   mVideo.ShutdownDecoder();
   mAudio.ShutdownDecoder();
 }
 
 bool
 MediaFormatReader::VideoIsHardwareAccelerated() const
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -51,18 +51,16 @@ public:
   Seek(const SeekTarget& aTarget, int64_t aUnused) override;
 
 protected:
   void NotifyDataArrivedInternal() override;
 
 public:
   media::TimeIntervals GetBuffered() override;
 
-  RefPtr<BufferedUpdatePromise> UpdateBufferedWithPromise() override;
-
   bool ForceZeroStartTime() const override;
 
   // For Media Resource Management
   void ReleaseResources() override;
 
   nsresult ResetDecode(TrackSet aTracks) override;
 
   RefPtr<ShutdownPromise> Shutdown() override;