Bug 1322800 part 10 - use StateObject::{Audio,Video}Queue() to replate NextFrameSeekTask::m{Audio,Video}Queue; r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Wed, 14 Dec 2016 15:41:31 +0800
changeset 450338 04a12b0bf770991e2670e4db2054233b5485d541
parent 450337 a9116197ff7686cac2230c1fb31a0d6d4b5389cb
child 450339 337900aa0f40f68ceb495f4775b4fce358243133
push id38836
push userbmo:kaku@mozilla.com
push dateFri, 16 Dec 2016 10:40:27 +0000
reviewersjwwang
bugs1322800
milestone53.0a1
Bug 1322800 part 10 - use StateObject::{Audio,Video}Queue() to replate NextFrameSeekTask::m{Audio,Video}Queue; r?jwwang MozReview-Commit-ID: Df87tNjaeAF
dom/media/MediaDecoderStateMachine.cpp
dom/media/NextFrameSeekTask.cpp
dom/media/NextFrameSeekTask.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -236,18 +236,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; }
+  MediaQueue<MediaData>& AudioQueue() const { return mMaster->mAudioQueue; }
+  MediaQueue<MediaData>& VideoQueue() const { 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
@@ -1378,17 +1378,17 @@ private:
   void ResetMDSM() override
   {
     // Do nothing.
   }
 
   void DoSeek() override
   {
     auto currentTime = mTask->mCurrentTime;
-    DiscardFrames(mTask->mVideoQueue, [currentTime] (int64_t aSampleTime) {
+    DiscardFrames(VideoQueue(), [currentTime] (int64_t aSampleTime) {
       return aSampleTime <= currentTime;
     });
 
     mSeekTaskRequest.Begin(mSeekTask->Seek(mMaster->Duration())
       ->Then(OwnerThread(), __func__,
              [this] (const SeekTaskResolveValue& aValue) {
                OnSeekTaskResolved(aValue);
              },
@@ -1593,19 +1593,19 @@ private:
   void RequestVideoData()
   {
     Reader()->RequestVideoData(false, media::TimeUnit());
   }
 
   bool NeedMoreVideo() const
   {
     // Need to request video when we have none and video queue is not finished.
-    return mTask->mVideoQueue.GetSize() == 0 &&
+    return VideoQueue().GetSize() == 0 &&
            !mTask->mSeekedVideoData &&
-           !mTask->mVideoQueue.IsFinished() &&
+           !VideoQueue().IsFinished() &&
            !mTask->mIsVideoQueueFinished;
   }
 
   bool IsVideoRequestPending() const
   {
     return Reader()->IsRequestingVideoData() || Reader()->IsWaitingVideoData();
   }
 
@@ -1622,35 +1622,35 @@ private:
     // lose video samples for the promise is resolved asynchronously.
     return !IsVideoRequestPending() && !NeedMoreVideo();
   }
 
   // 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()
   {
-    RefPtr<MediaData> data = mTask->mVideoQueue.PeekFront();
+    RefPtr<MediaData> data = VideoQueue().PeekFront();
     if (data) {
       mTask->mTarget.SetTime(TimeUnit::FromMicroseconds(data->mTime));
     } else if (mTask->mSeekedVideoData) {
       mTask->mTarget.SetTime(TimeUnit::FromMicroseconds(mTask->mSeekedVideoData->mTime));
-    } else if (mTask->mIsVideoQueueFinished || mTask->mVideoQueue.AtEndOfStream()) {
+    } else if (mTask->mIsVideoQueueFinished || VideoQueue().AtEndOfStream()) {
       mTask->mTarget.SetTime(mTask->mDuration);
     } else {
       MOZ_ASSERT(false, "No data!");
     }
   }
 
   void MaybeFinishSeek()
   {
     if (IsAudioSeekComplete() && IsVideoSeekComplete()) {
       UpdateSeekTargetTime();
 
       auto time = mTask->mTarget.GetTime().ToMicroseconds();
-      DiscardFrames(mTask->mAudioQueue, [time] (int64_t aSampleTime) {
+      DiscardFrames(AudioQueue(), [time] (int64_t aSampleTime) {
         return aSampleTime < time;
       });
 
       mTask->Resolve(__func__); // Call to MDSM::SeekCompleted();
     }
   }
 
   // For refactoring only, will be removed later.
--- a/dom/media/NextFrameSeekTask.cpp
+++ b/dom/media/NextFrameSeekTask.cpp
@@ -24,18 +24,16 @@ NextFrameSeekTask::NextFrameSeekTask(con
                                      MediaDecoderReaderWrapper* aReader,
                                      const SeekTarget& aTarget,
                                      const MediaInfo& aInfo,
                                      const media::TimeUnit& aDuration,
                                      int64_t aCurrentTime,
                                      MediaQueue<MediaData>& aAudioQueue,
                                      MediaQueue<MediaData>& aVideoQueue)
   : SeekTask(aDecoderID, aThread, aReader, aTarget)
-  , mAudioQueue(aAudioQueue)
-  , mVideoQueue(aVideoQueue)
   , mCurrentTime(aCurrentTime)
   , mDuration(aDuration)
 {
   AssertOwnerThread();
   MOZ_ASSERT(aInfo.HasVideo());
 }
 
 NextFrameSeekTask::~NextFrameSeekTask()
--- a/dom/media/NextFrameSeekTask.h
+++ b/dom/media/NextFrameSeekTask.h
@@ -50,22 +50,16 @@ public:
 
   void HandleVideoWaited(MediaData::Type aType) override;
 
   void HandleNotWaited(const WaitForDataRejectValue& aRejection) override;
 
   ~NextFrameSeekTask();
 
   /*
-   * Data shared with MDSM.
-   */
-  MediaQueue<MediaData>& mAudioQueue;
-  MediaQueue<MediaData>& mVideoQueue;
-
-  /*
    * Internal state.
    */
   const int64_t mCurrentTime;
   media::TimeUnit mDuration;
 };
 
 } // namespace media
 } // namespace mozilla