Bug 638807 - Data race on nsBuiltinDecoder::mFrameBufferLength; r=chris.double

This commit is contained in:
Yury
2011-04-11 17:15:45 -04:00
parent 5e7c83cc16
commit 1dcbc76d14
6 changed files with 69 additions and 20 deletions

View File

@@ -154,23 +154,21 @@ private:
nsCOMPtr<nsBuiltinDecoder> mDecoder;
public:
nsAudioMetadataEventRunner(nsBuiltinDecoder* aDecoder, PRUint32 aChannels,
PRUint32 aRate, PRUint32 aFrameBufferLength) :
PRUint32 aRate) :
mDecoder(aDecoder),
mChannels(aChannels),
mRate(aRate),
mFrameBufferLength(aFrameBufferLength)
mRate(aRate)
{
}
NS_IMETHOD Run()
{
mDecoder->MetadataLoaded(mChannels, mRate, mFrameBufferLength);
mDecoder->MetadataLoaded(mChannels, mRate);
return NS_OK;
}
const PRUint32 mChannels;
const PRUint32 mRate;
const PRUint32 mFrameBufferLength;
};
nsBuiltinDecoderStateMachine::nsBuiltinDecoderStateMachine(nsBuiltinDecoder* aDecoder,
@@ -1031,6 +1029,14 @@ PRInt64 nsBuiltinDecoderStateMachine::GetUndecodedData() const
return 0;
}
void nsBuiltinDecoderStateMachine::SetFrameBufferLength(PRUint32 aLength)
{
NS_ASSERTION(aLength >= 512 && aLength <= 16384,
"The length must be between 512 and 16384");
mDecoder->GetMonitor().AssertCurrentThreadIn();
mEventManager.SetSignalBufferLength(aLength);
}
nsresult nsBuiltinDecoderStateMachine::Run()
{
NS_ASSERTION(IsCurrentThread(mDecoder->mStateMachineThread),
@@ -1088,15 +1094,17 @@ nsresult nsBuiltinDecoderStateMachine::Run()
// setting the default framebuffer size for audioavailable events. Also,
// if there is audio, let the MozAudioAvailable event manager know about
// the metadata.
PRUint32 frameBufferLength = mInfo.mAudioChannels * FRAMEBUFFER_LENGTH_PER_CHANNEL;
nsCOMPtr<nsIRunnable> metadataLoadedEvent =
new nsAudioMetadataEventRunner(mDecoder, mInfo.mAudioChannels,
mInfo.mAudioRate, frameBufferLength);
NS_DispatchToMainThread(metadataLoadedEvent, NS_DISPATCH_NORMAL);
if (HasAudio()) {
mEventManager.Init(mInfo.mAudioChannels, mInfo.mAudioRate);
// Set the buffer length at the decoder level to be able, to be able
// to retrive the value via media element method. The RequestFrameBufferLength
// will call the nsBuiltinDecoderStateMachine::SetFrameBufferLength().
PRUint32 frameBufferLength = mInfo.mAudioChannels * FRAMEBUFFER_LENGTH_PER_CHANNEL;
mDecoder->RequestFrameBufferLength(frameBufferLength);
}
nsCOMPtr<nsIRunnable> metadataLoadedEvent =
new nsAudioMetadataEventRunner(mDecoder, mInfo.mAudioChannels, mInfo.mAudioRate);
NS_DispatchToMainThread(metadataLoadedEvent, NS_DISPATCH_NORMAL);
if (mState == DECODER_STATE_DECODING_METADATA) {
LOG(PR_LOG_DEBUG, ("%p Changed state from DECODING_METADATA to DECODING", mDecoder));