Bug 1108728 - Remove dormant related state from MediaDecoder. r=cpearce, a=sledru
authorSotaro Ikeda <sikeda@mozilla.com>
Fri, 12 Dec 2014 17:29:24 -0800
changeset 242936 9ad34e90e339
parent 242935 fae52bd681e0
child 242937 d7e079df1b3d
push id4343
push userryanvm@gmail.com
push date2015-01-20 16:38 +0000
treeherdermozilla-beta@c5dfa7d081f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sledru
bugs1108728
milestone36.0
Bug 1108728 - Remove dormant related state from MediaDecoder. r=cpearce, a=sledru
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -120,47 +120,43 @@ NS_IMPL_ISUPPORTS(MediaDecoder, nsIObser
 
 void MediaDecoder::SetDormantIfNecessary(bool aDormant)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
 
   if (!mDecoderStateMachine ||
       !mDecoderStateMachine->IsDormantNeeded() ||
-      mPlayState == PLAY_STATE_SHUTDOWN ||
-      mIsDormant == aDormant) {
+      mPlayState == PLAY_STATE_SHUTDOWN) {
     return;
   }
 
   if(aDormant) {
     // enter dormant state
     DestroyDecodedStream();
     mDecoderStateMachine->SetDormant(true);
 
     int64_t timeUsecs = 0;
     SecondsToUsecs(mCurrentTime, timeUsecs);
     mRequestedSeekTarget = SeekTarget(timeUsecs, SeekTarget::Accurate);
 
     mNextState = mPlayState;
-    mIsDormant = true;
-    mIsExitingDormant = false;
     ChangeState(PLAY_STATE_LOADING);
-  } else if (!aDormant && mPlayState == PLAY_STATE_LOADING) {
+  } else {
     // exit dormant state
     // trigger to state machine.
     mDecoderStateMachine->SetDormant(false);
-    mIsExitingDormant = true;
   }
 }
 
 void MediaDecoder::Pause()
 {
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-  if ((mPlayState == PLAY_STATE_LOADING && mIsDormant) ||
+  if (mPlayState == PLAY_STATE_LOADING ||
       mPlayState == PLAY_STATE_SEEKING ||
       mPlayState == PLAY_STATE_ENDED) {
     mNextState = PLAY_STATE_PAUSED;
     return;
   }
 
   ChangeState(PLAY_STATE_PAUSED);
 }
@@ -423,18 +419,16 @@ MediaDecoder::MediaDecoder() :
   mCurrentTime(0.0),
   mInitialVolume(0.0),
   mInitialPlaybackRate(1.0),
   mInitialPreservesPitch(true),
   mDuration(-1),
   mMediaSeekable(true),
   mSameOriginMedia(false),
   mReentrantMonitor("media.decoder"),
-  mIsDormant(false),
-  mIsExitingDormant(false),
   mPlayState(PLAY_STATE_LOADING),
   mNextState(PLAY_STATE_PAUSED),
   mIgnoreProgressData(false),
   mInfiniteStream(false),
   mOwner(nullptr),
   mPlaybackStatistics(new MediaChannelStatistics()),
   mPinnedForSeek(false),
   mShuttingDown(false),
@@ -591,22 +585,23 @@ nsresult MediaDecoder::Play()
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   NS_ASSERTION(mDecoderStateMachine != nullptr, "Should have state machine.");
   if (mPausedForPlaybackRateNull) {
     return NS_OK;
   }
   nsresult res = ScheduleStateMachineThread();
   NS_ENSURE_SUCCESS(res,res);
-  if ((mPlayState == PLAY_STATE_LOADING && mIsDormant) || mPlayState == PLAY_STATE_SEEKING) {
+  if (mPlayState == PLAY_STATE_LOADING || mPlayState == PLAY_STATE_SEEKING) {
     mNextState = PLAY_STATE_PLAYING;
     return NS_OK;
   }
-  if (mPlayState == PLAY_STATE_ENDED)
+  if (mPlayState == PLAY_STATE_ENDED) {
     return Seek(0, SeekTarget::PrevSyncPoint);
+  }
 
   ChangeState(PLAY_STATE_PLAYING);
   return NS_OK;
 }
 
 nsresult MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -619,17 +614,17 @@ nsresult MediaDecoder::Seek(double aTime
   NS_ENSURE_SUCCESS(rv, rv);
 
   mRequestedSeekTarget = SeekTarget(timeUsecs, aSeekType);
   mCurrentTime = aTime;
 
   // If we are already in the seeking state, then setting mRequestedSeekTarget
   // above will result in the new seek occurring when the current seek
   // completes.
-  if ((mPlayState != PLAY_STATE_LOADING || !mIsDormant) && mPlayState != PLAY_STATE_SEEKING) {
+  if (mPlayState != PLAY_STATE_LOADING && mPlayState != PLAY_STATE_SEEKING) {
     bool paused = false;
     if (mOwner) {
       paused = mOwner->GetPaused();
     }
     mNextState = paused ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING;
     PinForSeek();
     ChangeState(PLAY_STATE_SEEKING);
   }
@@ -695,22 +690,16 @@ void MediaDecoder::MetadataLoaded(nsAuto
   }
 
   DECODER_LOG("MetadataLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d",
               aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
               aInfo->HasAudio(), aInfo->HasVideo());
 
   {
     ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-    if (mPlayState == PLAY_STATE_LOADING && mIsDormant && !mIsExitingDormant) {
-      return;
-    } else if (mPlayState == PLAY_STATE_LOADING && mIsDormant && mIsExitingDormant) {
-      mIsDormant = false;
-      mIsExitingDormant = false;
-    }
     mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1;
     // Duration has changed so we should recompute playback rate
     UpdatePlaybackRate();
   }
 
   if (mDuration == -1) {
     SetInfinite(true);
   }
@@ -736,20 +725,16 @@ void MediaDecoder::FirstFrameLoaded(nsAu
   if (mShuttingDown) {
     return;
   }
 
   DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d",
               aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
               aInfo->HasAudio(), aInfo->HasVideo());
 
-  if (mPlayState == PLAY_STATE_LOADING && mIsDormant && !mIsExitingDormant) {
-    return;
-  }
-
   mInfo = aInfo.forget();
 
   if (mOwner) {
     Invalidate();
     if (!aRestoredFromDromant) {
       mOwner->FirstFrameLoaded();
     }
   }
@@ -826,32 +811,33 @@ bool MediaDecoder::IsSameOriginMedia()
 {
   GetReentrantMonitor().AssertCurrentThreadIn();
   return mSameOriginMedia;
 }
 
 bool MediaDecoder::IsSeeking() const
 {
   MOZ_ASSERT(NS_IsMainThread());
-  return mPlayState == PLAY_STATE_SEEKING;
+  return mPlayState == PLAY_STATE_SEEKING ||
+    (mPlayState == PLAY_STATE_LOADING && mRequestedSeekTarget.IsValid());
 }
 
 bool MediaDecoder::IsEnded() const
 {
   MOZ_ASSERT(NS_IsMainThread());
   return mPlayState == PLAY_STATE_ENDED || mPlayState == PLAY_STATE_SHUTDOWN;
 }
 
 void MediaDecoder::PlaybackEnded()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mShuttingDown ||
       mPlayState == PLAY_STATE_SEEKING ||
-      (mPlayState == PLAY_STATE_LOADING && mIsDormant)) {
+      (mPlayState == PLAY_STATE_LOADING)) {
     return;
   }
 
   {
     ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
 
     for (int32_t i = mOutputStreams.Length() - 1; i >= 0; --i) {
       OutputStreamData& os = mOutputStreams[i];
@@ -1138,18 +1124,17 @@ void MediaDecoder::ChangeState(PlayState
 {
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
 
   if (mNextState == aState) {
     mNextState = PLAY_STATE_PAUSED;
   }
 
-  if ((mPlayState == PLAY_STATE_LOADING && mIsDormant && aState != PLAY_STATE_SHUTDOWN) ||
-       mPlayState == PLAY_STATE_SHUTDOWN) {
+  if (mPlayState == PLAY_STATE_SHUTDOWN) {
     GetReentrantMonitor().NotifyAll();
     return;
   }
 
   if (mDecodedStream) {
     bool blockForPlayState = aState != PLAY_STATE_PLAYING;
     if (mDecodedStream->mHaveBlockedForPlayState != blockForPlayState) {
       mDecodedStream->mStream->ChangeExplicitBlockerCount(blockForPlayState ? 1 : -1);
@@ -1164,21 +1149,16 @@ void MediaDecoder::ChangeState(PlayState
   if (mPlayState == PLAY_STATE_PLAYING) {
     ConstructMediaTracks();
   } else if (mPlayState == PLAY_STATE_ENDED) {
     RemoveMediaTracks();
   }
 
   ApplyStateToStateMachine(mPlayState);
 
-  if (aState!= PLAY_STATE_LOADING) {
-    mIsDormant = false;
-    mIsExitingDormant = false;
-  }
-
   GetReentrantMonitor().NotifyAll();
 }
 
 void MediaDecoder::ApplyStateToStateMachine(PlayState aState)
 {
   MOZ_ASSERT(NS_IsMainThread());
   GetReentrantMonitor().AssertCurrentThreadIn();
 
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -1121,24 +1121,16 @@ protected:
   nsTArray<OutputStreamData> mOutputStreams;
   // The SourceMediaStream we are using to feed the mOutputStreams. This stream
   // is never exposed outside the decoder.
   // Only written on the main thread while holding the monitor. Therefore it
   // can be read on any thread while holding the monitor, or on the main thread
   // without holding the monitor.
   nsAutoPtr<DecodedStreamData> mDecodedStream;
 
-  // True if this decoder is in dormant state.
-  // Should be true only when PlayState is PLAY_STATE_LOADING.
-  bool mIsDormant;
-
-  // True if this decoder is exiting from dormant state.
-  // Should be true only when PlayState is PLAY_STATE_LOADING.
-  bool mIsExitingDormant;
-
   // Set to one of the valid play states.
   // This can only be changed on the main thread while holding the decoder
   // monitor. Thus, it can be safely read while holding the decoder monitor
   // OR on the main thread.
   // Any change to the state on the main thread must call NotifyAll on the
   // monitor so the decode thread can wake up.
   PlayState mPlayState;
 
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1665,17 +1665,17 @@ void MediaDecoderStateMachine::Seek(cons
 
   // MediaDecoder::mPlayState should be SEEKING while we seek, and
   // in that case MediaDecoder shouldn't be calling us.
   NS_ASSERTION(mState != DECODER_STATE_SEEKING,
                "We shouldn't already be seeking");
   NS_ASSERTION(mState > DECODER_STATE_DECODING_METADATA,
                "We should have got duration already");
 
-  if (mState <= DECODER_STATE_DECODING_FIRSTFRAME) {
+  if (mState < DECODER_STATE_DECODING) {
     DECODER_LOG("Seek() Not Enough Data to continue at this stage, queuing seek");
     mQueuedSeekTarget = aTarget;
     return;
   }
   mQueuedSeekTarget.Reset();
 
   StartSeek(aTarget);
 }