Bug 1304651 - Remove MediaDecoder::mPausedForPlaybackRateNull. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 22 Sep 2016 17:02:48 +0800
changeset 416852 bfecef8e440beeeccf3968b5f56bed53703c4e67
parent 416784 11e811f1e3efef61debf3cfd5688e72eb541204f
child 416853 261ebf4a551f99cfb17655d5af3414ddfdf3fb44
push id30265
push userjwwang@mozilla.com
push dateFri, 23 Sep 2016 06:07:16 +0000
bugs1304651
milestone52.0a1
Bug 1304651 - Remove MediaDecoder::mPausedForPlaybackRateNull. MozReview-Commit-ID: 7SIKYfDPCxG
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -499,17 +499,16 @@ MediaDecoder::MediaDecoder(MediaDecoderO
 #endif
   , mIgnoreProgressData(false)
   , mInfiniteStream(false)
   , mOwner(aOwner)
   , mFrameStats(new FrameStatistics())
   , mVideoFrameContainer(aOwner->GetVideoFrameContainer())
   , mPlaybackStatistics(new MediaChannelStatistics())
   , mPinnedForSeek(false)
-  , mPausedForPlaybackRateNull(false)
   , mMinimizePreroll(false)
   , mMediaTracksConstructed(false)
   , mFiredMetadataLoaded(false)
   , mElementVisible(!aOwner->IsHidden())
   , mForcedHidden(false)
   , mIsDormant(false)
   , mIsHeuristicDormantSupported(
       Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false))
@@ -775,17 +774,17 @@ MediaDecoder::SetMinimizePrerollUntilPla
 
 nsresult
 MediaDecoder::Play()
 {
   MOZ_ASSERT(NS_IsMainThread());
   UpdateDormantState(false /* aDormantTimeout */, true /* aActivity */);
 
   NS_ASSERTION(mDecoderStateMachine != nullptr, "Should have state machine.");
-  if (mPausedForPlaybackRateNull) {
+  if (mPlaybackRate == 0) {
     return NS_OK;
   }
 
   if (IsEnded()) {
     return Seek(0, SeekTarget::PrevSyncPoint);
   } else if (mPlayState == PLAY_STATE_LOADING) {
     mNextState = PLAY_STATE_PLAYING;
     return NS_OK;
@@ -1503,31 +1502,29 @@ MediaDecoder::SetLoadInBackground(bool a
     mResource->SetLoadInBackground(aLoadInBackground);
   }
 }
 
 void
 MediaDecoder::SetPlaybackRate(double aPlaybackRate)
 {
   MOZ_ASSERT(NS_IsMainThread());
+
+  double oldRate = mPlaybackRate;
   mPlaybackRate = aPlaybackRate;
-  if (mPlaybackRate == 0.0) {
-    mPausedForPlaybackRateNull = true;
+  if (aPlaybackRate == 0) {
     Pause();
     return;
   }
 
-  if (mPausedForPlaybackRateNull) {
-    // Play() uses mPausedForPlaybackRateNull value, so must reset it first
-    mPausedForPlaybackRateNull = false;
-    // If the playbackRate is no longer null, restart the playback, iff the
-    // media was playing.
-    if (!mOwner->GetPaused()) {
-      Play();
-    }
+
+  if (oldRate == 0 && !mOwner->GetPaused()) {
+    // PlaybackRate is no longer null.
+    // Restart the playback if the media was playing.
+    Play();
   }
 
   if (mDecoderStateMachine) {
     mDecoderStateMachine->DispatchSetPlaybackRate(aPlaybackRate);
   }
 }
 
 void
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -675,19 +675,16 @@ protected:
   // this estimate is "decode time" (where the "current time" is the
   // time of the last decoded video frame).
   RefPtr<MediaChannelStatistics> mPlaybackStatistics;
 
   // True when our media stream has been pinned. We pin the stream
   // while seeking.
   bool mPinnedForSeek;
 
-  // True if the playback is paused because the playback rate member is 0.0.
-  bool mPausedForPlaybackRateNull;
-
   // Be assigned from media element during the initialization and pass to
   // AudioStream Class.
   dom::AudioChannel mAudioChannel;
 
   // True if the decoder has been directed to minimize its preroll before
   // playback starts. After the first time playback starts, we don't attempt
   // to minimize preroll, as we assume the user is likely to keep playing,
   // or play the media again.