Bug 641718 - Round nsWaveReader's buffered ranges times to usecs. r=kinetik

This commit is contained in:
Chris Pearce 2011-04-14 10:12:23 +12:00
parent 73310e4cd6
commit db70e38a67
4 changed files with 11 additions and 2 deletions

View File

@ -231,6 +231,7 @@ _TEST_FILES += \
r16000_u8_c1_list.wav \
wavedata_u8.wav \
wavedata_s16.wav \
audio.wav \
$(NULL)
# Other files

Binary file not shown.

View File

@ -214,6 +214,7 @@ var gErrorTests = [
// These are files that have nontrivial duration and are useful for seeking within.
var gSeekTests = [
{ name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 },
{ name:"audio.wav", type:"audio/x-wav", duration:0.031247 },
{ name:"seek.ogv", type:"video/ogg", duration:3.966 },
{ name:"320x240.ogv", type:"video/ogg", duration:0.233 },
{ name:"seek.webm", type:"video/webm", duration:3.966 },

View File

@ -273,6 +273,10 @@ nsresult nsWaveReader::Seek(PRInt64 aTarget, PRInt64 aStartTime, PRInt64 aEndTim
return mDecoder->GetCurrentStream()->Seek(nsISeekableStream::NS_SEEK_SET, position);
}
static double RoundToUsecs(double aSeconds) {
return floor(aSeconds * USECS_PER_S) / USECS_PER_S;
}
nsresult nsWaveReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime)
{
PRInt64 startOffset = mDecoder->GetCurrentStream()->GetNextCachedData(mWavePCMOffset);
@ -282,8 +286,11 @@ nsresult nsWaveReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime)
NS_ASSERTION(startOffset >= mWavePCMOffset, "Integer underflow in GetBuffered");
NS_ASSERTION(endOffset >= mWavePCMOffset, "Integer underflow in GetBuffered");
aBuffered->Add(BytesToTime(startOffset - mWavePCMOffset),
BytesToTime(endOffset - mWavePCMOffset));
// We need to round the buffered ranges' times to microseconds so that they
// have the same precision as the currentTime and duration attribute on
// the media element.
aBuffered->Add(RoundToUsecs(BytesToTime(startOffset - mWavePCMOffset)),
RoundToUsecs(BytesToTime(endOffset - mWavePCMOffset)));
startOffset = mDecoder->GetCurrentStream()->GetNextCachedData(endOffset);
}
return NS_OK;