From ea63943c0e0d265cabcb2bdc63321e231c95d45b Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Fri, 28 Dec 2012 23:01:38 +0100 Subject: [PATCH] Bug 825329 - Properly implement AudioStream::GetPlaybackRate. r=kinetik --- content/media/AudioStream.cpp | 4 +-- content/media/AudioStream.h | 2 -- content/media/test/test_playback_rate.html | 40 ++++++++++++++++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/content/media/AudioStream.cpp b/content/media/AudioStream.cpp index 4c3d836fb9a..c0f7409806c 100644 --- a/content/media/AudioStream.cpp +++ b/content/media/AudioStream.cpp @@ -1112,7 +1112,6 @@ AudioClock::AudioClock(AudioStream* aStream) mOutRate(0), mInRate(0), mPreservesPitch(true), - mPlaybackRate(1.0), mCompensatingLatency(false) {} @@ -1120,7 +1119,6 @@ void AudioClock::Init() { mOutRate = mAudioStream->GetRate(); mInRate = mAudioStream->GetRate(); - mPlaybackRate = 1.0; mOldOutRate = mOutRate; } @@ -1190,7 +1188,7 @@ void AudioClock::SetPlaybackRate(double aPlaybackRate) double AudioClock::GetPlaybackRate() { - return mPlaybackRate; + return static_cast(mOutRate) / mInRate; } void AudioClock::SetPreservesPitch(bool aPreservesPitch) diff --git a/content/media/AudioStream.h b/content/media/AudioStream.h index 1ada6e8f738..a70e1d885cb 100644 --- a/content/media/AudioStream.h +++ b/content/media/AudioStream.h @@ -77,8 +77,6 @@ class AudioClock int mInRate; // True if the we are timestretching, false if we are resampling. bool mPreservesPitch; - // The current playback rate. - double mPlaybackRate; // True if we are playing at the old playbackRate after it has been changed. bool mCompensatingLatency; }; diff --git a/content/media/test/test_playback_rate.html b/content/media/test/test_playback_rate.html index da30fb6ad1c..b8d3bc40337 100644 --- a/content/media/test/test_playback_rate.html +++ b/content/media/test/test_playback_rate.html @@ -107,7 +107,41 @@ function onended(e) { ok(!t.muted, "The audio should be muted when playing at high speed, but should not appear as such."); is(t.currentTime, t.duration, "Current time should be equal to the duration (not change by playback rate)."); } - test_defaultPlaybackRate(e); + testResetPlaybackRate(e); +} + +function testResetPlaybackRate(e) { + var t = e.target; + t.addEventListener("timeupdate", ontimeupdate_resetPlabackRate); + t.currentTime = 0.0; + t.play(); + t.timeUpdate = 0; +} + +function ontimeupdate_resetPlabackRate(e) { + var t = e.target; + if (t.currentTime == 0.0) { + return; + } + if (t.timeUpdate == 0) { + t.playbackRate = 0.5; + t.timeUpdate++; + } else if (t.timeUpdate == 1){ + t.playbackRate = 1.0; + t.startTimestamp = Date.now(); + t.oldCurrentTime = t.currentTime; + t.timeUpdate++; + } else { + if (t.currentTime < 3 * t.duration / 4) { + return; + } + var delta = t.currentTime - t.oldCurrentTime, + delta_wallclock = (Date.now() - t.startTimestamp - t.bufferingTime) / 1000; + + ok(checkPlaybackRate(delta_wallclock, delta, 1.0, 0.25), "PlaybackRate reset."); + t.removeEventListener("timeupdate", ontimeupdate_resetPlabackRate); + test_defaultPlaybackRate(e); + } } function test_defaultPlaybackRate(e) { @@ -135,9 +169,9 @@ function ontimeupdate_defaultPlaybackRate(e) { "The default playback rate shoud be "+SLOW_RATE+"." + t.token); ok(delta_wallclock > delta , "We are effectively slowing down playback. (" + delta_wallclock + ", " + delta + ")"); if (t.skippedFastPart) { - is(t.ratechangecount, 7, "We should have received 7 \"ratechange\" events."); + is(t.ratechangecount, 10, "We should have received 10 \"ratechange\" events."); } else { - is(t.ratechangecount, 8, "We should have received 8 \"ratechange\" events."); + is(t.ratechangecount, 11, "We should have received 11 \"ratechange\" events."); } finish_test(t); }