Bug 1286441: do not use TaskQueue->IsEmpty() to check input task is exist or not. r?jya
MozReview-Commit-ID: IHG1u5nxZw5
--- 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