Bug 598812 - Fix time attribute of audio available event. r=cpearce a=blocking2.0

This commit is contained in:
async.processingjs@yahoo.com 2010-10-07 11:58:36 +13:00
parent 162b0a1a13
commit 92c10eecf7
8 changed files with 22 additions and 20 deletions

View File

@ -189,7 +189,7 @@ public:
nsresult DispatchAsyncEvent(const nsAString& aName);
nsresult DispatchAudioAvailableEvent(float* aFrameBuffer,
PRUint32 aFrameBufferLength,
PRUint64 aTime);
float aTime);
// Dispatch events that were raised while in the bfcache
nsresult DispatchPendingMediaEvents();
@ -296,7 +296,7 @@ public:
* Called when data has been written to the underlying audio stream.
*/
void NotifyAudioAvailable(float* aFrameBuffer, PRUint32 aFrameBufferLength,
PRUint64 aTime);
float aTime);
/**
* Called in order to check whether some node (this window, its document,

View File

@ -121,8 +121,6 @@ static PRLogModuleInfo* gMediaElementEventsLog;
#include "nsIChannelPolicy.h"
#include "nsChannelPolicy.h"
#define MS_PER_SECOND 1000
using namespace mozilla::layers;
// Under certain conditions there may be no-one holding references to
@ -693,7 +691,7 @@ void nsHTMLMediaElement::NotifyLoadError()
void nsHTMLMediaElement::NotifyAudioAvailable(float* aFrameBuffer,
PRUint32 aFrameBufferLength,
PRUint64 aTime)
float aTime)
{
// Auto manage the memory for the frame buffer, so that if we add an early
// return-on-error here in future, we won't forget to release the memory.
@ -2218,7 +2216,7 @@ ImageContainer* nsHTMLMediaElement::GetImageContainer()
nsresult nsHTMLMediaElement::DispatchAudioAvailableEvent(float* aFrameBuffer,
PRUint32 aFrameBufferLength,
PRUint64 aTime)
float aTime)
{
// Auto manage the memory for the frame buffer. If we fail and return
// an error, this ensures we free the memory in the frame buffer. Otherwise
@ -2238,7 +2236,7 @@ nsresult nsHTMLMediaElement::DispatchAudioAvailableEvent(float* aFrameBuffer,
rv = audioavailableEvent->InitAudioAvailableEvent(NS_LITERAL_STRING("MozAudioAvailable"),
PR_TRUE, PR_TRUE, frameBuffer.forget(), aFrameBufferLength,
(float)aTime / MS_PER_SECOND, mAllowAudioData);
aTime, mAllowAudioData);
NS_ENSURE_SUCCESS(rv, rv);
PRBool dummy;

View File

@ -40,7 +40,7 @@
#include "nsTArray.h"
#include "nsAudioAvailableEventManager.h"
#define MILLISECONDS_PER_SECOND 1000
#define MILLISECONDS_PER_SECOND 1000.0f
#define MAX_PENDING_EVENTS 100
using namespace mozilla;
@ -52,7 +52,7 @@ private:
nsAutoArrayPtr<float> mFrameBuffer;
public:
nsAudioAvailableEventRunner(nsBuiltinDecoder* aDecoder, float* aFrameBuffer,
PRUint32 aFrameBufferLength, PRUint64 aTime) :
PRUint32 aFrameBufferLength, float aTime) :
mDecoder(aDecoder),
mFrameBuffer(aFrameBuffer),
mFrameBufferLength(aFrameBufferLength),
@ -72,7 +72,9 @@ public:
}
const PRUint32 mFrameBufferLength;
const PRUint64 mTime;
// Start time of the buffer data (in seconds).
const float mTime;
};
@ -104,7 +106,7 @@ void nsAudioAvailableEventManager::DispatchPendingEvents(PRUint64 aCurrentTime)
while (mPendingEvents.Length() > 0) {
nsAudioAvailableEventRunner* e =
(nsAudioAvailableEventRunner*)mPendingEvents[0].get();
if (e->mTime > aCurrentTime) {
if (e->mTime * MILLISECONDS_PER_SECOND > aCurrentTime) {
break;
}
nsCOMPtr<nsIRunnable> event = mPendingEvents[0];
@ -137,11 +139,11 @@ void nsAudioAvailableEventManager::QueueWrittenAudioData(float* aAudioData,
// Group audio samples into optimal size for event dispatch, and queue.
while (signalBufferTail <= audioDataLength) {
PRUint64 time = 0;
float time = 0.0;
// Guard against unsigned number overflow during first frame time calculation.
if (aEndTimeSampleOffset > mSignalBufferPosition + audioDataLength) {
time = MILLISECONDS_PER_SECOND * (aEndTimeSampleOffset -
mSignalBufferPosition - audioDataLength) / mSamplesPerSecond;
time = (aEndTimeSampleOffset - mSignalBufferPosition - audioDataLength) /
mSamplesPerSecond;
}
// Fill the signalBuffer.
@ -219,9 +221,11 @@ void nsAudioAvailableEventManager::Drain(PRUint64 aEndTime)
(mSignalBufferLength - mSignalBufferPosition) * sizeof(float));
// Force this last event to go now.
float time = (aEndTime / MILLISECONDS_PER_SECOND) -
(mSignalBufferPosition / mSamplesPerSecond);
nsCOMPtr<nsIRunnable> lastEvent =
new nsAudioAvailableEventRunner(mDecoder, mSignalBuffer.forget(),
mSignalBufferLength, aEndTime);
mSignalBufferLength, time);
NS_DispatchToMainThread(lastEvent, NS_DISPATCH_NORMAL);
mSignalBufferPosition = 0;

View File

@ -82,7 +82,7 @@ private:
nsBuiltinDecoder* mDecoder;
// The number of samples per second.
PRUint64 mSamplesPerSecond;
float mSamplesPerSecond;
// A buffer for audio data to be dispatched in DOM events.
nsAutoArrayPtr<float> mSignalBuffer;

View File

@ -310,7 +310,7 @@ already_AddRefed<nsIPrincipal> nsBuiltinDecoder::GetCurrentPrincipal()
void nsBuiltinDecoder::AudioAvailable(float* aFrameBuffer,
PRUint32 aFrameBufferLength,
PRUint64 aTime)
float aTime)
{
// Auto manage the frame buffer's memory. If we return due to an error
// here, this ensures we free the memory. Otherwise, we pass off ownership

View File

@ -413,7 +413,7 @@ class nsBuiltinDecoder : public nsMediaDecoder
// state machine.
void Stop();
void AudioAvailable(float* aFrameBuffer, PRUint32 aFrameBufferLength, PRUint64 aTime);
void AudioAvailable(float* aFrameBuffer, PRUint32 aFrameBufferLength, float aTime);
// Called by the state machine to notify the decoder that the duration
// has changed.

View File

@ -437,7 +437,7 @@ void nsBuiltinDecoderStateMachine::AudioLoop()
// time.
missingSamples = NS_MIN(static_cast<PRInt64>(PR_UINT32_MAX), missingSamples);
audioDuration += PlaySilence(static_cast<PRUint32>(missingSamples),
channels, sampleTime);
channels, playedSamples);
} else {
audioDuration += PlayFromAudioQueue(sampleTime, channels);
}

View File

@ -178,7 +178,7 @@ function audioAvailable(event) {
spectrumMaxs.push({ value: maxValue, index: maxIndex, time: (currentSampleOffset / testFileSampleRate) });
if( (typeof event.time !== "number") ||
(Math.abs(event.time - currentSampleOffset / testFileSampleRate) > 0.01) ) {
(Math.abs(event.time - currentSampleOffset / testFileSampleRate) >= 0.001) ) {
isTimePropertyValid = false;
}