Bug 1273405. Part 2 - remove use of FlushableTaskQueue::Flush(). r=jya.
MozReview-Commit-ID: bchmGXw1fw
--- a/dom/media/platforms/agnostic/VorbisDecoder.cpp
+++ b/dom/media/platforms/agnostic/VorbisDecoder.cpp
@@ -4,16 +4,17 @@
* 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 "VorbisDecoder.h"
#include "VorbisUtils.h"
#include "XiphExtradata.h"
#include "mozilla/PodOperations.h"
+#include "mozilla/SyncRunnable.h"
#include "nsAutoPtr.h"
#undef LOG
extern mozilla::LogModule* GetPDMLog();
#define LOG(type, msg) MOZ_LOG(GetPDMLog(), type, msg)
namespace mozilla {
@@ -34,16 +35,17 @@ ogg_packet InitVorbisPacket(const unsign
VorbisDataDecoder::VorbisDataDecoder(const AudioInfo& aConfig,
FlushableTaskQueue* aTaskQueue,
MediaDataDecoderCallback* aCallback)
: mInfo(aConfig)
, mTaskQueue(aTaskQueue)
, mCallback(aCallback)
, mPacketCount(0)
, mFrames(0)
+ , mIsFlushing(false)
{
// Zero these member vars to avoid crashes in Vorbis clear functions when
// destructor is called before |Init|.
PodZero(&mVorbisBlock);
PodZero(&mVorbisDsp);
PodZero(&mVorbisInfo);
PodZero(&mVorbisComment);
}
@@ -133,16 +135,19 @@ VorbisDataDecoder::Input(MediaRawData* a
this, &VorbisDataDecoder::ProcessDecode, aSample));
return NS_OK;
}
void
VorbisDataDecoder::ProcessDecode(MediaRawData* aSample)
{
+ if (mIsFlushing) {
+ return;
+ }
if (DoDecode(aSample) == -1) {
mCallback->Error();
} else if (mTaskQueue->IsEmpty()) {
mCallback->InputExhausted();
}
}
int
@@ -264,22 +269,26 @@ VorbisDataDecoder::Drain()
{
mTaskQueue->Dispatch(NewRunnableMethod(this, &VorbisDataDecoder::ProcessDrain));
return NS_OK;
}
nsresult
VorbisDataDecoder::Flush()
{
- mTaskQueue->Flush();
- // Ignore failed results from vorbis_synthesis_restart. They
- // aren't fatal and it fails when ResetDecode is called at a
- // time when no vorbis data has been read.
- vorbis_synthesis_restart(&mVorbisDsp);
- mLastFrameTime.reset();
+ mIsFlushing = true;
+ nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([this] () {
+ // Ignore failed results from vorbis_synthesis_restart. They
+ // aren't fatal and it fails when ResetDecode is called at a
+ // time when no vorbis data has been read.
+ vorbis_synthesis_restart(&mVorbisDsp);
+ mLastFrameTime.reset();
+ });
+ SyncRunnable::DispatchToThread(mTaskQueue, r);
+ mIsFlushing = false;
return NS_OK;
}
/* static */
bool
VorbisDataDecoder::IsVorbis(const nsACString& aMimeType)
{
return aMimeType.EqualsLiteral("audio/webm; codecs=vorbis") ||
--- a/dom/media/platforms/agnostic/VorbisDecoder.h
+++ b/dom/media/platforms/agnostic/VorbisDecoder.h
@@ -56,12 +56,13 @@ private:
vorbis_comment mVorbisComment;
vorbis_dsp_state mVorbisDsp;
vorbis_block mVorbisBlock;
int64_t mPacketCount;
int64_t mFrames;
Maybe<int64_t> mLastFrameTime;
UniquePtr<AudioConverter> mAudioConverter;
+ Atomic<bool> mIsFlushing;
};
} // namespace mozilla
#endif