Bug 1273397. Part 3 - remove use of FlushableTaskQueue::Flush(). r=jya. draft 1273405_VorbisDataDecoder_Flush
authorJW Wang <jwwang@mozilla.com>
Tue, 17 May 2016 15:24:39 +0800
branch1273405_VorbisDataDecoder_Flush
changeset 370012 47b40fa986d86ce8e18197b9fe53ad62c1016008
parent 370011 b5f185ab7e2ebd5b9ecb784306fa1be6ff7fcbdc
child 370013 8e75fa48f27e31fde3bab85794da064565209a06
push id18977
push userjwwang@mozilla.com
push dateTue, 24 May 2016 03:49:46 +0000
reviewersjya
bugs1273397
milestone49.0a1
Bug 1273397. Part 3 - remove use of FlushableTaskQueue::Flush(). r=jya. MozReview-Commit-ID: 9xptFPNMY73
dom/media/platforms/agnostic/VPXDecoder.cpp
dom/media/platforms/agnostic/VPXDecoder.h
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -4,16 +4,17 @@
  * 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 "VPXDecoder.h"
 #include "gfx2DGlue.h"
 #include "nsError.h"
 #include "TimeUnits.h"
 #include "mozilla/PodOperations.h"
+#include "mozilla/SyncRunnable.h"
 #include "prsystem.h"
 
 #include <algorithm>
 
 #undef LOG
 extern mozilla::LogModule* GetPDMLog();
 #define LOG(arg, ...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, ("VPXDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
 
@@ -34,16 +35,17 @@ static int MimeTypeToCodec(const nsACStr
 
 VPXDecoder::VPXDecoder(const VideoInfo& aConfig,
                        ImageContainer* aImageContainer,
                        FlushableTaskQueue* aTaskQueue,
                        MediaDataDecoderCallback* aCallback)
   : mImageContainer(aImageContainer)
   , mTaskQueue(aTaskQueue)
   , mCallback(aCallback)
+  , mIsFlushing(false)
   , mInfo(aConfig)
   , mCodec(MimeTypeToCodec(aConfig.mMimeType))
 {
   MOZ_COUNT_CTOR(VPXDecoder);
   PodZero(&mVPX);
 }
 
 VPXDecoder::~VPXDecoder()
@@ -84,17 +86,22 @@ VPXDecoder::Init()
     return InitPromise::CreateAndReject(DecoderFailureReason::INIT_ERROR, __func__);
   }
   return InitPromise::CreateAndResolve(TrackInfo::kVideoTrack, __func__);
 }
 
 nsresult
 VPXDecoder::Flush()
 {
-  mTaskQueue->Flush();
+  mIsFlushing = true;
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([this] () {
+    // nothing to do for now.
+  });
+  SyncRunnable::DispatchToThread(mTaskQueue, r);
+  mIsFlushing = false;
   return NS_OK;
 }
 
 int
 VPXDecoder::DoDecode(MediaRawData* aSample)
 {
 #if defined(DEBUG)
   vpx_codec_stream_info_t si;
@@ -175,16 +182,19 @@ VPXDecoder::DoDecode(MediaRawData* aSamp
     mCallback->Output(v);
   }
   return 0;
 }
 
 void
 VPXDecoder::ProcessDecode(MediaRawData* aSample)
 {
+  if (mIsFlushing) {
+    return;
+  }
   if (DoDecode(aSample) == -1) {
     mCallback->Error();
   } else if (mTaskQueue->IsEmpty()) {
     mCallback->InputExhausted();
   }
 }
 
 nsresult
--- a/dom/media/platforms/agnostic/VPXDecoder.h
+++ b/dom/media/platforms/agnostic/VPXDecoder.h
@@ -49,16 +49,17 @@ public:
 private:
   void ProcessDecode(MediaRawData* aSample);
   int DoDecode(MediaRawData* aSample);
   void ProcessDrain();
 
   const RefPtr<ImageContainer> mImageContainer;
   const RefPtr<FlushableTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
+  Atomic<bool> mIsFlushing;
 
   // VPx decoder state
   vpx_codec_ctx_t mVPX;
 
   const VideoInfo& mInfo;
 
   const int mCodec;
 };