Bug 1317576. Part 1 - add some helper functions. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 14 Nov 2016 16:31:48 +0800
changeset 439468 3aace0492fef2d33a0f85a4d8e61dd30bd8bb554
parent 438821 407e59b429f7577050b5791a2efdf2684adf50d5
child 439469 c5c141c6d03920aab2012835f40bdf63a85c13a5
push id36009
push userjwwang@mozilla.com
push dateWed, 16 Nov 2016 02:24:06 +0000
bugs1317576
milestone53.0a1
Bug 1317576. Part 1 - add some helper functions. MozReview-Commit-ID: FNWmQohsDRq
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -232,16 +232,18 @@ protected:
   bool IsExpectingMoreData() const
   {
     // We are expecting more data if either the resource states so, or if we
     // have a waiting promise pending (such as with non-MSE EME).
     return Resource()->IsExpectingMoreData() ||
            (Reader()->IsWaitForDataSupported() &&
             (Reader()->IsWaitingAudioData() || Reader()->IsWaitingVideoData()));
   }
+  MediaQueue<MediaData>& AudioQueue() { return mMaster->mAudioQueue; }
+  MediaQueue<MediaData>& VideoQueue() { return mMaster->mVideoQueue; }
 
   // Note this function will delete the current state object.
   // Don't access members to avoid UAF after this call.
   template <class S, typename... Ts>
   auto SetState(Ts... aArgs)
     -> decltype(ReturnTypeHelper(&S::Enter))
   {
     // keep mMaster in a local object because mMaster will become invalid after
@@ -788,17 +790,17 @@ public:
         mSeekJob.mTarget.IsFast()) {
       mSeekTask = new AccurateSeekTask(
         mMaster->mDecoderID, OwnerThread(), Reader(), mSeekJob.mTarget,
         Info(), mMaster->Duration(), mMaster->GetMediaTime());
     } else if (mSeekJob.mTarget.IsNextFrame()) {
       mSeekTask = new NextFrameSeekTask(
         mMaster->mDecoderID, OwnerThread(), Reader(), mSeekJob.mTarget,
         Info(), mMaster->Duration(),mMaster->GetMediaTime(),
-        mMaster->AudioQueue(), mMaster->VideoQueue());
+        AudioQueue(), VideoQueue());
     } else {
       MOZ_DIAGNOSTIC_ASSERT(false, "Cannot handle this seek task.");
     }
 
     // Don't stop playback for a video-only seek since audio is playing.
     if (!mSeekJob.mTarget.IsVideoOnly()) {
       mMaster->StopPlayback();
     }
@@ -888,36 +890,36 @@ private:
 
     if (aValue.mSeekedVideoData) {
       mMaster->Push(aValue.mSeekedVideoData, MediaData::VIDEO_DATA);
       mMaster->mDecodedVideoEndTime = std::max(
         aValue.mSeekedVideoData->GetEndTime(), mMaster->mDecodedVideoEndTime);
     }
 
     if (aValue.mIsAudioQueueFinished) {
-      mMaster->AudioQueue().Finish();
+      AudioQueue().Finish();
     }
 
     if (aValue.mIsVideoQueueFinished) {
-      mMaster->VideoQueue().Finish();
+      VideoQueue().Finish();
     }
 
     SeekCompleted();
   }
 
   void OnSeekTaskRejected(const SeekTaskRejectValue& aValue)
   {
     mSeekTaskRequest.Complete();
 
     if (aValue.mIsAudioQueueFinished) {
-      mMaster->AudioQueue().Finish();
+      AudioQueue().Finish();
     }
 
     if (aValue.mIsVideoQueueFinished) {
-      mMaster->VideoQueue().Finish();
+      VideoQueue().Finish();
     }
 
     mMaster->DecodeError(aValue.mError);
   }
 
   void SeekCompleted();
 
   SeekJob mSeekJob;
@@ -1368,18 +1370,18 @@ DecodingFirstFrameState::HandleSeek(Seek
 }
 
 void
 MediaDecoderStateMachine::
 DecodingFirstFrameState::MaybeFinishDecodeFirstFrame()
 {
   MOZ_ASSERT(!mMaster->mSentFirstFrameLoadedEvent);
 
-  if ((mMaster->IsAudioDecoding() && mMaster->AudioQueue().GetSize() == 0) ||
-      (mMaster->IsVideoDecoding() && mMaster->VideoQueue().GetSize() == 0)) {
+  if ((mMaster->IsAudioDecoding() && AudioQueue().GetSize() == 0) ||
+      (mMaster->IsVideoDecoding() && VideoQueue().GetSize() == 0)) {
     return;
   }
 
   mMaster->FinishDecodeFirstFrame();
 
   if (mPendingSeek.Exists()) {
     SetState<SeekingState>(Move(mPendingSeek), EventVisibility::Observable);
   } else {
@@ -1473,17 +1475,17 @@ SeekingState::SeekCompleted()
   int64_t seekTime = mSeekTask->GetSeekTarget().GetTime().ToMicroseconds();
   int64_t newCurrentTime = seekTime;
 
   // Setup timestamp state.
   RefPtr<MediaData> video = mMaster->VideoQueue().PeekFront();
   if (seekTime == mMaster->Duration().ToMicroseconds()) {
     newCurrentTime = seekTime;
   } else if (mMaster->HasAudio()) {
-    RefPtr<MediaData> audio = mMaster->AudioQueue().PeekFront();
+    RefPtr<MediaData> audio = AudioQueue().PeekFront();
     // Though we adjust the newCurrentTime in audio-based, and supplemented
     // by video. For better UX, should NOT bind the slide position to
     // the first audio data timestamp directly.
     // While seeking to a position where there's only either audio or video, or
     // seeking to a position lies before audio or video, we need to check if
     // seekTime is bounded in suitable duration. See Bug 1112438.
     int64_t audioStart = audio ? audio->mTime : seekTime;
     // We only pin the seek time to the video start time if the video frame