Bug 1055843 - Do not pause when playbackRate = 0. Instead don't play anything. r=padenot
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 01 Sep 2014 14:52:39 +1000
changeset 224503 bdb0a8c2902d21907375f563b78084c8ed9f04d5
parent 224502 e3092e36afb00b285e37e6585e12e24457330925
child 224504 98c97c77ee78daa94d3fc60bdb398174663c2052
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1055843
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1055843 - Do not pause when playbackRate = 0. Instead don't play anything. r=padenot
content/html/content/src/HTMLMediaElement.cpp
content/media/MediaDecoder.cpp
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -3835,19 +3835,19 @@ HTMLMediaElement::SetPlaybackRate(double
   // not supported.
   if (aPlaybackRate < 0) {
     aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
     return;
   }
 
   mPlaybackRate = ClampPlaybackRate(aPlaybackRate);
 
-  if (mPlaybackRate < 0 ||
-      mPlaybackRate > THRESHOLD_HIGH_PLAYBACKRATE_AUDIO ||
-      mPlaybackRate < THRESHOLD_LOW_PLAYBACKRATE_AUDIO) {
+  if (mPlaybackRate != 0.0 &&
+      (mPlaybackRate < 0 || mPlaybackRate > THRESHOLD_HIGH_PLAYBACKRATE_AUDIO ||
+       mPlaybackRate < THRESHOLD_LOW_PLAYBACKRATE_AUDIO)) {
     SetMutedInternal(mMuted | MUTED_BY_INVALID_PLAYBACK_RATE);
   } else {
     SetMutedInternal(mMuted & ~MUTED_BY_INVALID_PLAYBACK_RATE);
   }
 
   if (mDecoder) {
     mDecoder->SetPlaybackRate(mPlaybackRate);
   }
--- a/content/media/MediaDecoder.cpp
+++ b/content/media/MediaDecoder.cpp
@@ -604,16 +604,19 @@ nsresult MediaDecoder::ScheduleStateMach
   return mDecoderStateMachine->ScheduleStateMachine();
 }
 
 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) {
     mNextState = PLAY_STATE_PLAYING;
     return NS_OK;
   }
   if (mPlayState == PLAY_STATE_ENDED)
     return Seek(0, SeekTarget::PrevSyncPoint);
@@ -1432,27 +1435,33 @@ void MediaDecoder::UpdatePlaybackOffset(
 
 bool MediaDecoder::OnStateMachineThread() const
 {
   return mDecoderStateMachine->OnStateMachineThread();
 }
 
 void MediaDecoder::SetPlaybackRate(double aPlaybackRate)
 {
-  if (aPlaybackRate == 0) {
+  if (aPlaybackRate == mInitialPlaybackRate) {
+    return;
+  }
+
+  if (aPlaybackRate == 0.0) {
     mPausedForPlaybackRateNull = true;
+    mInitialPlaybackRate = aPlaybackRate;
     Pause();
     return;
   } else 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 && !mOwner->GetPaused()) {
       Play();
     }
-    mPausedForPlaybackRateNull = false;
   }
 
   if (mDecoderStateMachine) {
     mDecoderStateMachine->SetPlaybackRate(aPlaybackRate);
   } else {
     mInitialPlaybackRate = aPlaybackRate;
   }
 }