Bug 1274189. Part 2 - remove use of FlushableTaskQueue::Flush(). r=jya.
MozReview-Commit-ID: I079lp6vSqu
--- a/dom/media/platforms/agnostic/OpusDecoder.cpp
+++ b/dom/media/platforms/agnostic/OpusDecoder.cpp
@@ -5,16 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OpusDecoder.h"
#include "TimeUnits.h"
#include "VorbisUtils.h"
#include "VorbisDecoder.h" // For VorbisLayout
#include "mozilla/Endian.h"
#include "mozilla/PodOperations.h"
+#include "mozilla/SyncRunnable.h"
#include <stdint.h>
#include <inttypes.h> // For PRId64
extern mozilla::LogModule* GetPDMLog();
#define OPUS_DEBUG(arg, ...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, \
("OpusDataDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
@@ -26,16 +27,17 @@ OpusDataDecoder::OpusDataDecoder(const A
: mInfo(aConfig)
, mTaskQueue(aTaskQueue)
, mCallback(aCallback)
, mOpusDecoder(nullptr)
, mSkip(0)
, mDecodedHeader(false)
, mPaddingDiscarded(false)
, mFrames(0)
+ , mIsFlushing(false)
{
}
OpusDataDecoder::~OpusDataDecoder()
{
if (mOpusDecoder) {
opus_multistream_decoder_destroy(mOpusDecoder);
mOpusDecoder = nullptr;
@@ -136,16 +138,19 @@ OpusDataDecoder::Input(MediaRawData* aSa
this, &OpusDataDecoder::ProcessDecode, aSample));
return NS_OK;
}
void
OpusDataDecoder::ProcessDecode(MediaRawData* aSample)
{
+ if (mIsFlushing) {
+ return;
+ }
if (DoDecode(aSample) == -1) {
mCallback->Error();
} else if(mTaskQueue->IsEmpty()) {
mCallback->InputExhausted();
}
}
int
@@ -308,24 +313,30 @@ OpusDataDecoder::Drain()
{
mTaskQueue->Dispatch(NewRunnableMethod(this, &OpusDataDecoder::ProcessDrain));
return NS_OK;
}
nsresult
OpusDataDecoder::Flush()
{
- mTaskQueue->Flush();
- if (mOpusDecoder) {
+ if (!mOpusDecoder) {
+ return NS_OK;
+ }
+ mIsFlushing = true;
+ nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([this] () {
+ MOZ_ASSERT(mOpusDecoder);
// Reset the decoder.
opus_multistream_decoder_ctl(mOpusDecoder, OPUS_RESET_STATE);
mSkip = mOpusParser->mPreSkip;
mPaddingDiscarded = false;
mLastFrameTime.reset();
- }
+ });
+ SyncRunnable::DispatchToThread(mTaskQueue, runnable);
+ mIsFlushing = false;
return NS_OK;
}
/* static */
bool
OpusDataDecoder::IsOpus(const nsACString& aMimeType)
{
return aMimeType.EqualsLiteral("audio/webm; codecs=opus") ||
--- a/dom/media/platforms/agnostic/OpusDecoder.h
+++ b/dom/media/platforms/agnostic/OpusDecoder.h
@@ -55,12 +55,14 @@ private:
// Opus padding should only be discarded on the final packet. Once this
// is set to true, if the reader attempts to decode any further packets it
// will raise an error so we can indicate that the file is invalid.
bool mPaddingDiscarded;
int64_t mFrames;
Maybe<int64_t> mLastFrameTime;
uint8_t mMappingTable[MAX_AUDIO_CHANNELS]; // Channel mapping table.
+
+ Atomic<bool> mIsFlushing;
};
} // namespace mozilla
#endif