Bug 1320466 part 8 - clean up redundant fucntion calls; r=jwwang
authorKaku Kuo <kaku@mozilla.com>
Sun, 27 Nov 2016 00:07:25 +0800
changeset 324934 98428e833421048961cc630f709eedca4a1bce6f
parent 324933 3a13ac4fb7a65965b6dd6a67c30d9e68d5d10413
child 324935 0d8eb74cce6f781c95d84c875b6f94dd6a29c305
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjwwang
bugs1320466
milestone53.0a1
Bug 1320466 part 8 - clean up redundant fucntion calls; r=jwwang MozReview-Commit-ID: 9zfbUGLLeee
dom/media/AccurateSeekTask.cpp
dom/media/AccurateSeekTask.h
dom/media/NextFrameSeekTask.cpp
dom/media/NextFrameSeekTask.h
--- a/dom/media/AccurateSeekTask.cpp
+++ b/dom/media/AccurateSeekTask.cpp
@@ -107,31 +107,138 @@ AccurateSeekTask::CalculateNewCurrentTim
   MOZ_ASSERT(false, "AccurateSeekTask doesn't handle other seek types.");
   return 0;
 }
 
 void
 AccurateSeekTask::HandleAudioDecoded(MediaData* aAudio)
 {
   AssertOwnerThread();
-  OnAudioDecoded(aAudio);
+  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+  RefPtr<MediaData> audio(aAudio);
+  MOZ_ASSERT(audio);
+
+  // The MDSM::mDecodedAudioEndTime will be updated once the whole SeekTask is
+  // resolved.
+
+  SAMPLE_LOG("OnAudioDecoded [%lld,%lld]", audio->mTime, audio->GetEndTime());
+
+  // Video-only seek doesn't reset audio decoder. There might be pending audio
+  // requests when AccurateSeekTask::Seek() begins. We will just store the data
+  // without checking |mDiscontinuity| or calling DropAudioUpToSeekTarget().
+  if (mTarget.IsVideoOnly()) {
+    mSeekedAudioData = audio.forget();
+    return;
+  }
+
+  AdjustFastSeekIfNeeded(audio);
+
+  if (mTarget.IsFast()) {
+    // Non-precise seek; we can stop the seek at the first sample.
+    mSeekedAudioData = audio;
+    mDoneAudioSeeking = true;
+  } else {
+    nsresult rv = DropAudioUpToSeekTarget(audio);
+    if (NS_FAILED(rv)) {
+      RejectIfExist(rv, __func__);
+      return;
+    }
+  }
+
+  if (!mDoneAudioSeeking) {
+    RequestAudioData();
+    return;
+  }
+  MaybeFinishSeek();
 }
 
 void
 AccurateSeekTask::HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart)
 {
   AssertOwnerThread();
-  OnVideoDecoded(aVideo);
+  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+  RefPtr<MediaData> video(aVideo);
+  MOZ_ASSERT(video);
+
+  // The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
+  // resolved.
+
+  SAMPLE_LOG("OnVideoDecoded [%lld,%lld]", video->mTime, video->GetEndTime());
+
+  AdjustFastSeekIfNeeded(video);
+
+  if (mTarget.IsFast()) {
+    // Non-precise seek. We can stop the seek at the first sample.
+    mSeekedVideoData = video;
+    mDoneVideoSeeking = true;
+  } else {
+    nsresult rv = DropVideoUpToSeekTarget(video.get());
+    if (NS_FAILED(rv)) {
+      RejectIfExist(rv, __func__);
+      return;
+    }
+  }
+
+  if (!mDoneVideoSeeking) {
+    RequestVideoData();
+    return;
+  }
+  MaybeFinishSeek();
 }
 
 void
 AccurateSeekTask::HandleNotDecoded(MediaData::Type aType, const MediaResult& aError)
 {
   AssertOwnerThread();
-  OnNotDecoded(aType, aError);
+  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+  SAMPLE_LOG("OnNotDecoded type=%d reason=%u", aType, aError.Code());
+
+  // Ignore pending requests from video-only seek.
+  if (aType == MediaData::AUDIO_DATA && mTarget.IsVideoOnly()) {
+    return;
+  }
+
+  // If the decoder is waiting for data, we tell it to call us back when the
+  // data arrives.
+  if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
+    mReader->WaitForData(aType);
+    return;
+  }
+
+  if (aError == NS_ERROR_DOM_MEDIA_CANCELED) {
+    if (aType == MediaData::AUDIO_DATA) {
+      RequestAudioData();
+    } else {
+      RequestVideoData();
+    }
+    return;
+  }
+
+  if (aError == NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
+    if (aType == MediaData::AUDIO_DATA) {
+      mIsAudioQueueFinished = true;
+      mDoneAudioSeeking = true;
+    } else {
+      mIsVideoQueueFinished = true;
+      mDoneVideoSeeking = true;
+      if (mFirstVideoFrameAfterSeek) {
+        // Hit the end of stream. Move mFirstVideoFrameAfterSeek into
+        // mSeekedVideoData so we have something to display after seeking.
+        mSeekedVideoData = mFirstVideoFrameAfterSeek.forget();
+      }
+    }
+    MaybeFinishSeek();
+    return;
+  }
+
+  // This is a decode error, delegate to the generic error path.
+  RejectIfExist(aError, __func__);
 }
 
 void
 AccurateSeekTask::HandleAudioWaited(MediaData::Type aType)
 {
   AssertOwnerThread();
 
   // Ignore pending requests from video-only seek.
@@ -352,138 +459,9 @@ AccurateSeekTask::AdjustFastSeekIfNeeded
     // seek and decode to the seek target. This is not conformant to the
     // spec, fastSeek should always be fast, but until we get the time to
     // change all Readers to seek to the keyframe after the currentTime
     // in this case, we'll just decode forward. Bug 1026330.
     mTarget.SetType(SeekTarget::Accurate);
   }
 }
 
-void
-AccurateSeekTask::OnAudioDecoded(MediaData* aAudioSample)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  RefPtr<MediaData> audio(aAudioSample);
-  MOZ_ASSERT(audio);
-
-  // The MDSM::mDecodedAudioEndTime will be updated once the whole SeekTask is
-  // resolved.
-
-  SAMPLE_LOG("OnAudioDecoded [%lld,%lld]", audio->mTime, audio->GetEndTime());
-
-  // Video-only seek doesn't reset audio decoder. There might be pending audio
-  // requests when AccurateSeekTask::Seek() begins. We will just store the data
-  // without checking |mDiscontinuity| or calling DropAudioUpToSeekTarget().
-  if (mTarget.IsVideoOnly()) {
-    mSeekedAudioData = audio.forget();
-    return;
-  }
-
-  AdjustFastSeekIfNeeded(audio);
-
-  if (mTarget.IsFast()) {
-    // Non-precise seek; we can stop the seek at the first sample.
-    mSeekedAudioData = audio;
-    mDoneAudioSeeking = true;
-  } else {
-    nsresult rv = DropAudioUpToSeekTarget(audio);
-    if (NS_FAILED(rv)) {
-      RejectIfExist(rv, __func__);
-      return;
-    }
-  }
-
-  if (!mDoneAudioSeeking) {
-    RequestAudioData();
-    return;
-  }
-  MaybeFinishSeek();
-}
-
-void
-AccurateSeekTask::OnNotDecoded(MediaData::Type aType,
-                               const MediaResult& aError)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  SAMPLE_LOG("OnNotDecoded type=%d reason=%u", aType, aError.Code());
-
-  // Ignore pending requests from video-only seek.
-  if (aType == MediaData::AUDIO_DATA && mTarget.IsVideoOnly()) {
-    return;
-  }
-
-  // If the decoder is waiting for data, we tell it to call us back when the
-  // data arrives.
-  if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
-    mReader->WaitForData(aType);
-    return;
-  }
-
-  if (aError == NS_ERROR_DOM_MEDIA_CANCELED) {
-    if (aType == MediaData::AUDIO_DATA) {
-      RequestAudioData();
-    } else {
-      RequestVideoData();
-    }
-    return;
-  }
-
-  if (aError == NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
-    if (aType == MediaData::AUDIO_DATA) {
-      mIsAudioQueueFinished = true;
-      mDoneAudioSeeking = true;
-    } else {
-      mIsVideoQueueFinished = true;
-      mDoneVideoSeeking = true;
-      if (mFirstVideoFrameAfterSeek) {
-        // Hit the end of stream. Move mFirstVideoFrameAfterSeek into
-        // mSeekedVideoData so we have something to display after seeking.
-        mSeekedVideoData = mFirstVideoFrameAfterSeek.forget();
-      }
-    }
-    MaybeFinishSeek();
-    return;
-  }
-
-  // This is a decode error, delegate to the generic error path.
-  RejectIfExist(aError, __func__);
-}
-
-void
-AccurateSeekTask::OnVideoDecoded(MediaData* aVideoSample)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  RefPtr<MediaData> video(aVideoSample);
-  MOZ_ASSERT(video);
-
-  // The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
-  // resolved.
-
-  SAMPLE_LOG("OnVideoDecoded [%lld,%lld]", video->mTime, video->GetEndTime());
-
-  AdjustFastSeekIfNeeded(video);
-
-  if (mTarget.IsFast()) {
-    // Non-precise seek. We can stop the seek at the first sample.
-    mSeekedVideoData = video;
-    mDoneVideoSeeking = true;
-  } else {
-    nsresult rv = DropVideoUpToSeekTarget(video.get());
-    if (NS_FAILED(rv)) {
-      RejectIfExist(rv, __func__);
-      return;
-    }
-  }
-
-  if (!mDoneVideoSeeking) {
-    RequestVideoData();
-    return;
-  }
-  MaybeFinishSeek();
-}
-
 } // namespace mozilla
--- a/dom/media/AccurateSeekTask.h
+++ b/dom/media/AccurateSeekTask.h
@@ -55,22 +55,16 @@ private:
   nsresult DropVideoUpToSeekTarget(MediaData* aSample);
 
   void MaybeFinishSeek();
 
   void OnSeekResolved(media::TimeUnit);
 
   void OnSeekRejected(nsresult aResult);
 
-  void OnAudioDecoded(MediaData* aAudioSample);
-
-  void OnVideoDecoded(MediaData* aVideoSample);
-
-  void OnNotDecoded(MediaData::Type, const MediaResult&);
-
   void AdjustFastSeekIfNeeded(MediaData* aSample);
 
   /*
    * Internal state.
    */
   const media::TimeUnit mCurrentTimeBeforeSeek;
   const uint32_t mAudioRate;  // Audio sample rate.
   bool mDoneAudioSeeking;
--- a/dom/media/NextFrameSeekTask.cpp
+++ b/dom/media/NextFrameSeekTask.cpp
@@ -71,37 +71,105 @@ NextFrameSeekTask::CalculateNewCurrentTi
   // which has been updated to the next frame's time.
   return mTarget.GetTime().ToMicroseconds();
 }
 
 void
 NextFrameSeekTask::HandleAudioDecoded(MediaData* aAudio)
 {
   AssertOwnerThread();
-  OnAudioDecoded(aAudio);
+  MOZ_ASSERT(aAudio);
+  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+  // The MDSM::mDecodedAudioEndTime will be updated once the whole SeekTask is
+  // resolved.
+
+  SAMPLE_LOG("OnAudioDecoded [%lld,%lld]", aAudio->mTime, aAudio->GetEndTime());
+
+  // We accept any audio data here.
+  mSeekedAudioData = aAudio;
+
+  MaybeFinishSeek();
 }
 
 void
 NextFrameSeekTask::HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart)
 {
   AssertOwnerThread();
-  OnVideoDecoded(aVideo);
+  MOZ_ASSERT(aVideo);
+  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+  // The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
+  // resolved.
+
+  SAMPLE_LOG("OnVideoDecoded [%lld,%lld]", aVideo->mTime, aVideo->GetEndTime());
+
+  if (aVideo->mTime > mCurrentTime) {
+    mSeekedVideoData = aVideo;
+  }
+
+  if (NeedMoreVideo()) {
+    RequestVideoData();
+    return;
+  }
+
+  MaybeFinishSeek();
 }
 
 void
 NextFrameSeekTask::HandleNotDecoded(MediaData::Type aType, const MediaResult& aError)
 {
   AssertOwnerThread();
   switch (aType) {
   case MediaData::AUDIO_DATA:
-    OnAudioNotDecoded(aError);
+  {
+    MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+    SAMPLE_LOG("OnAudioNotDecoded (aError=%u)", aError.Code());
+
+    // We don't really handle audio deocde error here. Let MDSM to trigger further
+    // audio decoding tasks if it needs to play audio, and MDSM will then receive
+    // the decoding state from MediaDecoderReader.
+
+    MaybeFinishSeek();
     break;
+  }
   case MediaData::VIDEO_DATA:
-    OnVideoNotDecoded(aError);
+  {
+    MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
+
+    SAMPLE_LOG("OnVideoNotDecoded (aError=%u)", aError.Code());
+
+    if (aError == NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
+      mIsVideoQueueFinished = true;
+    }
+
+    // Video seek not finished.
+    if (NeedMoreVideo()) {
+      switch (aError.Code()) {
+        case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
+          mReader->WaitForData(MediaData::VIDEO_DATA);
+          break;
+        case NS_ERROR_DOM_MEDIA_CANCELED:
+          RequestVideoData();
+          break;
+        case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
+          MOZ_ASSERT(false, "Shouldn't want more data for ended video.");
+          break;
+        default:
+          // Reject the promise since we can't finish video seek anyway.
+          RejectIfExist(aError, __func__);
+          break;
+      }
+      return;
+    }
+
+    MaybeFinishSeek();
     break;
+  }
   default:
     MOZ_ASSERT_UNREACHABLE("We cannot handle RAW_DATA or NULL_DATA here.");
   }
 }
 
 void
 NextFrameSeekTask::HandleAudioWaited(MediaData::Type aType)
 {
@@ -242,112 +310,16 @@ NextFrameSeekTask::MaybeFinishSeek()
       return aSampleTime < time;
     });
 
     Resolve(__func__); // Call to MDSM::SeekCompleted();
   }
 }
 
 void
-NextFrameSeekTask::OnAudioDecoded(MediaData* aAudioSample)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(aAudioSample);
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  // The MDSM::mDecodedAudioEndTime will be updated once the whole SeekTask is
-  // resolved.
-
-  SAMPLE_LOG("OnAudioDecoded [%lld,%lld]",
-             aAudioSample->mTime,
-             aAudioSample->GetEndTime());
-
-  // We accept any audio data here.
-  mSeekedAudioData = aAudioSample;
-
-  MaybeFinishSeek();
-}
-
-void
-NextFrameSeekTask::OnAudioNotDecoded(const MediaResult& aError)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  SAMPLE_LOG("OnAudioNotDecoded (aError=%u)", aError.Code());
-
-  // We don't really handle audio deocde error here. Let MDSM to trigger further
-  // audio decoding tasks if it needs to play audio, and MDSM will then receive
-  // the decoding state from MediaDecoderReader.
-
-  MaybeFinishSeek();
-}
-
-void
-NextFrameSeekTask::OnVideoDecoded(MediaData* aVideoSample)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(aVideoSample);
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  // The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
-  // resolved.
-
-  SAMPLE_LOG("OnVideoDecoded [%lld,%lld]",
-             aVideoSample->mTime,
-             aVideoSample->GetEndTime());
-
-  if (aVideoSample->mTime > mCurrentTime) {
-    mSeekedVideoData = aVideoSample;
-  }
-
-  if (NeedMoreVideo()) {
-    RequestVideoData();
-    return;
-  }
-
-  MaybeFinishSeek();
-}
-
-void
-NextFrameSeekTask::OnVideoNotDecoded(const MediaResult& aError)
-{
-  AssertOwnerThread();
-  MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
-
-  SAMPLE_LOG("OnVideoNotDecoded (aError=%u)", aError.Code());
-
-  if (aError == NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
-    mIsVideoQueueFinished = true;
-  }
-
-  // Video seek not finished.
-  if (NeedMoreVideo()) {
-    switch (aError.Code()) {
-      case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
-        mReader->WaitForData(MediaData::VIDEO_DATA);
-        break;
-      case NS_ERROR_DOM_MEDIA_CANCELED:
-        RequestVideoData();
-        break;
-      case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
-        MOZ_ASSERT(false, "Shouldn't want more data for ended video.");
-        break;
-      default:
-        // Reject the promise since we can't finish video seek anyway.
-        RejectIfExist(aError, __func__);
-        break;
-    }
-    return;
-  }
-
-  MaybeFinishSeek();
-}
-
-void
 NextFrameSeekTask::UpdateSeekTargetTime()
 {
   AssertOwnerThread();
 
   RefPtr<MediaData> data = mVideoQueue.PeekFront();
   if (data) {
     mTarget.SetTime(TimeUnit::FromMicroseconds(data->mTime));
   } else if (mSeekedVideoData) {
--- a/dom/media/NextFrameSeekTask.h
+++ b/dom/media/NextFrameSeekTask.h
@@ -64,24 +64,16 @@ private:
   bool IsVideoRequestPending() const;
 
   bool IsAudioSeekComplete() const;
 
   bool IsVideoSeekComplete() const;
 
   void MaybeFinishSeek();
 
-  void OnAudioDecoded(MediaData* aAudioSample);
-
-  void OnAudioNotDecoded(const MediaResult& aError);
-
-  void OnVideoDecoded(MediaData* aVideoSample);
-
-  void OnVideoNotDecoded(const MediaResult& aError);
-
   // Update the seek target's time before resolving this seek task, the updated
   // time will be used in the MDSM::SeekCompleted() to update the MDSM's position.
   void UpdateSeekTargetTime();
 
   /*
    * Data shared with MDSM.
    */
   MediaQueue<MediaData>& mAudioQueue;