Bug 1241003 - ignore AudioData with 0 frames to avoid silence. r=kinetik. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 21 Jan 2016 21:14:42 +0800
changeset 324277 988c6c356994d5c8231e5fa7b4ce7228107f9d97
parent 324276 c01d0355c486f152fc449e861d590057672cf1eb
child 324278 9a3c2003a5bdaf78b119c0d6c29ddffaed8ef005
push id9871
push userjwwang@mozilla.com
push dateFri, 22 Jan 2016 07:26:27 +0000
reviewerskinetik
bugs1241003
milestone46.0a1
Bug 1241003 - ignore AudioData with 0 frames to avoid silence. r=kinetik.
dom/media/mediasink/DecodedAudioDataSink.cpp
--- a/dom/media/mediasink/DecodedAudioDataSink.cpp
+++ b/dom/media/mediasink/DecodedAudioDataSink.cpp
@@ -197,22 +197,28 @@ DecodedAudioDataSink::PopFrames(uint32_t
     AudioDataValue* GetWritable() const { return mData.get(); }
   private:
     const uint32_t mFrames;
     const uint32_t mChannels;
     const uint32_t mRate;
     UniquePtr<AudioDataValue[]> mData;
   };
 
-  if (!mCurrentData) {
+  while (!mCurrentData) {
     // No data in the queue. Return an empty chunk.
     if (AudioQueue().GetSize() == 0) {
       return MakeUnique<Chunk>();
     }
 
+    // Ignore the element with 0 frames and try next.
+    if (AudioQueue().PeekFront()->mFrames == 0) {
+      RefPtr<MediaData> releaseMe = AudioQueue().PopFront();
+      continue;
+    }
+
     // See if there's a gap in the audio. If there is, push silence into the
     // audio hardware, so we can play across the gap.
     // Calculate the timestamp of the next chunk of audio in numbers of
     // samples.
     CheckedInt64 sampleTime = UsecsToFrames(AudioQueue().PeekFront()->mTime, mInfo.mRate);
     // Calculate the number of frames that have been pushed onto the audio hardware.
     CheckedInt64 playedFrames = UsecsToFrames(mStartTime, mInfo.mRate) +
                                 static_cast<int64_t>(mWritten);
@@ -234,16 +240,17 @@ DecodedAudioDataSink::PopFrames(uint32_t
       mWritten += framesToPop;
       return MakeUnique<SilentChunk>(framesToPop, mInfo.mChannels, mInfo.mRate);
     }
 
     mCurrentData = dont_AddRef(AudioQueue().PopFront().take()->As<AudioData>());
     mCursor = MakeUnique<AudioBufferCursor>(mCurrentData->mAudioData.get(),
                                             mCurrentData->mChannels,
                                             mCurrentData->mFrames);
+    MOZ_ASSERT(mCurrentData->mFrames > 0);
   }
 
   auto framesToPop = std::min(aFrames, mCursor->Available());
 
   SINK_LOG_V("playing audio at time=%lld offset=%u length=%u",
              mCurrentData->mTime, mCurrentData->mFrames - mCursor->Available(), framesToPop);
 
   UniquePtr<AudioStream::Chunk> chunk =