Bug 1255268 - Replace SeekJob::Steal() with move semantics. r=cpearce. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 10 Mar 2016 15:30:32 +0800
changeset 339330 3573aa9590bdfcfa79e3be7a2e9625ed34e348fc
parent 339329 8bf3bdd5097177ce3e939a1ee232848dbb8c2c2e
child 515967 ae5685b4ee13affaae1a442e3a2f1ee385c48f87
push id12701
push userjwwang@mozilla.com
push dateFri, 11 Mar 2016 00:53:53 +0000
reviewerscpearce
bugs1255268
milestone48.0a1
Bug 1255268 - Replace SeekJob::Steal() with move semantics. r=cpearce. MozReview-Commit-ID: 3idqNa2MWA9
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -858,17 +858,17 @@ MediaDecoderStateMachine::MaybeFinishDec
   }
   FinishDecodeFirstFrame();
   if (!mQueuedSeek.Exists()) {
     return false;
   }
 
   // We can now complete the pending seek.
   SetState(DECODER_STATE_SEEKING);
-  InitiateSeek(mQueuedSeek);
+  InitiateSeek(Move(mQueuedSeek));
   return true;
 }
 
 void
 MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideoSample,
                                          TimeStamp aDecodeStartTime)
 {
   MOZ_ASSERT(OnTaskQueue());
@@ -1263,17 +1263,17 @@ MediaDecoderStateMachine::SetDormant(boo
 
   DECODER_LOG("SetDormant=%d", aDormant);
 
   if (aDormant) {
     if (mState == DECODER_STATE_SEEKING) {
       if (mQueuedSeek.Exists()) {
         // Keep latest seek target
       } else if (mCurrentSeek.Exists()) {
-        mQueuedSeek.Steal(mCurrentSeek);
+        mQueuedSeek = Move(mCurrentSeek);
       } else {
         mQueuedSeek.mTarget = SeekTarget(mCurrentPosition,
                                          SeekTarget::Accurate,
                                          MediaDecoderEventVisibility::Suppressed);
         // XXXbholley - Nobody is listening to this promise. Do we need to pass it
         // back to MediaDecoder when we come out of dormant?
         RefPtr<MediaDecoder::SeekPromise> unused = mQueuedSeek.mPromise.Ensure(__func__);
       }
@@ -1369,17 +1369,17 @@ void MediaDecoderStateMachine::StartDeco
       // we have the start time from last time we loaded.
       // FinishDecodeFirstFrame will be launched upon completion of the seek when
       // we have data ready to play.
       MOZ_ASSERT(mQueuedSeek.Exists() && mSentFirstFrameLoadedEvent,
                  "Return from dormant must have queued seek");
     }
     if (mQueuedSeek.Exists()) {
       SetState(DECODER_STATE_SEEKING);
-      InitiateSeek(mQueuedSeek);
+      InitiateSeek(Move(mQueuedSeek));
       return;
     }
   }
 
   mDecodeStartTime = TimeStamp::Now();
 
   CheckIfDecodeComplete();
   if (mState == DECODER_STATE_COMPLETED) {
@@ -1491,17 +1491,17 @@ MediaDecoderStateMachine::Seek(SeekTarge
   }
   mQueuedSeek.RejectIfExists(__func__);
 
   DECODER_LOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
   SetState(DECODER_STATE_SEEKING);
 
   SeekJob seekJob;
   seekJob.mTarget = aTarget;
-  InitiateSeek(seekJob);
+  InitiateSeek(Move(seekJob));
   return mCurrentSeek.mPromise.Ensure(__func__);
 }
 
 RefPtr<MediaDecoder::SeekPromise>
 MediaDecoderStateMachine::InvokeSeek(SeekTarget aTarget)
 {
   return InvokeAsync(OwnerThread(), this, __func__,
                      &MediaDecoderStateMachine::Seek, aTarget);
@@ -1572,22 +1572,22 @@ MediaDecoderStateMachine::DispatchDecode
                 GetDecodedAudioDuration(),
                 VideoQueue().Duration());
     nsCOMPtr<nsIRunnable> task = NS_NewRunnableMethod(mReader, &MediaDecoderReader::SetIdle);
     DecodeTaskQueue()->Dispatch(task.forget());
   }
 }
 
 void
-MediaDecoderStateMachine::InitiateSeek(SeekJob& aSeekJob)
+MediaDecoderStateMachine::InitiateSeek(SeekJob aSeekJob)
 {
   MOZ_ASSERT(OnTaskQueue());
 
   mCurrentSeek.RejectIfExists(__func__);
-  mCurrentSeek.Steal(aSeekJob);
+  mCurrentSeek = Move(aSeekJob);
 
   // Bound the seek time to be inside the media range.
   int64_t end = Duration().ToMicroseconds();
   NS_ASSERTION(end != -1, "Should know end time by now");
   int64_t seekTime = mCurrentSeek.mTarget.GetTime().ToMicroseconds();
   seekTime = std::min(seekTime, end);
   seekTime = std::max(int64_t(0), seekTime);
   NS_ASSERTION(seekTime >= 0 && seekTime <= end,
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -523,22 +523,31 @@ protected:
   // Dispatches a LoadedMetadataEvent.
   // This is threadsafe and can be called on any thread.
   // The decoder monitor must be held.
   void EnqueueLoadedMetadataEvent();
 
   void EnqueueFirstFrameLoadedEvent();
 
   struct SeekJob {
-    void Steal(SeekJob& aOther)
+    SeekJob() {}
+
+    SeekJob(SeekJob&& aOther) : mTarget(aOther.mTarget)
+    {
+      aOther.mTarget.Reset();
+      mPromise = Move(aOther.mPromise);
+    }
+
+    SeekJob& operator=(SeekJob&& aOther)
     {
       MOZ_DIAGNOSTIC_ASSERT(!Exists());
       mTarget = aOther.mTarget;
       aOther.mTarget.Reset();
       mPromise = Move(aOther.mPromise);
+      return *this;
     }
 
     bool Exists()
     {
       MOZ_ASSERT(mTarget.IsValid() == !mPromise.IsEmpty());
       return mTarget.IsValid();
     }
 
@@ -562,17 +571,17 @@ protected:
     }
 
     SeekTarget mTarget;
     MozPromiseHolder<MediaDecoder::SeekPromise> mPromise;
   };
 
   // Clears any previous seeking state and initiates a new see on the decoder.
   // The decoder monitor must be held.
-  void InitiateSeek(SeekJob& aSeekJob);
+  void InitiateSeek(SeekJob aSeekJob);
 
   nsresult DispatchAudioDecodeTaskIfNeeded();
 
   // Ensures a task to decode audio has been dispatched to the decode task queue.
   // If a task to decode has already been dispatched, this does nothing,
   // otherwise this dispatches a task to do the decode.
   // This is called on the state machine or decode threads.
   // The decoder monitor must be held.