mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 12:45:27 +00:00
Bug 1270350 - per comment 0, use SyncRunnable to repalce the boilerplate code. r=jya.
MozReview-Commit-ID: 9hqmUnNC3Vm
This commit is contained in:
parent
b852e0988e
commit
facd846fd6
@ -15,6 +15,7 @@
|
||||
#include "MP4Decoder.h"
|
||||
#include "MediaData.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/SyncRunnable.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Logging.h"
|
||||
@ -149,11 +150,8 @@ AppleVDADecoder::Flush()
|
||||
mTaskQueue->Flush();
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
NewRunnableMethod(this, &AppleVDADecoder::ProcessFlush);
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mTaskQueue->Dispatch(runnable.forget());
|
||||
while (mIsFlushing) {
|
||||
mon.Wait();
|
||||
}
|
||||
SyncRunnable::DispatchToThread(mTaskQueue, runnable);
|
||||
mIsFlushing = false;
|
||||
mInputIncoming = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
@ -179,9 +177,6 @@ AppleVDADecoder::ProcessFlush()
|
||||
"with error:%d.", rv);
|
||||
}
|
||||
ClearReorderedFrames();
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mIsFlushing = false;
|
||||
mon.NotifyAll();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -125,7 +125,6 @@ protected:
|
||||
// This is used to calculate how many frames has been buffered by the decoder.
|
||||
Atomic<uint32_t> mQueuedSamples;
|
||||
|
||||
// For wait on mIsFlushing during Shutdown() process.
|
||||
// Protects mReorderQueue.
|
||||
Monitor mMonitor;
|
||||
// Set on reader/decode thread calling Flush() to indicate that output is
|
||||
|
@ -123,9 +123,6 @@ AppleVTDecoder::ProcessFlush()
|
||||
"with error:%d.", rv);
|
||||
}
|
||||
ClearReorderedFrames();
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mIsFlushing = false;
|
||||
mon.NotifyAll();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4,6 +4,7 @@
|
||||
* 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 "mozilla/SyncRunnable.h"
|
||||
#include "mozilla/TaskQueue.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -31,8 +32,6 @@ StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
|
||||
, mFrame(NULL)
|
||||
, mExtraData(nullptr)
|
||||
, mCodecID(aCodecID)
|
||||
, mMonitor("FFMpegaDataDecoder")
|
||||
, mIsFlushing(false)
|
||||
{
|
||||
MOZ_ASSERT(aLib);
|
||||
MOZ_COUNT_CTOR(FFmpegDataDecoder);
|
||||
@ -116,15 +115,10 @@ nsresult
|
||||
FFmpegDataDecoder<LIBAV_VER>::Flush()
|
||||
{
|
||||
MOZ_ASSERT(mCallback->OnReaderTaskQueue());
|
||||
mIsFlushing = true;
|
||||
mTaskQueue->Flush();
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
NewRunnableMethod(this, &FFmpegDataDecoder<LIBAV_VER>::ProcessFlush);
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mTaskQueue->Dispatch(runnable.forget());
|
||||
while (mIsFlushing) {
|
||||
mon.Wait();
|
||||
}
|
||||
SyncRunnable::DispatchToThread(mTaskQueue, runnable);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -145,9 +139,6 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessFlush()
|
||||
if (mCodecContext) {
|
||||
mLib->avcodec_flush_buffers(mCodecContext);
|
||||
}
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mIsFlushing = false;
|
||||
mon.NotifyAll();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -57,14 +57,6 @@ protected:
|
||||
RefPtr<MediaByteBuffer> mExtraData;
|
||||
AVCodecID mCodecID;
|
||||
|
||||
// For wait on mIsFlushing during Shutdown() process.
|
||||
// Protects mReorderQueue.
|
||||
Monitor mMonitor;
|
||||
// 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 in ProcessDrain().
|
||||
Atomic<bool> mIsFlushing;
|
||||
|
||||
private:
|
||||
static StaticMutex sMonitor;
|
||||
};
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/SyncRunnable.h"
|
||||
|
||||
extern mozilla::LogModule* GetPDMLog();
|
||||
#define LOG(...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
@ -23,7 +24,6 @@ WMFMediaDataDecoder::WMFMediaDataDecoder(MFTManager* aMFTManager,
|
||||
: mTaskQueue(aTaskQueue)
|
||||
, mCallback(aCallback)
|
||||
, mMFTManager(aMFTManager)
|
||||
, mMonitor("WMFMediaDataDecoder")
|
||||
, mIsFlushing(false)
|
||||
, mIsShutDown(false)
|
||||
{
|
||||
@ -118,12 +118,9 @@ WMFMediaDataDecoder::Input(MediaRawData* aSample)
|
||||
void
|
||||
WMFMediaDataDecoder::ProcessDecode(MediaRawData* aSample)
|
||||
{
|
||||
{
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
if (mIsFlushing) {
|
||||
// Skip sample, to be released by runnable.
|
||||
return;
|
||||
}
|
||||
if (mIsFlushing) {
|
||||
// Skip sample, to be released by runnable.
|
||||
return;
|
||||
}
|
||||
|
||||
HRESULT hr = mMFTManager->Input(aSample);
|
||||
@ -172,9 +169,6 @@ WMFMediaDataDecoder::ProcessFlush()
|
||||
if (mMFTManager) {
|
||||
mMFTManager->Flush();
|
||||
}
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mIsFlushing = false;
|
||||
mon.NotifyAll();
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -183,24 +177,18 @@ WMFMediaDataDecoder::Flush()
|
||||
MOZ_ASSERT(mCallback->OnReaderTaskQueue());
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown);
|
||||
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mIsFlushing = true;
|
||||
mTaskQueue->Dispatch(NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessFlush));
|
||||
while (mIsFlushing) {
|
||||
mon.Wait();
|
||||
}
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessFlush);
|
||||
SyncRunnable::DispatchToThread(mTaskQueue, runnable);
|
||||
mIsFlushing = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
WMFMediaDataDecoder::ProcessDrain()
|
||||
{
|
||||
bool isFlushing;
|
||||
{
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
isFlushing = mIsFlushing;
|
||||
}
|
||||
if (!isFlushing && mMFTManager) {
|
||||
if (!mIsFlushing && mMFTManager) {
|
||||
// Order the decoder to drain...
|
||||
mMFTManager->Drain();
|
||||
// Then extract all available output.
|
||||
|
@ -125,12 +125,10 @@ private:
|
||||
// This is used to approximate the decoder's position in the media resource.
|
||||
int64_t mLastStreamOffset;
|
||||
|
||||
// For access to and waiting on mIsFlushing
|
||||
Monitor mMonitor;
|
||||
// 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.
|
||||
bool mIsFlushing;
|
||||
Atomic<bool> mIsFlushing;
|
||||
|
||||
bool mIsShutDown;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user