Bug 1181913 - fix data race in AudioSink::mWritten. r=kinetik

This commit is contained in:
JW Wang 2015-07-09 22:58:24 +08:00
parent 56a826cd0a
commit ac161fa645
2 changed files with 4 additions and 2 deletions

View File

@ -199,7 +199,8 @@ AudioSink::AudioLoop()
CheckedInt64 sampleTime = UsecsToFrames(AudioQueue().PeekFront()->mTime, mInfo.mRate); CheckedInt64 sampleTime = UsecsToFrames(AudioQueue().PeekFront()->mTime, mInfo.mRate);
// Calculate the number of frames that have been pushed onto the audio hardware. // Calculate the number of frames that have been pushed onto the audio hardware.
CheckedInt64 playedFrames = UsecsToFrames(mStartTime, mInfo.mRate) + mWritten; CheckedInt64 playedFrames = UsecsToFrames(mStartTime, mInfo.mRate) +
static_cast<int64_t>(mWritten);
CheckedInt64 missingFrames = sampleTime - playedFrames; CheckedInt64 missingFrames = sampleTime - playedFrames;
if (!missingFrames.isValid() || !sampleTime.isValid()) { if (!missingFrames.isValid() || !sampleTime.isValid()) {

View File

@ -9,6 +9,7 @@
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
#include "MediaDecoderReader.h" #include "MediaDecoderReader.h"
#include "mozilla/dom/AudioChannelBinding.h" #include "mozilla/dom/AudioChannelBinding.h"
#include "mozilla/Atomics.h"
namespace mozilla { namespace mozilla {
@ -116,7 +117,7 @@ private:
const int64_t mStartTime; const int64_t mStartTime;
// PCM frames written to the stream so far. // PCM frames written to the stream so far.
int64_t mWritten; Atomic<int64_t> mWritten;
// Keep the last good position returned from the audio stream. Used to ensure // Keep the last good position returned from the audio stream. Used to ensure
// position returned by GetPosition() is mono-increasing in spite of audio // position returned by GetPosition() is mono-increasing in spite of audio