diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /dom/media/platforms/wmf/WMF.h | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/platforms/wmf/WMF.h')
-rw-r--r-- | dom/media/platforms/wmf/WMF.h | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/dom/media/platforms/wmf/WMF.h b/dom/media/platforms/wmf/WMF.h index 740442ceda..86afcb8e5c 100644 --- a/dom/media/platforms/wmf/WMF.h +++ b/dom/media/platforms/wmf/WMF.h @@ -23,6 +23,7 @@ #include <codecapi.h> #include "mozilla/Atomics.h" +#include "mozilla/AppShutdown.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/StaticMutex.h" #include "nsThreadUtils.h" @@ -74,7 +75,8 @@ class MediaFoundationInitializer final { if (sIsShutdown) { return false; } - return Get()->mHasInitialized; + auto* rv = Get(); + return rv ? rv->mHasInitialized : false; } private: @@ -82,17 +84,36 @@ class MediaFoundationInitializer final { { StaticMutexAutoLock lock(sCreateMutex); if (!sInitializer) { + // Already in shutdown. + if (AppShutdown::GetCurrentShutdownPhase() != + ShutdownPhase::NotInShutdown) { + sIsShutdown = true; + return nullptr; + } sInitializer.reset(new MediaFoundationInitializer()); - GetMainThreadSerialEventTarget()->Dispatch( - NS_NewRunnableFunction("MediaFoundationInitializer::Get", [&] { - // Need to run this before MTA thread gets destroyed. - RunOnShutdown( - [&] { - sInitializer.reset(); - sIsShutdown = true; - }, - ShutdownPhase::XPCOMShutdown); - })); + auto shutdownCleanUp = [&] { + if (AppShutdown::GetCurrentShutdownPhase() != + ShutdownPhase::NotInShutdown) { + sInitializer.reset(); + sIsShutdown = true; + return; + } + // As MFShutdown needs to run on the MTA thread that is destroyed + // on XPCOMShutdownThreads, so we need to run cleanup before that + // phase. + RunOnShutdown( + [&]() { + sInitializer.reset(); + sIsShutdown = true; + }, + ShutdownPhase::XPCOMShutdown); + }; + if (NS_IsMainThread()) { + shutdownCleanUp(); + } else { + GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction( + "MediaFoundationInitializer::Get", shutdownCleanUp)); + } } } return sInitializer.get(); |