Bug 1341200. Part 2 - replace mFlushRequest with a bool for mFlushRequest.Disconnect() is never used and a bool is sufficient to do the job.
MozReview-Commit-ID: GFnSvunqtGq
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1080,17 +1080,17 @@ MediaFormatReader::ShutdownDecoderWithPr
if (!decoder.mFlushed && decoder.mDecoder) {
// The decoder has yet to be flushed.
// We always flush the decoder prior to a shutdown to ensure that all the
// potentially pending operations on the decoder are completed.
decoder.Flush();
return decoder.mShutdownPromise.Ensure(__func__);
}
- if (decoder.mFlushRequest.Exists() || decoder.mShutdownRequest.Exists()) {
+ if (decoder.mFlushing || decoder.mShutdownRequest.Exists()) {
// Let the current flush or shutdown operation complete, Flush will continue
// shutting down the current decoder now that the shutdown promise is set.
return decoder.mShutdownPromise.Ensure(__func__);
}
if (!decoder.mDecoder) {
// Shutdown any decoders that may be in the process of being initialized
// in the Decoder Factory.
@@ -1887,17 +1887,17 @@ MediaFormatReader::DecodeDemuxedSamples(
void
MediaFormatReader::HandleDemuxedSamples(
TrackType aTrack, AbstractMediaDecoder::AutoNotifyDecoded& aA)
{
MOZ_ASSERT(OnTaskQueue());
auto& decoder = GetDecoderData(aTrack);
- if (decoder.mFlushRequest.Exists() || decoder.mShutdownRequest.Exists()) {
+ if (decoder.mFlushing || decoder.mShutdownRequest.Exists()) {
LOGV("Decoder operation in progress, let it complete.");
return;
}
if (decoder.mQueuedSamples.IsEmpty()) {
return;
}
@@ -2269,17 +2269,17 @@ MediaFormatReader::Update(TrackType aTra
" qs=%u decoding:%d flushing:%d shutdown:%d pending:%u waiting:%d sid:%u",
TrackTypeToStr(aTrack),
needInput,
needOutput,
decoder.mNumSamplesInput,
decoder.mNumSamplesOutput,
uint32_t(size_t(decoder.mSizeOfQueue)),
decoder.mDecodeRequest.Exists(),
- decoder.mFlushRequest.Exists(),
+ decoder.mFlushing,
decoder.mShutdownRequest.Exists(),
uint32_t(decoder.mOutput.Length()),
decoder.mWaitingForData,
decoder.mLastStreamSourceID);
if ((decoder.mWaitingForData
&& (!decoder.mTimeThreshold || decoder.mTimeThreshold.ref().mWaiting))
|| (decoder.mWaitingForKey && decoder.mDecodeRequest.Exists())) {
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -180,16 +180,17 @@ private:
, mType(aType)
, mMutex("DecoderData")
, mDescription("shutdown")
, mUpdateScheduled(false)
, mDemuxEOS(false)
, mWaitingForData(false)
, mWaitingForKey(false)
, mReceivedNewData(false)
+ , mFlushing(false)
, mFlushed(true)
, mDrainState(DrainState::None)
, mNumOfConsecutiveError(0)
, mMaxConsecutiveError(aNumOfMaxError)
, mNumSamplesInput(0)
, mNumSamplesOutput(0)
, mNumSamplesOutputTotal(0)
, mNumSamplesSkippedTotal(0)
@@ -259,17 +260,17 @@ private:
bool IsWaiting() const
{
MOZ_ASSERT(mOwner->OnTaskQueue());
return mWaitingForData || mWaitingForKey;
}
// MediaDataDecoder handler's variables.
MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDecodeRequest;
- MozPromiseRequestHolder<MediaDataDecoder::FlushPromise> mFlushRequest;
+ bool mFlushing; // True if flush is in action.
// Set to true if the last operation run on the decoder was a flush.
bool mFlushed;
MozPromiseHolder<ShutdownPromise> mShutdownPromise;
MozPromiseRequestHolder<ShutdownPromise> mShutdownRequest;
MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDrainRequest;
DrainState mDrainState;
bool HasPendingDrain() const
@@ -337,52 +338,52 @@ private:
mTrackDemuxer->Reset();
mQueuedSamples.Clear();
}
// Flush the decoder if present and reset decoding related data.
// Following a flush, the decoder is ready to accept any new data.
void Flush()
{
- if (mFlushRequest.Exists() || mFlushed) {
+ if (mFlushing || mFlushed) {
// Flush still pending or already flushed, nothing more to do.
return;
}
mDecodeRequest.DisconnectIfExists();
mDrainRequest.DisconnectIfExists();
mDrainState = DrainState::None;
CancelWaitingForKey();
mOutput.Clear();
mNumSamplesInput = 0;
mNumSamplesOutput = 0;
mSizeOfQueue = 0;
if (mDecoder && !mFlushed) {
RefPtr<MediaFormatReader> owner = mOwner;
TrackType type = mType == MediaData::AUDIO_DATA
? TrackType::kAudioTrack
: TrackType::kVideoTrack;
+ mFlushing = true;
mDecoder->Flush()
->Then(mOwner->OwnerThread(), __func__,
[owner, type, this]() {
- mFlushRequest.Complete();
+ mFlushing = false;
if (!mShutdownPromise.IsEmpty()) {
ShutdownDecoder();
return;
}
owner->ScheduleUpdate(type);
},
[owner, type, this](const MediaResult& aError) {
- mFlushRequest.Complete();
+ mFlushing = false;
if (!mShutdownPromise.IsEmpty()) {
ShutdownDecoder();
return;
}
owner->NotifyError(type, aError);
- })
- ->Track(mFlushRequest);
+ });
}
mFlushed = true;
}
bool CancelWaitingForKey()
{
if (!mWaitingForKey) {
return false;