Bug 466598. Clamp seeking in WAV files. r+sr=roc

This commit is contained in:
Matthew Gregan 2008-12-03 14:38:15 +13:00
parent 2e6127ba6e
commit 90c9d5fd1d
4 changed files with 104 additions and 4 deletions

View File

@ -379,7 +379,10 @@ nsWaveStateMachine::Seek(float aTime)
{
nsAutoMonitor monitor(mMonitor);
mNextState = mState;
mTimeOffset = aTime;
mTimeOffset = NS_MIN(aTime, BytesToTime(mWaveLength));
if (mTimeOffset < 0.0) {
mTimeOffset = 0.0;
}
ChangeState(STATE_SEEKING);
}
@ -570,6 +573,7 @@ nsWaveStateMachine::Run()
}
PRInt64 position = RoundDownToSample(TimeToBytes(mTimeOffset)) + mWavePCMOffset;
NS_ABORT_IF_FALSE(position >= 0 && position <= mWaveLength + mWavePCMOffset, "Invalid seek position");
monitor.Exit();
nsresult rv = mStream->Seek(nsISeekableStream::NS_SEEK_SET, position);
@ -606,7 +610,7 @@ nsWaveStateMachine::Run()
monitor.Exit();
mAudioStream->Drain();
monitor.Enter();
mTimeOffset = mAudioStream->GetTime();
mTimeOffset += mAudioStream->GetTime();
}
// Dispose the audio stream early (before SHUTDOWN) so that
@ -635,7 +639,7 @@ nsWaveStateMachine::Run()
case STATE_SHUTDOWN:
if (mAudioStream) {
mTimeOffset = mAudioStream->GetTime();
mTimeOffset += mAudioStream->GetTime();
}
CloseAudioStream();
return NS_OK;
@ -951,7 +955,7 @@ nsWaveDecoder::GetCurrentTime()
nsresult
nsWaveDecoder::Seek(float aTime)
{
if (mPlaybackStateMachine && aTime >= 0.0) {
if (mPlaybackStateMachine) {
mPlaybackStateMachine->Seek(aTime);
return NS_OK;
}

View File

@ -69,6 +69,8 @@ _TEST_FILES = test_autoplay.html \
test_volume.html \
test_wav_8bit.html \
test_wav_ended1.html \
test_wav_seek_past_end.html \
test_wav_seek_then_play.html \
320x240.ogg \
bug461281.ogg \
seek.ogg \

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Wave Media test: seek after file end</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<audio id='v'
onloadedmetadata='return startTest();'
onended='return playbackEnded();'>
<source type='audio/x-wav' src='r11025_s16_c1.wav'>
</audio>
<pre id="test">
<script class="testbody" type="text/javascript">
// Test if the ended event works correctly.
var v = document.getElementById('v');
var endPassed = false;
var completed = false;
function startTest() {
if (completed)
return false;
v.currentTime = v.duration + 0.5;
v.play();
return false;
}
function playbackEnded() {
if (completed)
return false
completed = true;
ok(v.currentTime >= 0.9 && v.currentTime <= 1.1,
"Checking currentTime at end: " + v.currentTime);
ok(v.ended, "Checking playback has ended");
SimpleTest.finish();
return false;
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Wave Media test: seek then play</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<audio id='v'
onloadedmetadata='return startTest();'
onended='return playbackEnded();'>
<source type='audio/x-wav' src='r11025_s16_c1.wav'>
</audio>
<pre id="test">
<script class="testbody" type="text/javascript">
// Test if the ended event works correctly.
var v = document.getElementById('v');
var endPassed = false;
var completed = false;
function startTest() {
if (completed)
return false;
v.currentTime = v.duration / 2;
v.play();
return false;
}
function playbackEnded() {
if (completed)
return false
completed = true;
ok(v.currentTime >= 0.9 && v.currentTime <= 1.1,
"Checking currentTime at end: " + v.currentTime);
ok(v.ended, "Checking playback has ended");
SimpleTest.finish();
return false;
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>