Bug 825329 - Properly implement AudioStream::GetPlaybackRate. r=kinetik

This commit is contained in:
Paul Adenot 2012-12-28 23:01:38 +01:00
parent 54a3ee7cad
commit ea63943c0e
3 changed files with 38 additions and 8 deletions

View File

@ -1112,7 +1112,6 @@ AudioClock::AudioClock(AudioStream* aStream)
mOutRate(0), mOutRate(0),
mInRate(0), mInRate(0),
mPreservesPitch(true), mPreservesPitch(true),
mPlaybackRate(1.0),
mCompensatingLatency(false) mCompensatingLatency(false)
{} {}
@ -1120,7 +1119,6 @@ void AudioClock::Init()
{ {
mOutRate = mAudioStream->GetRate(); mOutRate = mAudioStream->GetRate();
mInRate = mAudioStream->GetRate(); mInRate = mAudioStream->GetRate();
mPlaybackRate = 1.0;
mOldOutRate = mOutRate; mOldOutRate = mOutRate;
} }
@ -1190,7 +1188,7 @@ void AudioClock::SetPlaybackRate(double aPlaybackRate)
double AudioClock::GetPlaybackRate() double AudioClock::GetPlaybackRate()
{ {
return mPlaybackRate; return static_cast<double>(mOutRate) / mInRate;
} }
void AudioClock::SetPreservesPitch(bool aPreservesPitch) void AudioClock::SetPreservesPitch(bool aPreservesPitch)

View File

@ -77,8 +77,6 @@ class AudioClock
int mInRate; int mInRate;
// True if the we are timestretching, false if we are resampling. // True if the we are timestretching, false if we are resampling.
bool mPreservesPitch; bool mPreservesPitch;
// The current playback rate.
double mPlaybackRate;
// True if we are playing at the old playbackRate after it has been changed. // True if we are playing at the old playbackRate after it has been changed.
bool mCompensatingLatency; bool mCompensatingLatency;
}; };

View File

@ -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."); 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)."); 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) { function test_defaultPlaybackRate(e) {
@ -135,9 +169,9 @@ function ontimeupdate_defaultPlaybackRate(e) {
"The default playback rate shoud be "+SLOW_RATE+"." + t.token); "The default playback rate shoud be "+SLOW_RATE+"." + t.token);
ok(delta_wallclock > delta , "We are effectively slowing down playback. (" + delta_wallclock + ", " + delta + ")"); ok(delta_wallclock > delta , "We are effectively slowing down playback. (" + delta_wallclock + ", " + delta + ")");
if (t.skippedFastPart) { 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 { } 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); finish_test(t);
} }