Bug 1391142. P1 - dispatch IsLiveStream changes from MediaDecoder to MDSM. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 17 Aug 2017 11:48:08 +0800
changeset 648646 c1b967967b4fbd45472090c5bbef132728a4a499
parent 648645 0a58e748c7d8e887069a4e8b2f0b8369c79a1d1d
child 648647 baf1ee6805434b218ef57716ba24ba5acd73b52a
push id74836
push userjwwang@mozilla.com
push dateFri, 18 Aug 2017 05:01:08 +0000
bugs1391142
milestone57.0a1
Bug 1391142. P1 - dispatch IsLiveStream changes from MediaDecoder to MDSM. This allows us to remove the dependency on MediaResource from MDSM in P2. MozReview-Commit-ID: I46fWXfnGQK
dom/media/MediaDecoder.cpp
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -677,16 +677,21 @@ MediaDecoder::DiscardOngoingSeekIfExists
 
 void
 MediaDecoder::CallSeek(const SeekTarget& aTarget)
 {
   MOZ_ASSERT(NS_IsMainThread());
   AbstractThread::AutoEnter context(AbstractMainThread());
   DiscardOngoingSeekIfExists();
 
+  // Since we don't have a listener for changes in IsLiveStream, our best bet
+  // is to ensure IsLiveStream is uptodate when seek begins. This value will be
+  // checked when seek is completed.
+  mDecoderStateMachine->DispatchIsLiveStream(GetResource()->IsLiveStream());
+
   mDecoderStateMachine->InvokeSeek(aTarget)
   ->Then(mAbstractMainThread, __func__, this,
          &MediaDecoder::OnSeekResolved, &MediaDecoder::OnSeekRejected)
   ->Track(mSeekRequest);
 }
 
 double
 MediaDecoder::GetCurrentTime()
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2465,18 +2465,17 @@ DecodingState::MaybeStartBuffering()
 }
 
 void
 MediaDecoderStateMachine::
 SeekingState::SeekCompleted()
 {
   const auto newCurrentTime = CalculateNewCurrentTime();
 
-  bool isLiveStream = Resource()->IsLiveStream();
-  if (newCurrentTime == mMaster->Duration() && !isLiveStream) {
+  if (newCurrentTime == mMaster->Duration() && !mMaster->mIsLiveStream) {
     // Seeked to end of media. Explicitly finish the queues so DECODING
     // will transition to COMPLETED immediately. Note we don't do
     // this when playing a live stream, since the end of media will advance
     // once we download more data!
     AudioQueue().Finish();
     VideoQueue().Finish();
 
     // We won't start MediaSink when paused. m{Audio,Video}Completed will
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -214,16 +214,27 @@ public:
     nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
       "MediaDecoderStateMachine::DispatchCanPlayThrough",
       [self, aCanPlayThrough]() {
         self->mCanPlayThrough = aCanPlayThrough;
       });
     OwnerThread()->DispatchStateChange(r.forget());
   }
 
+  void DispatchIsLiveStream(bool aIsLiveStream)
+  {
+    RefPtr<MediaDecoderStateMachine> self = this;
+    nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
+      "MediaDecoderStateMachine::DispatchIsLiveStream",
+      [self, aIsLiveStream]() {
+        self->mIsLiveStream = aIsLiveStream;
+      });
+    OwnerThread()->DispatchStateChange(r.forget());
+  }
+
   // Drop reference to mResource. Only called during shutdown dance.
   void BreakCycles() {
     MOZ_ASSERT(NS_IsMainThread());
     mResource = nullptr;
   }
 
   TimedMetadataEventSource& TimedMetadataEvent() {
     return mMetadataManager.TimedMetadataEvent();
@@ -579,16 +590,18 @@ private:
   const char* AudioRequestStatus() const;
   const char* VideoRequestStatus() const;
 
   void OnSuspendTimerResolved();
   void CancelSuspendTimer();
 
   bool mCanPlayThrough = false;
 
+  bool mIsLiveStream = false;
+
   // True if we shouldn't play our audio (but still write it to any capturing
   // streams). When this is true, the audio thread will never start again after
   // it has stopped.
   bool mAudioCaptured;
 
   // True if all audio frames are already rendered.
   bool mAudioCompleted = false;