Bug 1340969. Part 2 - remove MFR::mShutdownPromise by using promise chaining.
MozReview-Commit-ID: 6Oa1yar80aH
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1076,25 +1076,21 @@ MediaFormatReader::Shutdown()
}
mShutdownPromisePool->Track(mDemuxer->Shutdown());
mDemuxer = nullptr;
mCompositorUpdatedListener.DisconnectIfExists();
mOnTrackWaitingForKeyListener.Disconnect();
- RefPtr<ShutdownPromise> p = mShutdownPromise.Ensure(__func__);
- mShutdownPromisePool->Shutdown()
+ mShutdown = true;
+ return mShutdownPromisePool->Shutdown()
->Then(OwnerThread(), __func__, this,
&MediaFormatReader::TearDownDecoders,
&MediaFormatReader::TearDownDecoders);
-
- mShutdown = true;
-
- return p;
}
RefPtr<ShutdownPromise>
MediaFormatReader::ShutdownDecoderWithPromise(TrackType aTrack)
{
LOGV("%s", TrackTypeToStr(aTrack));
auto& decoder = GetDecoderData(aTrack);
@@ -1137,17 +1133,17 @@ MediaFormatReader::ShutdownDecoder(Track
}
if (!decoder.mShutdownPromise.IsEmpty()) {
LOGV("Shutdown already in progress");
return;
}
Unused << ShutdownDecoderWithPromise(aTrack);
}
-void
+RefPtr<ShutdownPromise>
MediaFormatReader::TearDownDecoders()
{
if (mAudio.mTaskQueue) {
mAudio.mTaskQueue->BeginShutdown();
mAudio.mTaskQueue->AwaitShutdownAndIdle();
mAudio.mTaskQueue = nullptr;
}
if (mVideo.mTaskQueue) {
@@ -1155,22 +1151,17 @@ MediaFormatReader::TearDownDecoders()
mVideo.mTaskQueue->AwaitShutdownAndIdle();
mVideo.mTaskQueue = nullptr;
}
mDecoderFactory = nullptr;
mPlatform = nullptr;
mVideoFrameContainer = nullptr;
- if (mShutdownPromise.IsEmpty()) {
- return;
- }
-
- MediaDecoderReader::Shutdown();
- mShutdownPromise.Resolve(true, __func__);
+ return MediaDecoderReader::Shutdown();
}
void
MediaFormatReader::InitLayersBackendType()
{
// Extract the layer manager backend type so that platform decoders
// can determine whether it's worthwhile using hardware accelerated
// video decoding.
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -590,15 +590,14 @@ private:
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 TearDownDecoders();
- MozPromiseHolder<ShutdownPromise> mShutdownPromise;
+ RefPtr<ShutdownPromise> TearDownDecoders();
};
} // namespace mozilla
#endif