Bug 1286441: do not use TaskQueue->IsEmpty() to check input task is exist or not. r?jya draft
authorAlfredo Yang <ayang@mozilla.com>
Tue, 12 Jul 2016 18:25:11 +0800
changeset 386956 bcff1cd20943ecb50c0c176fd0db4e1c974f8910
parent 386010 679118259e91f40d4a8f968f03ec4cff066cdb5b
child 525259 378e966c8550ce2f0b4f626bf7839dd9c30dfdc8
push id22863
push userayang@mozilla.com
push dateWed, 13 Jul 2016 04:16:10 +0000
reviewersjya
bugs1286441
milestone50.0a1
Bug 1286441: do not use TaskQueue->IsEmpty() to check input task is exist or not. r?jya MozReview-Commit-ID: IHG1u5nxZw5
dom/media/platforms/wmf/WMFMediaDataDecoder.cpp
dom/media/platforms/wmf/WMFMediaDataDecoder.h
--- a/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp
+++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp
@@ -18,16 +18,17 @@
 namespace mozilla {
 
 WMFMediaDataDecoder::WMFMediaDataDecoder(MFTManager* aMFTManager,
                                          TaskQueue* aTaskQueue,
                                          MediaDataDecoderCallback* aCallback)
   : mTaskQueue(aTaskQueue)
   , mCallback(aCallback)
   , mMFTManager(aMFTManager)
+  , mNumOfInputTasks(0)
   , mIsFlushing(false)
   , mIsShutDown(false)
 {
 }
 
 WMFMediaDataDecoder::~WMFMediaDataDecoder()
 {
 }
@@ -99,22 +100,26 @@ WMFMediaDataDecoder::ProcessShutdown()
 }
 
 // Inserts data into the decoder's pipeline.
 nsresult
 WMFMediaDataDecoder::Input(MediaRawData* aSample)
 {
   MOZ_ASSERT(mCallback->OnReaderTaskQueue());
   MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown);
+  mNumOfInputTasks++;
 
+  RefPtr<WMFMediaDataDecoder> self = this;
+  RefPtr<MediaRawData> sample = aSample;
   nsCOMPtr<nsIRunnable> runnable =
-    NewRunnableMethod<RefPtr<MediaRawData>>(
-      this,
-      &WMFMediaDataDecoder::ProcessDecode,
-      RefPtr<MediaRawData>(aSample));
+    NS_NewRunnableFunction([self, sample]() {
+      self->mNumOfInputTasks--;
+      self->ProcessDecode(sample);
+  });
+
   mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 void
 WMFMediaDataDecoder::ProcessDecode(MediaRawData* aSample)
 {
   if (mIsFlushing) {
@@ -144,17 +149,17 @@ WMFMediaDataDecoder::ProcessOutput()
   RefPtr<MediaData> output;
   HRESULT hr = S_OK;
   while (SUCCEEDED(hr = mMFTManager->Output(mLastStreamOffset, output)) &&
          output) {
     mHasSuccessfulOutput = true;
     mCallback->Output(output);
   }
   if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
-    if (mTaskQueue->IsEmpty()) {
+    if (mNumOfInputTasks <= 0) {
       mCallback->InputExhausted();
     }
   } else if (FAILED(hr)) {
     NS_WARNING("WMFMediaDataDecoder failed to output data");
     mCallback->Error(MediaDataDecoderError::DECODE_ERROR);
     if (!mRecordedError) {
       SendTelemetry(hr);
       mRecordedError = true;
--- a/dom/media/platforms/wmf/WMFMediaDataDecoder.h
+++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.h
@@ -132,16 +132,18 @@ private:
   MediaDataDecoderCallback* mCallback;
 
   nsAutoPtr<MFTManager> mMFTManager;
 
   // The last offset into the media resource that was passed into Input().
   // This is used to approximate the decoder's position in the media resource.
   int64_t mLastStreamOffset;
 
+  Atomic<int32_t> mNumOfInputTasks;
+
   // Set on reader/decode thread calling Flush() to indicate that output is
   // not required and so input samples on mTaskQueue need not be processed.
   // Cleared on mTaskQueue.
   Atomic<bool> mIsFlushing;
 
   bool mIsShutDown;
 
   // For telemetry