Bug 1341200. Part 6 - let ShutdownDecoderWithPromise() return void by tracking the shutdown promise. r=jya
MozReview-Commit-ID: GIYdLXZYEyk
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1108,88 +1108,90 @@ MediaFormatReader::Shutdown()
mVideo.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
}
if (HasAudio()) {
mAudio.ResetDemuxer();
mAudio.mTrackDemuxer->BreakCycles();
mAudio.mTrackDemuxer = nullptr;
mAudio.ResetState();
- mShutdownPromisePool->Track(ShutdownDecoderWithPromise(TrackInfo::kAudioTrack));
+ ShutdownDecoderWithPromise(TrackInfo::kAudioTrack);
}
if (HasVideo()) {
mVideo.ResetDemuxer();
mVideo.mTrackDemuxer->BreakCycles();
mVideo.mTrackDemuxer = nullptr;
mVideo.ResetState();
- mShutdownPromisePool->Track(ShutdownDecoderWithPromise(TrackInfo::kVideoTrack));
+ ShutdownDecoderWithPromise(TrackInfo::kVideoTrack);
}
mShutdownPromisePool->Track(mDemuxer->Shutdown());
mDemuxer = nullptr;
mCompositorUpdatedListener.DisconnectIfExists();
mOnTrackWaitingForKeyListener.Disconnect();
mShutdown = true;
return mShutdownPromisePool->Shutdown()
->Then(OwnerThread(), __func__, this,
&MediaFormatReader::TearDownDecoders,
&MediaFormatReader::TearDownDecoders);
}
-RefPtr<ShutdownPromise>
+void
MediaFormatReader::ShutdownDecoderWithPromise(TrackType aTrack)
{
LOGV("%s", TrackTypeToStr(aTrack));
auto& decoder = GetDecoderData(aTrack);
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__);
+ mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
+ return;
}
if (decoder.mFlushing || decoder.mShuttingDown) {
// 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__);
+ mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
+ return;
}
if (!decoder.mDecoder) {
// Shutdown any decoders that may be in the process of being initialized
// in the Decoder Factory.
// This will be a no-op until we're processing the final decoder shutdown
// prior to the MediaFormatReader being shutdown.
mDecoderFactory->ShutdownDecoder(aTrack);
- return ShutdownPromise::CreateAndResolve(true, __func__);
+ return;
}
// Finally, let's just shut down the currently active decoder.
decoder.ShutdownDecoder();
- return decoder.mShutdownPromise.Ensure(__func__);
+ mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
}
void
MediaFormatReader::ShutdownDecoder(TrackType aTrack)
{
LOG("%s", TrackTypeToStr(aTrack));
auto& decoder = GetDecoderData(aTrack);
if (!decoder.mDecoder) {
LOGV("Already shut down");
return;
}
if (!decoder.mShutdownPromise.IsEmpty()) {
LOGV("Shutdown already in progress");
return;
}
- Unused << ShutdownDecoderWithPromise(aTrack);
+ ShutdownDecoderWithPromise(aTrack);
}
RefPtr<ShutdownPromise>
MediaFormatReader::TearDownDecoders()
{
if (mAudio.mTaskQueue) {
mAudio.mTaskQueue->BeginShutdown();
mAudio.mTaskQueue->AwaitShutdownAndIdle();
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -544,15 +544,15 @@ private:
void MaybeResolveMetadataPromise();
UniquePtr<MetadataTags> mTags;
// A flag indicating if the start time is known or not.
bool mHasStartTime = false;
void ShutdownDecoder(TrackType aTrack);
- RefPtr<ShutdownPromise> ShutdownDecoderWithPromise(TrackType aTrack);
+ void ShutdownDecoderWithPromise(TrackType aTrack);
RefPtr<ShutdownPromise> TearDownDecoders();
};
} // namespace mozilla
#endif