Bug 1320466 part 5 - implement media data waited/not-waited handlers in SeekTask; r=jwwang
authorKaku Kuo <kaku@mozilla.com>
Sat, 26 Nov 2016 14:44:12 +0800
changeset 324931 38c2d58de393339a8ffc76e188f0e4ff68844229
parent 324930 e102e1d94504b6e93256a1613a0f9a9240ae941c
child 324932 2db94d238128bef513f7cff768f87ad4056030a1
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjwwang
bugs1320466
milestone53.0a1
Bug 1320466 part 5 - implement media data waited/not-waited handlers in SeekTask; r=jwwang MozReview-Commit-ID: HLlUnBxtNcy
dom/media/AccurateSeekTask.cpp
dom/media/AccurateSeekTask.h
dom/media/NextFrameSeekTask.cpp
dom/media/NextFrameSeekTask.h
dom/media/SeekTask.h
--- a/dom/media/AccurateSeekTask.cpp
+++ b/dom/media/AccurateSeekTask.cpp
@@ -128,16 +128,41 @@ AccurateSeekTask::HandleVideoDecoded(Med
 
 void
 AccurateSeekTask::HandleNotDecoded(MediaData::Type aType, const MediaResult& aError)
 {
   AssertOwnerThread();
   OnNotDecoded(aType, aError);
 }
 
+void
+AccurateSeekTask::HandleAudioWaited(MediaData::Type aType)
+{
+  AssertOwnerThread();
+
+  // Ignore pending requests from video-only seek.
+  if (mTarget.IsVideoOnly()) {
+    return;
+  }
+  RequestAudioData();
+}
+
+void
+AccurateSeekTask::HandleVideoWaited(MediaData::Type aType)
+{
+  AssertOwnerThread();
+  RequestVideoData();
+}
+
+void
+AccurateSeekTask::HandleNotWaited(const WaitForDataRejectValue& aRejection)
+{
+  AssertOwnerThread();
+}
+
 RefPtr<AccurateSeekTask::SeekTaskPromise>
 AccurateSeekTask::Seek(const media::TimeUnit& aDuration)
 {
   AssertOwnerThread();
 
   // Do the seek.
   mSeekRequest.Begin(mReader->Seek(mTarget, aDuration)
     ->Then(OwnerThread(), __func__, this,
@@ -491,29 +516,29 @@ AccurateSeekTask::SetCallbacks()
     } else {
       OnNotDecoded(MediaData::VIDEO_DATA,
         aData.as<MediaResult>());
     }
   });
 
   mAudioWaitCallback = mReader->AudioWaitCallback().Connect(
     OwnerThread(), [this] (WaitCallbackData aData) {
-    // Ignore pending requests from video-only seek.
-    if (mTarget.IsVideoOnly()) {
-      return;
-    }
     if (aData.is<MediaData::Type>()) {
-      RequestAudioData();
+      HandleAudioWaited(aData.as<MediaData::Type>());
+    } else {
+      HandleNotWaited(aData.as<WaitForDataRejectValue>());
     }
   });
 
   mVideoWaitCallback = mReader->VideoWaitCallback().Connect(
     OwnerThread(), [this] (WaitCallbackData aData) {
     if (aData.is<MediaData::Type>()) {
-      RequestVideoData();
+      HandleVideoWaited(aData.as<MediaData::Type>());
+    } else {
+      HandleNotWaited(aData.as<WaitForDataRejectValue>());
     }
   });
 }
 
 void
 AccurateSeekTask::CancelCallbacks()
 {
   AssertOwnerThread();
--- a/dom/media/AccurateSeekTask.h
+++ b/dom/media/AccurateSeekTask.h
@@ -32,16 +32,22 @@ public:
   int64_t CalculateNewCurrentTime() const override;
 
   void HandleAudioDecoded(MediaData* aAudio) override;
 
   void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override;
 
   void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) override;
 
+  void HandleAudioWaited(MediaData::Type aType) override;
+
+  void HandleVideoWaited(MediaData::Type aType) override;
+
+  void HandleNotWaited(const WaitForDataRejectValue& aRejection) override;
+
 private:
   ~AccurateSeekTask();
 
   void RequestVideoData();
 
   void RequestAudioData();
 
   nsresult DropAudioUpToSeekTarget(MediaData* aSample);
--- a/dom/media/NextFrameSeekTask.cpp
+++ b/dom/media/NextFrameSeekTask.cpp
@@ -103,16 +103,67 @@ NextFrameSeekTask::HandleNotDecoded(Medi
   case MediaData::VIDEO_DATA:
     OnVideoNotDecoded(aError);
     break;
   default:
     MOZ_ASSERT_UNREACHABLE("We cannot handle RAW_DATA or NULL_DATA here.");
   }
 }
 
+void
+NextFrameSeekTask::HandleAudioWaited(MediaData::Type aType)
+{
+  AssertOwnerThread();
+
+  // We don't make an audio decode request here, instead, let MDSM to
+  // trigger further audio decode tasks if MDSM itself needs to play audio.
+  MaybeFinishSeek();
+}
+
+void
+NextFrameSeekTask::HandleVideoWaited(MediaData::Type aType)
+{
+  AssertOwnerThread();
+
+  if (NeedMoreVideo()) {
+    RequestVideoData();
+    return;
+  }
+  MaybeFinishSeek();
+}
+
+void
+NextFrameSeekTask::HandleNotWaited(const WaitForDataRejectValue& aRejection)
+{
+  AssertOwnerThread();
+
+  switch(aRejection.mType) {
+  case MediaData::AUDIO_DATA:
+  {
+    // We don't make an audio decode request here, instead, let MDSM to
+    // trigger further audio decode tasks if MDSM itself needs to play audio.
+    MaybeFinishSeek();
+    break;
+  }
+  case MediaData::VIDEO_DATA:
+  {
+    if (NeedMoreVideo()) {
+      // Reject if we can't finish video seeking.
+      CancelCallbacks();
+      RejectIfExist(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
+      return;
+    }
+    MaybeFinishSeek();
+    break;
+  }
+  default:
+    MOZ_ASSERT_UNREACHABLE("We cannot handle RAW_DATA or NULL_DATA here.");
+  }
+}
+
 /*
  * Remove samples from the queue until aCompare() returns false.
  * aCompare A function object with the signature bool(int64_t) which returns
  *          true for samples that should be removed.
  */
 template <typename Function> static void
 DiscardFrames(MediaQueue<MediaData>& aQueue, const Function& aCompare)
 {
@@ -325,34 +376,30 @@ NextFrameSeekTask::SetCallbacks()
       OnVideoDecoded(Get<0>(aData.as<Type>()));
     } else {
       OnVideoNotDecoded(aData.as<MediaResult>());
     }
   });
 
   mAudioWaitCallback = mReader->AudioWaitCallback().Connect(
     OwnerThread(), [this] (WaitCallbackData aData) {
-    // We don't make an audio decode request here, instead, let MDSM to
-    // trigger further audio decode tasks if MDSM itself needs to play audio.
-    MaybeFinishSeek();
+    if (aData.is<MediaData::Type>()) {
+      HandleAudioWaited(aData.as<MediaData::Type>());
+    } else {
+      HandleNotWaited(aData.as<WaitForDataRejectValue>());
+    }
   });
 
   mVideoWaitCallback = mReader->VideoWaitCallback().Connect(
     OwnerThread(), [this] (WaitCallbackData aData) {
-    if (NeedMoreVideo()) {
-      if (aData.is<MediaData::Type>()) {
-        RequestVideoData();
-      } else {
-        // Reject if we can't finish video seeking.
-        CancelCallbacks();
-        RejectIfExist(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
-      }
-      return;
+    if (aData.is<MediaData::Type>()) {
+      HandleVideoWaited(aData.as<MediaData::Type>());
+    } else {
+      HandleNotWaited(aData.as<WaitForDataRejectValue>());
     }
-    MaybeFinishSeek();
   });
 }
 
 void
 NextFrameSeekTask::CancelCallbacks()
 {
   AssertOwnerThread();
   mAudioCallback.DisconnectIfExists();
--- a/dom/media/NextFrameSeekTask.h
+++ b/dom/media/NextFrameSeekTask.h
@@ -43,16 +43,22 @@ public:
   int64_t CalculateNewCurrentTime() const override;
 
   void HandleAudioDecoded(MediaData* aAudio) override;
 
   void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override;
 
   void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) override;
 
+  void HandleAudioWaited(MediaData::Type aType) override;
+
+  void HandleVideoWaited(MediaData::Type aType) override;
+
+  void HandleNotWaited(const WaitForDataRejectValue& aRejection) override;
+
 private:
   ~NextFrameSeekTask();
 
   void RequestVideoData();
 
   bool NeedMoreVideo() const;
 
   bool IsVideoRequestPending() const;
--- a/dom/media/SeekTask.h
+++ b/dom/media/SeekTask.h
@@ -63,16 +63,22 @@ public:
   const SeekTarget& GetSeekTarget();
 
   virtual void HandleAudioDecoded(MediaData* aAudio) = 0;
 
   virtual void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) = 0;
 
   virtual void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) = 0;
 
+  virtual void HandleAudioWaited(MediaData::Type aType) = 0;
+
+  virtual void HandleVideoWaited(MediaData::Type aType) = 0;
+
+  virtual void HandleNotWaited(const WaitForDataRejectValue& aRejection) = 0;
+
 protected:
   SeekTask(const void* aDecoderID,
            AbstractThread* aThread,
            MediaDecoderReaderWrapper* aReader,
            const SeekTarget& aTarget);
 
   virtual ~SeekTask();