Bug 1273390. Part 4 - remove use of FlushableTaskQueue::Flush(). r=jya. draft 1273390_WaveDataDecoder_Flush
authorJW Wang <jwwang@mozilla.com>
Tue, 17 May 2016 14:56:05 +0800
branch1273390_WaveDataDecoder_Flush
changeset 367672 2eb123d9be20a525953a7049c2758f413e88775f
parent 367671 a289e8c41dbb6f28705a6cfc0f5661ed80819e51
child 367673 7e582ef4b481e099d0d94250c9fb0dec019cf30b
push id18315
push userjwwang@mozilla.com
push dateTue, 17 May 2016 06:58:32 +0000
reviewersjya
bugs1273390
milestone49.0a1
Bug 1273390. Part 4 - remove use of FlushableTaskQueue::Flush(). r=jya. MozReview-Commit-ID: HTIZQ5XoprF
dom/media/platforms/agnostic/WAVDecoder.cpp
dom/media/platforms/agnostic/WAVDecoder.h
--- a/dom/media/platforms/agnostic/WAVDecoder.cpp
+++ b/dom/media/platforms/agnostic/WAVDecoder.cpp
@@ -2,16 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WAVDecoder.h"
 #include "AudioSampleFormat.h"
 #include "nsAutoPtr.h"
+#include "mozilla/SyncRunnable.h"
 
 using mp4_demuxer::ByteReader;
 
 namespace mozilla {
 
 int16_t
 DecodeALawSample(uint8_t aValue)
 {
@@ -46,16 +47,17 @@ DecodeULawSample(uint8_t aValue)
 }
 
 WaveDataDecoder::WaveDataDecoder(const AudioInfo& aConfig,
                                  FlushableTaskQueue* aTaskQueue,
                                  MediaDataDecoderCallback* aCallback)
   : mInfo(aConfig)
   , mTaskQueue(aTaskQueue)
   , mCallback(aCallback)
+  , mIsFlushing(false)
   , mFrames(0)
 {
 }
 
 nsresult
 WaveDataDecoder::Shutdown()
 {
   return NS_OK;
@@ -76,16 +78,19 @@ WaveDataDecoder::Input(MediaRawData* aSa
 
   return NS_OK;
 }
 
 void
 WaveDataDecoder::ProcessDecode(MediaRawData* aSample)
 {
   MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  if (mIsFlushing) {
+    return;
+  }
   if (!DoDecode(aSample)) {
     mCallback->Error();
   } else if (mTaskQueue->IsEmpty()) {
     mCallback->InputExhausted();
   }
 }
 
 bool
@@ -164,18 +169,22 @@ WaveDataDecoder::Drain()
   mTaskQueue->Dispatch(NewRunnableMethod(this, &WaveDataDecoder::ProcessDrain));
   return NS_OK;
 }
 
 nsresult
 WaveDataDecoder::Flush()
 {
   MOZ_ASSERT(mCallback->OnReaderTaskQueue());
-  mTaskQueue->Flush();
-  mFrames = 0;
+  mIsFlushing = true;
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([this] () {
+    mFrames = 0;
+  });
+  SyncRunnable::DispatchToThread(mTaskQueue, r);
+  mIsFlushing = false;
   return NS_OK;
 }
 
 /* static */
 bool
 WaveDataDecoder::IsWave(const nsACString& aMimeType)
 {
   // Some WebAudio uses "audio/x-wav",
--- a/dom/media/platforms/agnostic/WAVDecoder.h
+++ b/dom/media/platforms/agnostic/WAVDecoder.h
@@ -35,14 +35,15 @@ private:
 
   void ProcessDecode(MediaRawData* aSample);
   bool DoDecode(MediaRawData* aSample);
   void ProcessDrain();
 
   const AudioInfo& mInfo;
   RefPtr<FlushableTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
+  Atomic<bool> mIsFlushing;
 
   int64_t mFrames;
 };
 
 } // namespace mozilla
 #endif