From e6cf21241e66c935d80d15ae46e7c9a32d08ec86 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Sun, 19 Apr 2015 22:42:22 -0700 Subject: [PATCH] Backed out changeset 01abd1d12b2c (bug 1155432) for Windows build bustage CLOSED TREE --- dom/media/fmp4/wmf/WMFMediaDataDecoder.cpp | 114 ++++++--------------- dom/media/fmp4/wmf/WMFMediaDataDecoder.h | 11 +- 2 files changed, 34 insertions(+), 91 deletions(-) diff --git a/dom/media/fmp4/wmf/WMFMediaDataDecoder.cpp b/dom/media/fmp4/wmf/WMFMediaDataDecoder.cpp index 905018901a5e..835b0cfa2466 100644 --- a/dom/media/fmp4/wmf/WMFMediaDataDecoder.cpp +++ b/dom/media/fmp4/wmf/WMFMediaDataDecoder.cpp @@ -27,14 +27,13 @@ WMFMediaDataDecoder::WMFMediaDataDecoder(MFTManager* aMFTManager, : mTaskQueue(aTaskQueue) , mCallback(aCallback) , mMFTManager(aMFTManager) - , mMonitor("WMFMediaDataDecoder") - , mIsDecodeTaskDispatched(false) - , mIsFlushing(false) { + MOZ_COUNT_CTOR(WMFMediaDataDecoder); } WMFMediaDataDecoder::~WMFMediaDataDecoder() { + MOZ_COUNT_DTOR(WMFMediaDataDecoder); } nsresult @@ -49,17 +48,12 @@ WMFMediaDataDecoder::Init() nsresult WMFMediaDataDecoder::Shutdown() { - nsresult rv = mTaskQueue->Dispatch( + DebugOnly rv = mTaskQueue->FlushAndDispatch( NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessShutdown)); #ifdef DEBUG if (NS_FAILED(rv)) { NS_WARNING("WMFMediaDataDecoder::Shutdown() dispatch of task failed!"); } - { - MonitorAutoLock mon(mMonitor); - // The MP4Reader should have flushed before calling Shutdown(). - MOZ_ASSERT(!mIsDecodeTaskDispatched); - } #endif return NS_OK; } @@ -67,73 +61,36 @@ WMFMediaDataDecoder::Shutdown() void WMFMediaDataDecoder::ProcessShutdown() { - if (mMFTManager) { - mMFTManager->Shutdown(); - mMFTManager = nullptr; - } + mMFTManager->Shutdown(); + mMFTManager = nullptr; mDecoder = nullptr; } -void -WMFMediaDataDecoder::EnsureDecodeTaskDispatched() -{ - mMonitor.AssertCurrentThreadOwns(); - if (!mIsDecodeTaskDispatched) { - mTaskQueue->Dispatch( - NS_NewRunnableMethod(this, - &WMFMediaDataDecoder::Decode)); - mIsDecodeTaskDispatched = true; - } -} - // Inserts data into the decoder's pipeline. nsresult WMFMediaDataDecoder::Input(MediaRawData* aSample) { - MonitorAutoLock mon(mMonitor); - mInput.push(aSample); - EnsureDecodeTaskDispatched(); + mTaskQueue->Dispatch( + NS_NewRunnableMethodWithArg>( + this, + &WMFMediaDataDecoder::ProcessDecode, + nsRefPtr(aSample))); return NS_OK; } void -WMFMediaDataDecoder::Decode() +WMFMediaDataDecoder::ProcessDecode(MediaRawData* aSample) { - while (true) { - nsRefPtr input; - { - MonitorAutoLock mon(mMonitor); - MOZ_ASSERT(mIsDecodeTaskDispatched); - if (mInput.empty()) { - if (mIsFlushing) { - if (mDecoder) { - mDecoder->Flush(); - } - mIsFlushing = false; - } - mIsDecodeTaskDispatched = false; - mon.NotifyAll(); - return; - } - input = mInput.front(); - mInput.pop(); - } - - HRESULT hr = mMFTManager->Input(input); - if (FAILED(hr)) { - NS_WARNING("MFTManager rejected sample"); - { - MonitorAutoLock mon(mMonitor); - PurgeInputQueue(); - } - mCallback->Error(); - return; - } - - mLastStreamOffset = input->mOffset; - - ProcessOutput(); + HRESULT hr = mMFTManager->Input(aSample); + if (FAILED(hr)) { + NS_WARNING("MFTManager rejected sample"); + mCallback->Error(); + return; } + + mLastStreamOffset = aSample->mOffset; + + ProcessOutput(); } void @@ -151,33 +108,24 @@ WMFMediaDataDecoder::ProcessOutput() } } else if (FAILED(hr)) { NS_WARNING("WMFMediaDataDecoder failed to output data"); - { - MonitorAutoLock mon(mMonitor); - PurgeInputQueue(); - } mCallback->Error(); } } -void -WMFMediaDataDecoder::PurgeInputQueue() -{ - mMonitor.AssertCurrentThreadOwns(); - while (!mInput.empty()) { - mInput.pop(); - } -} - nsresult WMFMediaDataDecoder::Flush() { - MonitorAutoLock mon(mMonitor); - PurgeInputQueue(); - mIsFlushing = true; - EnsureDecodeTaskDispatched(); - while (mIsDecodeTaskDispatched || mIsFlushing) { - mon.Wait(); - } + // Flush the input task queue. This cancels all pending Decode() calls. + // Note this blocks until the task queue finishes its current job, if + // it's executing at all. Note the MP4Reader ignores all output while + // flushing. + mTaskQueue->Flush(); + + // Order the MFT to flush; drop all internal data. + NS_ENSURE_TRUE(mDecoder, NS_ERROR_FAILURE); + HRESULT hr = mDecoder->Flush(); + NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); + return NS_OK; } diff --git a/dom/media/fmp4/wmf/WMFMediaDataDecoder.h b/dom/media/fmp4/wmf/WMFMediaDataDecoder.h index dbd6090ee8db..42c61738a22a 100644 --- a/dom/media/fmp4/wmf/WMFMediaDataDecoder.h +++ b/dom/media/fmp4/wmf/WMFMediaDataDecoder.h @@ -74,9 +74,9 @@ public: private: - void Decode(); - void EnsureDecodeTaskDispatched(); - void PurgeInputQueue(); + // Called on the task queue. Inserts the sample into the decoder, and + // extracts output if available. + void ProcessDecode(MediaRawData* aSample); // Called on the task queue. Extracts output if available, and delivers // it to the reader. Called after ProcessDecode() and ProcessDrain(). @@ -97,11 +97,6 @@ private: // 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; - - Monitor mMonitor; - std::queue> mInput; - bool mIsDecodeTaskDispatched; - bool mIsFlushing; }; } // namespace mozilla