Bug 1052206 - Add Fuzz r=kinetik
authorSotaro Ikeda <sikeda@mozilla.com>
Mon, 22 Sep 2014 13:26:36 -0700
changeset 206590 2d6ffa903e38c1ca0088ce41e78c10c38f38ea11
parent 206589 499a2a39ac53d286cd61798defa0e99d82c007e4
child 206591 790f41c631ccb2f8b87d6193e116007efeaf2a2e
child 206592 0c8fa599e8895dde0bc07f00aa0ab5b44e791e35
push idunknown
push userunknown
push dateunknown
reviewerskinetik
bugs1052206
milestone35.0a1
Bug 1052206 - Add Fuzz r=kinetik
content/media/AudioSink.cpp
--- 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();