summaryrefslogtreecommitdiffstats
path: root/dom/media/eme/mediafoundation
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /dom/media/eme/mediafoundation
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/eme/mediafoundation')
-rw-r--r--dom/media/eme/mediafoundation/WMFCDMImpl.cpp155
-rw-r--r--dom/media/eme/mediafoundation/WMFCDMImpl.h24
-rw-r--r--dom/media/eme/mediafoundation/WMFCDMProxy.cpp2
3 files changed, 106 insertions, 75 deletions
diff --git a/dom/media/eme/mediafoundation/WMFCDMImpl.cpp b/dom/media/eme/mediafoundation/WMFCDMImpl.cpp
index add978f755..983a7c00f2 100644
--- a/dom/media/eme/mediafoundation/WMFCDMImpl.cpp
+++ b/dom/media/eme/mediafoundation/WMFCDMImpl.cpp
@@ -10,81 +10,12 @@
#include "mozilla/AppShutdown.h"
#include "mozilla/ClearOnShutdown.h"
+#include "mozilla/ScopeExit.h"
#include "mozilla/dom/MediaKeySession.h"
#include "mozilla/dom/KeySystemNames.h"
namespace mozilla {
-bool WMFCDMImpl::GetCapabilities(bool aIsHardwareDecryption,
- nsTArray<KeySystemConfig>& aOutConfigs) {
- MOZ_ASSERT(NS_IsMainThread());
- if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
- return false;
- }
-
- static std::unordered_map<std::string, nsTArray<KeySystemConfig>>
- sKeySystemConfigs{};
- static bool sSetRunOnShutdown = false;
- if (!sSetRunOnShutdown) {
- GetMainThreadSerialEventTarget()->Dispatch(
- NS_NewRunnableFunction("WMFCDMImpl::GetCapabilities", [&] {
- RunOnShutdown([&] { sKeySystemConfigs.clear(); },
- ShutdownPhase::XPCOMShutdown);
- }));
- sSetRunOnShutdown = true;
- }
-
- // Retrieve result from our cached key system
- auto keySystem = std::string{NS_ConvertUTF16toUTF8(mKeySystem).get()};
- if (auto rv = sKeySystemConfigs.find(keySystem);
- rv != sKeySystemConfigs.end()) {
- for (const auto& config : rv->second) {
- if (IsHardwareDecryptionSupported(config) == aIsHardwareDecryption) {
- EME_LOG("Return cached capabilities for %s (%s)", keySystem.c_str(),
- NS_ConvertUTF16toUTF8(config.GetDebugInfo()).get());
- aOutConfigs.AppendElement(config);
- return true;
- }
- }
- }
-
- // Not cached result, ask the remote process.
- nsCOMPtr<nsISerialEventTarget> backgroundTaskQueue;
- NS_CreateBackgroundTaskQueue(__func__, getter_AddRefs(backgroundTaskQueue));
- if (!mCDM) {
- mCDM = MakeRefPtr<MFCDMChild>(mKeySystem);
- }
- bool ok = false;
- media::Await(
- do_AddRef(backgroundTaskQueue),
- mCDM->GetCapabilities(aIsHardwareDecryption),
- [&ok, &aOutConfigs, keySystem,
- aIsHardwareDecryption](const MFCDMCapabilitiesIPDL& capabilities) {
- EME_LOG("capabilities: keySystem=%s (hw-secure=%d)", keySystem.c_str(),
- aIsHardwareDecryption);
- for (const auto& v : capabilities.videoCapabilities()) {
- EME_LOG("capabilities: video=%s",
- NS_ConvertUTF16toUTF8(v.contentType()).get());
- }
- for (const auto& a : capabilities.audioCapabilities()) {
- EME_LOG("capabilities: audio=%s",
- NS_ConvertUTF16toUTF8(a.contentType()).get());
- }
- for (const auto& v : capabilities.encryptionSchemes()) {
- EME_LOG("capabilities: encryptionScheme=%s", EncryptionSchemeStr(v));
- }
- KeySystemConfig* config = aOutConfigs.AppendElement();
- MFCDMCapabilitiesIPDLToKeySystemConfig(capabilities, *config);
- sKeySystemConfigs[keySystem].AppendElement(*config);
- ok = true;
- },
- [](nsresult rv) {
- EME_LOG("Fail to get key system capabilities. rv=%x", uint32_t(rv));
- });
-
- return ok;
-}
-
RefPtr<WMFCDMImpl::InitPromise> WMFCDMImpl::Init(
const WMFCDMImpl::InitParams& aParams) {
if (!mCDM) {
@@ -111,4 +42,88 @@ RefPtr<WMFCDMImpl::InitPromise> WMFCDMImpl::Init(
return mInitPromiseHolder.Ensure(__func__);
}
+RefPtr<KeySystemConfig::SupportedConfigsPromise>
+WMFCDMCapabilites::GetCapabilities(
+ const nsTArray<KeySystemConfigRequest>& aRequests) {
+ MOZ_ASSERT(NS_IsMainThread());
+ if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
+ return SupportedConfigsPromise::CreateAndReject(false, __func__);
+ }
+
+ if (!mCapabilitiesPromiseHolder.IsEmpty()) {
+ return mCapabilitiesPromiseHolder.Ensure(__func__);
+ }
+
+ using CapabilitiesPromise = MFCDMChild::CapabilitiesPromise;
+ nsTArray<RefPtr<CapabilitiesPromise>> promises;
+ for (const auto& request : aRequests) {
+ RefPtr<MFCDMChild> cdm = new MFCDMChild(request.mKeySystem);
+ promises.AppendElement(cdm->GetCapabilities(MFCDMCapabilitiesRequest{
+ nsString{request.mKeySystem},
+ request.mDecryption == KeySystemConfig::DecryptionInfo::Hardware}));
+ mCDMs.AppendElement(std::move(cdm));
+ }
+
+ CapabilitiesPromise::AllSettled(GetCurrentSerialEventTarget(), promises)
+ ->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ [self = RefPtr<WMFCDMCapabilites>(this), this](
+ CapabilitiesPromise::AllSettledPromiseType::ResolveOrRejectValue&&
+ aResult) {
+ mCapabilitiesPromisesRequest.Complete();
+
+ // Reset cdm
+ auto exit = MakeScopeExit([&] {
+ for (auto& cdm : mCDMs) {
+ cdm->Shutdown();
+ }
+ mCDMs.Clear();
+ });
+
+ nsTArray<KeySystemConfig> outConfigs;
+ for (const auto& promiseRv : aResult.ResolveValue()) {
+ if (promiseRv.IsReject()) {
+ continue;
+ }
+ const MFCDMCapabilitiesIPDL& capabilities =
+ promiseRv.ResolveValue();
+ EME_LOG("capabilities: keySystem=%s (hw-secure=%d)",
+ NS_ConvertUTF16toUTF8(capabilities.keySystem()).get(),
+ capabilities.isHardwareDecryption());
+ for (const auto& v : capabilities.videoCapabilities()) {
+ EME_LOG("capabilities: video=%s",
+ NS_ConvertUTF16toUTF8(v.contentType()).get());
+ }
+ for (const auto& a : capabilities.audioCapabilities()) {
+ EME_LOG("capabilities: audio=%s",
+ NS_ConvertUTF16toUTF8(a.contentType()).get());
+ }
+ for (const auto& v : capabilities.encryptionSchemes()) {
+ EME_LOG("capabilities: encryptionScheme=%s",
+ EncryptionSchemeStr(v));
+ }
+ KeySystemConfig* config = outConfigs.AppendElement();
+ MFCDMCapabilitiesIPDLToKeySystemConfig(capabilities, *config);
+ }
+ if (outConfigs.IsEmpty()) {
+ EME_LOG(
+ "Failed on getting capabilities from all settled promise");
+ mCapabilitiesPromiseHolder.Reject(false, __func__);
+ return;
+ }
+ mCapabilitiesPromiseHolder.Resolve(std::move(outConfigs), __func__);
+ })
+ ->Track(mCapabilitiesPromisesRequest);
+
+ return mCapabilitiesPromiseHolder.Ensure(__func__);
+}
+
+WMFCDMCapabilites::~WMFCDMCapabilites() {
+ mCapabilitiesPromisesRequest.DisconnectIfExists();
+ mCapabilitiesPromiseHolder.RejectIfExists(false, __func__);
+ for (auto& cdm : mCDMs) {
+ cdm->Shutdown();
+ }
+}
+
} // namespace mozilla
diff --git a/dom/media/eme/mediafoundation/WMFCDMImpl.h b/dom/media/eme/mediafoundation/WMFCDMImpl.h
index b7e6308848..c5bf8234af 100644
--- a/dom/media/eme/mediafoundation/WMFCDMImpl.h
+++ b/dom/media/eme/mediafoundation/WMFCDMImpl.h
@@ -34,10 +34,6 @@ class WMFCDMImpl final {
explicit WMFCDMImpl(const nsAString& aKeySystem) : mKeySystem(aKeySystem) {}
- // TODO: make this async?
- bool GetCapabilities(bool aIsHardwareDecryption,
- nsTArray<KeySystemConfig>& aOutConfigs);
-
using InitPromise = GenericPromise;
struct InitParams {
nsString mOrigin;
@@ -119,6 +115,26 @@ class WMFCDMImpl final {
MozPromiseHolder<InitPromise> mInitPromiseHolder;
};
+// A helper class to get multiple capabilities from different key systems.
+class WMFCDMCapabilites final {
+ public:
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WMFCDMCapabilites);
+ WMFCDMCapabilites() = default;
+
+ using SupportedConfigsPromise = KeySystemConfig::SupportedConfigsPromise;
+ RefPtr<SupportedConfigsPromise> GetCapabilities(
+ const nsTArray<KeySystemConfigRequest>& aRequests);
+
+ private:
+ ~WMFCDMCapabilites();
+
+ nsTArray<RefPtr<MFCDMChild>> mCDMs;
+ MozPromiseHolder<SupportedConfigsPromise> mCapabilitiesPromiseHolder;
+ MozPromiseRequestHolder<
+ MFCDMChild::CapabilitiesPromise::AllSettledPromiseType>
+ mCapabilitiesPromisesRequest;
+};
+
} // namespace mozilla
#endif // DOM_MEDIA_EME_MEDIAFOUNDATION_WMFCDMIMPL_H_
diff --git a/dom/media/eme/mediafoundation/WMFCDMProxy.cpp b/dom/media/eme/mediafoundation/WMFCDMProxy.cpp
index f7e05dfb6a..5fd73c2dcf 100644
--- a/dom/media/eme/mediafoundation/WMFCDMProxy.cpp
+++ b/dom/media/eme/mediafoundation/WMFCDMProxy.cpp
@@ -158,7 +158,7 @@ void WMFCDMProxy::ResolvePromiseWithKeyStatus(
RETURN_IF_SHUTDOWN();
EME_LOG("WMFCDMProxy::ResolvePromiseWithKeyStatus(this=%p, pid=%" PRIu32
", status=%s)",
- this, aId, ToMediaKeyStatusStr(aStatus));
+ this, aId, dom::GetEnumString(aStatus).get());
if (!mKeys.IsNull()) {
mKeys->ResolvePromiseWithKeyStatus(aId, aStatus);
} else {