--- a/content/media/AudioSink.cpp
+++ b/content/media/AudioSink.cpp
@@ -20,16 +20,19 @@ extern PRLogModuleInfo* gMediaDecoderLog
SINK_LOG(msg, ##__VA_ARGS__); \
} \
PR_END_MACRO
#else
#define SINK_LOG(msg, ...)
#define SINK_LOG_V(msg, ...)
#endif
+// The amount of audio frames that is used to fuzz rounding errors.
+static const int64_t AUDIO_FUZZ_FRAMES = 1;
+
AudioSink::AudioSink(MediaDecoderStateMachine* aStateMachine,
int64_t aStartTime, AudioInfo aInfo, dom::AudioChannel aChannel)
: mStateMachine(aStateMachine)
, mStartTime(aStartTime)
, mWritten(0)
, mInfo(aInfo)
, mChannel(aChannel)
, mVolume(1.0)
@@ -157,17 +160,17 @@ AudioSink::AudioLoop()
CheckedInt64 playedFrames = UsecsToFrames(mStartTime, mInfo.mRate) + mWritten;
CheckedInt64 missingFrames = sampleTime - playedFrames;
if (!missingFrames.isValid() || !sampleTime.isValid()) {
NS_WARNING("Int overflow adding in AudioLoop");
break;
}
- if (missingFrames.value() > 0) {
+ if (missingFrames.value() > AUDIO_FUZZ_FRAMES) {
// The next audio chunk begins some time after the end of the last chunk
// we pushed to the audio hardware. We must push silence into the audio
// hardware so that the next audio chunk begins playback at the correct
// time.
missingFrames = std::min<int64_t>(UINT32_MAX, missingFrames.value());
mWritten += PlaySilence(static_cast<uint32_t>(missingFrames.value()));
} else {
mWritten += PlayFromAudioQueue();