summaryrefslogtreecommitdiffstats
path: root/dom/media/eme
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /dom/media/eme
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/eme')
-rw-r--r--dom/media/eme/EMEUtils.cpp39
-rw-r--r--dom/media/eme/EMEUtils.h3
-rw-r--r--dom/media/eme/KeySystemConfig.cpp37
-rw-r--r--dom/media/eme/KeySystemConfig.h7
-rw-r--r--dom/media/eme/MediaKeySession.cpp23
-rw-r--r--dom/media/eme/MediaKeySession.h7
-rw-r--r--dom/media/eme/MediaKeySystemAccess.cpp85
-rw-r--r--dom/media/eme/MediaKeySystemAccess.h3
-rw-r--r--dom/media/eme/MediaKeySystemAccessManager.cpp3
-rw-r--r--dom/media/eme/MediaKeys.cpp17
-rw-r--r--dom/media/eme/mediadrm/MediaDrmCDMCallbackProxy.cpp1
-rw-r--r--dom/media/eme/mediafoundation/WMFCDMImpl.cpp107
-rw-r--r--dom/media/eme/mediafoundation/WMFCDMImpl.h4
-rw-r--r--dom/media/eme/mediafoundation/WMFCDMProxy.cpp3
14 files changed, 194 insertions, 145 deletions
diff --git a/dom/media/eme/EMEUtils.cpp b/dom/media/eme/EMEUtils.cpp
index 294951e7e6..5a6b645df2 100644
--- a/dom/media/eme/EMEUtils.cpp
+++ b/dom/media/eme/EMEUtils.cpp
@@ -8,13 +8,13 @@
#include "jsfriendapi.h"
#include "MediaData.h"
+#include "KeySystemConfig.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/dom/KeySystemNames.h"
#include "mozilla/dom/UnionTypes.h"
#ifdef MOZ_WMF_CDM
# include "mozilla/PMFCDM.h"
-# include "KeySystemConfig.h"
#endif
namespace mozilla {
@@ -143,22 +143,35 @@ const char* ToMediaKeyStatusStr(dom::MediaKeyStatus aStatus) {
bool IsHardwareDecryptionSupported(
const dom::MediaKeySystemConfiguration& aConfig) {
- bool supportHardwareDecryption = false;
for (const auto& capabilities : aConfig.mAudioCapabilities) {
if (capabilities.mRobustness.EqualsLiteral("HW_SECURE_ALL")) {
- supportHardwareDecryption = true;
- break;
+ return true;
}
}
for (const auto& capabilities : aConfig.mVideoCapabilities) {
if (capabilities.mRobustness.EqualsLiteral("3000") ||
capabilities.mRobustness.EqualsLiteral("HW_SECURE_ALL") ||
capabilities.mRobustness.EqualsLiteral("HW_SECURE_DECODE")) {
- supportHardwareDecryption = true;
- break;
+ return true;
+ }
+ }
+ return false;
+}
+
+bool IsHardwareDecryptionSupported(const KeySystemConfig& aConfig) {
+ for (const auto& robustness : aConfig.mAudioRobustness) {
+ if (robustness.EqualsLiteral("HW_SECURE_ALL")) {
+ return true;
+ }
+ }
+ for (const auto& robustness : aConfig.mVideoRobustness) {
+ if (robustness.EqualsLiteral("3000") ||
+ robustness.EqualsLiteral("HW_SECURE_ALL") ||
+ robustness.EqualsLiteral("HW_SECURE_DECODE")) {
+ return true;
}
}
- return supportHardwareDecryption;
+ return false;
}
const char* EncryptionSchemeStr(const CryptoScheme& aScheme) {
@@ -245,4 +258,16 @@ bool CheckIfHarewareDRMConfigExists(
return foundHWDRMconfig;
}
+bool DoesKeySystemSupportHardwareDecryption(const nsAString& aKeySystem) {
+#ifdef MOZ_WMF_CDM
+ if (aKeySystem.EqualsLiteral(kPlayReadyKeySystemHardware) ||
+ aKeySystem.EqualsLiteral(kPlayReadyHardwareClearLeadKeySystemName) ||
+ aKeySystem.EqualsLiteral(kWidevineExperimentKeySystemName) ||
+ aKeySystem.EqualsLiteral(kWidevineExperiment2KeySystemName)) {
+ return true;
+ }
+#endif
+ return false;
+}
+
} // namespace mozilla
diff --git a/dom/media/eme/EMEUtils.h b/dom/media/eme/EMEUtils.h
index ca5c684a9f..3fbf22f359 100644
--- a/dom/media/eme/EMEUtils.h
+++ b/dom/media/eme/EMEUtils.h
@@ -89,6 +89,7 @@ const char* ToMediaKeyStatusStr(dom::MediaKeyStatus aStatus);
// Return true if given config supports hardware decryption (SL3000 or L1).
bool IsHardwareDecryptionSupported(
const dom::MediaKeySystemConfiguration& aConfig);
+bool IsHardwareDecryptionSupported(const KeySystemConfig& aConfig);
const char* EncryptionSchemeStr(const CryptoScheme& aScheme);
@@ -104,6 +105,8 @@ bool DoesKeySystemSupportClearLead(const nsAString& aKeySystem);
bool CheckIfHarewareDRMConfigExists(
const nsTArray<dom::MediaKeySystemConfiguration>& aConfigs);
+bool DoesKeySystemSupportHardwareDecryption(const nsAString& aKeySystem);
+
} // namespace mozilla
#endif // EME_LOG_H_
diff --git a/dom/media/eme/KeySystemConfig.cpp b/dom/media/eme/KeySystemConfig.cpp
index b1b1f9ff63..0cb5da1a56 100644
--- a/dom/media/eme/KeySystemConfig.cpp
+++ b/dom/media/eme/KeySystemConfig.cpp
@@ -57,9 +57,10 @@ bool KeySystemConfig::Supports(const nsAString& aKeySystem) {
{nsCString(kWidevineExperimentKeySystemName)});
}
- if ((IsPlayReadyKeySystemAndSupported(aKeySystem) ||
- IsWMFClearKeySystemAndSupported(aKeySystem)) &&
- WMFCDMImpl::Supports(aKeySystem)) {
+ // PlayReady and WMF-based ClearKey are always installed, we don't need to
+ // download them.
+ if (IsPlayReadyKeySystemAndSupported(aKeySystem) ||
+ IsWMFClearKeySystemAndSupported(aKeySystem)) {
return true;
}
#endif
@@ -69,7 +70,8 @@ bool KeySystemConfig::Supports(const nsAString& aKeySystem) {
/* static */
bool KeySystemConfig::CreateKeySystemConfigs(
- const nsAString& aKeySystem, nsTArray<KeySystemConfig>& aOutConfigs) {
+ const nsAString& aKeySystem, const DecryptionInfo aDecryption,
+ nsTArray<KeySystemConfig>& aOutConfigs) {
if (!Supports(aKeySystem)) {
return false;
}
@@ -103,10 +105,16 @@ bool KeySystemConfig::CreateKeySystemConfigs(
config->mMP4.SetCanDecrypt(EME_CODEC_FLAC);
config->mMP4.SetCanDecrypt(EME_CODEC_OPUS);
config->mMP4.SetCanDecrypt(EME_CODEC_VP9);
+#ifdef MOZ_AV1
+ config->mMP4.SetCanDecrypt(EME_CODEC_AV1);
+#endif
config->mWebM.SetCanDecrypt(EME_CODEC_VORBIS);
config->mWebM.SetCanDecrypt(EME_CODEC_OPUS);
config->mWebM.SetCanDecrypt(EME_CODEC_VP8);
config->mWebM.SetCanDecrypt(EME_CODEC_VP9);
+#ifdef MOZ_AV1
+ config->mWebM.SetCanDecrypt(EME_CODEC_AV1);
+#endif
if (StaticPrefs::media_clearkey_test_key_systems_enabled()) {
// Add testing key systems. These offer the same capabilities as the
@@ -156,6 +164,10 @@ bool KeySystemConfig::CreateKeySystemConfigs(
&config->mMP4},
{nsCString(VIDEO_MP4), EME_CODEC_VP9, java::MediaDrmProxy::AVC,
&config->mMP4},
+# ifdef MOZ_AV1
+ {nsCString(VIDEO_MP4), EME_CODEC_AV1, java::MediaDrmProxy::AV1,
+ &config->mMP4},
+# endif
{nsCString(AUDIO_MP4), EME_CODEC_AAC, java::MediaDrmProxy::AAC,
&config->mMP4},
{nsCString(AUDIO_MP4), EME_CODEC_FLAC, java::MediaDrmProxy::FLAC,
@@ -166,6 +178,10 @@ bool KeySystemConfig::CreateKeySystemConfigs(
&config->mWebM},
{nsCString(VIDEO_WEBM), EME_CODEC_VP9, java::MediaDrmProxy::VP9,
&config->mWebM},
+# ifdef MOZ_AV1
+ {nsCString(VIDEO_WEBM), EME_CODEC_AV1, java::MediaDrmProxy::AV1,
+ &config->mWebM},
+# endif
{nsCString(AUDIO_WEBM), EME_CODEC_VORBIS, java::MediaDrmProxy::VORBIS,
&config->mWebM},
{nsCString(AUDIO_WEBM), EME_CODEC_OPUS, java::MediaDrmProxy::OPUS,
@@ -198,10 +214,16 @@ bool KeySystemConfig::CreateKeySystemConfigs(
config->mMP4.SetCanDecrypt(EME_CODEC_OPUS);
config->mMP4.SetCanDecryptAndDecode(EME_CODEC_H264);
config->mMP4.SetCanDecryptAndDecode(EME_CODEC_VP9);
+# ifdef MOZ_AV1
+ config->mMP4.SetCanDecryptAndDecode(EME_CODEC_AV1);
+# endif
config->mWebM.SetCanDecrypt(EME_CODEC_VORBIS);
config->mWebM.SetCanDecrypt(EME_CODEC_OPUS);
config->mWebM.SetCanDecryptAndDecode(EME_CODEC_VP8);
config->mWebM.SetCanDecryptAndDecode(EME_CODEC_VP9);
+# ifdef MOZ_AV1
+ config->mWebM.SetCanDecryptAndDecode(EME_CODEC_AV1);
+# endif
#endif
return true;
}
@@ -209,7 +231,8 @@ bool KeySystemConfig::CreateKeySystemConfigs(
if (IsPlayReadyKeySystemAndSupported(aKeySystem) ||
IsWidevineExperimentKeySystemAndSupported(aKeySystem)) {
RefPtr<WMFCDMImpl> cdm = MakeRefPtr<WMFCDMImpl>(aKeySystem);
- return cdm->GetCapabilities(aOutConfigs);
+ return cdm->GetCapabilities(aDecryption == DecryptionInfo::Hardware,
+ aOutConfigs);
}
#endif
return false;
@@ -243,7 +266,9 @@ void KeySystemConfig::GetGMPKeySystemConfigs(dom::Promise* aPromise) {
continue;
}
#endif
- if (KeySystemConfig::CreateKeySystemConfigs(name, keySystemConfigs)) {
+ if (KeySystemConfig::CreateKeySystemConfigs(
+ name, KeySystemConfig::DecryptionInfo::Software,
+ keySystemConfigs)) {
auto* info = cdmInfo.AppendElement(fallible);
if (!info) {
aPromise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
diff --git a/dom/media/eme/KeySystemConfig.h b/dom/media/eme/KeySystemConfig.h
index 8bd7d98217..cc35ba76de 100644
--- a/dom/media/eme/KeySystemConfig.h
+++ b/dom/media/eme/KeySystemConfig.h
@@ -36,6 +36,7 @@ struct KeySystemConfig {
static constexpr auto EME_CODEC_VORBIS = "vorbis"_ns;
static constexpr auto EME_CODEC_FLAC = "flac"_ns;
static constexpr auto EME_CODEC_H264 = "h264"_ns;
+ static constexpr auto EME_CODEC_AV1 = "av1"_ns;
static constexpr auto EME_CODEC_VP8 = "vp8"_ns;
static constexpr auto EME_CODEC_VP9 = "vp9"_ns;
static constexpr auto EME_CODEC_HEVC = "hevc"_ns;
@@ -123,7 +124,13 @@ struct KeySystemConfig {
// Return true if given key system is supported on the current device.
static bool Supports(const nsAString& aKeySystem);
+
+ enum class DecryptionInfo : uint8_t {
+ Software,
+ Hardware,
+ };
static bool CreateKeySystemConfigs(const nsAString& aKeySystem,
+ const DecryptionInfo aDecryption,
nsTArray<KeySystemConfig>& aOutConfigs);
static void GetGMPKeySystemConfigs(dom::Promise* aPromise);
diff --git a/dom/media/eme/MediaKeySession.cpp b/dom/media/eme/MediaKeySession.cpp
index 908df5f7c8..8a3a01dd5c 100644
--- a/dom/media/eme/MediaKeySession.cpp
+++ b/dom/media/eme/MediaKeySession.cpp
@@ -52,7 +52,7 @@ static const uint32_t MAX_CENC_INIT_DATA_LENGTH = 64 * 1024;
MediaKeySession::MediaKeySession(nsPIDOMWindowInner* aParent, MediaKeys* aKeys,
const nsAString& aKeySystem,
MediaKeySessionType aSessionType,
- ErrorResult& aRv)
+ bool aHardwareDecryption, ErrorResult& aRv)
: DOMEventTargetHelper(aParent),
mKeys(aKeys),
mKeySystem(aKeySystem),
@@ -61,7 +61,8 @@ MediaKeySession::MediaKeySession(nsPIDOMWindowInner* aParent, MediaKeys* aKeys,
mIsClosed(false),
mUninitialized(true),
mKeyStatusMap(new MediaKeyStatusMap(aParent)),
- mExpiration(JS::GenericNaN()) {
+ mExpiration(JS::GenericNaN()),
+ mHardwareDecryption(aHardwareDecryption) {
EME_LOG("MediaKeySession[%p,''] ctor", this);
MOZ_ASSERT(aParent);
@@ -123,9 +124,8 @@ void MediaKeySession::UpdateKeyStatusMap() {
nsPrintfCString("MediaKeySession[%p,'%s'] key statuses change {", this,
NS_ConvertUTF16toUTF8(mSessionId).get()));
for (const CDMCaps::KeyStatus& status : keyStatuses) {
- message.AppendPrintf(
- " (%s,%s)", ToHexString(status.mId).get(),
- nsCString(MediaKeyStatusValues::GetString(status.mStatus)).get());
+ message.AppendPrintf(" (%s,%s)", ToHexString(status.mId).get(),
+ GetEnumString(status.mStatus).get());
}
message.AppendLiteral(" }");
// Use %s so we aren't exposing random strings to printf interpolation.
@@ -250,8 +250,8 @@ already_AddRefed<Promise> MediaKeySession::GenerateRequest(
// cdm implementation value does not support initDataType as an
// Initialization Data Type, return a promise rejected with a
// NotSupportedError. String comparison is case-sensitive.
- if (!MediaKeySystemAccess::KeySystemSupportsInitDataType(mKeySystem,
- aInitDataType)) {
+ if (!MediaKeySystemAccess::KeySystemSupportsInitDataType(
+ mKeySystem, aInitDataType, mHardwareDecryption)) {
promise->MaybeRejectWithNotSupportedError(
"Unsupported initDataType passed to MediaKeySession.generateRequest()");
EME_LOG(
@@ -542,8 +542,7 @@ void MediaKeySession::DispatchKeyMessage(MediaKeyMessageType aMessageType,
EME_LOG(
"MediaKeySession[%p,'%s'] DispatchKeyMessage() type=%s message='%s'",
this, NS_ConvertUTF16toUTF8(mSessionId).get(),
- nsCString(MediaKeyMessageTypeValues::GetString(aMessageType)).get(),
- ToHexString(aMessage).get());
+ GetEnumString(aMessageType).get(), ToHexString(aMessage).get());
}
RefPtr<MediaKeyMessageEvent> event(
@@ -611,12 +610,8 @@ void MediaKeySession::SetOnmessage(EventHandlerNonNull* aCallback) {
SetEventHandler(nsGkAtoms::onmessage, aCallback);
}
-nsCString ToCString(MediaKeySessionType aType) {
- return nsCString(MediaKeySessionTypeValues::GetString(aType));
-}
-
nsString ToString(MediaKeySessionType aType) {
- return NS_ConvertUTF8toUTF16(ToCString(aType));
+ return NS_ConvertUTF8toUTF16(GetEnumString(aType));
}
} // namespace mozilla::dom
diff --git a/dom/media/eme/MediaKeySession.h b/dom/media/eme/MediaKeySession.h
index e19488c311..7204f99eef 100644
--- a/dom/media/eme/MediaKeySession.h
+++ b/dom/media/eme/MediaKeySession.h
@@ -36,8 +36,6 @@ class ArrayBufferViewOrArrayBuffer;
class MediaKeyError;
class MediaKeyStatusMap;
-nsCString ToCString(MediaKeySessionType aType);
-
nsString ToString(MediaKeySessionType aType);
class MediaKeySession final : public DOMEventTargetHelper,
@@ -49,7 +47,7 @@ class MediaKeySession final : public DOMEventTargetHelper,
public:
MediaKeySession(nsPIDOMWindowInner* aParent, MediaKeys* aKeys,
const nsAString& aKeySystem, MediaKeySessionType aSessionType,
- ErrorResult& aRv);
+ bool aHardwareDecryption, ErrorResult& aRv);
void SetSessionId(const nsAString& aSessionId);
@@ -134,6 +132,9 @@ class MediaKeySession final : public DOMEventTargetHelper,
bool mUninitialized;
RefPtr<MediaKeyStatusMap> mKeyStatusMap;
double mExpiration;
+
+ // True if this key session is related with hardware decryption.
+ bool mHardwareDecryption;
};
} // namespace dom
diff --git a/dom/media/eme/MediaKeySystemAccess.cpp b/dom/media/eme/MediaKeySystemAccess.cpp
index b58ff76424..d498c2a773 100644
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -214,6 +214,9 @@ static KeySystemConfig::EMECodecString ToEMEAPICodecString(
if (IsH264CodecString(aCodec)) {
return KeySystemConfig::EME_CODEC_H264;
}
+ if (IsAV1CodecString(aCodec)) {
+ return KeySystemConfig::EME_CODEC_AV1;
+ }
if (IsVP8CodecString(aCodec)) {
return KeySystemConfig::EME_CODEC_VP8;
}
@@ -228,31 +231,53 @@ static KeySystemConfig::EMECodecString ToEMEAPICodecString(
return ""_ns;
}
-static nsTArray<KeySystemConfig> GetSupportedKeySystems() {
+static nsTArray<KeySystemConfig> GetSupportedKeySystems(
+ const nsAString& aKeySystem, bool aIsHardwareDecryption) {
+ using DecryptionInfo = KeySystemConfig::DecryptionInfo;
nsTArray<KeySystemConfig> keySystemConfigs;
-
- const nsTArray<nsString> keySystemNames{
- NS_ConvertUTF8toUTF16(kClearKeyKeySystemName),
- NS_ConvertUTF8toUTF16(kWidevineKeySystemName),
+ if (IsWidevineKeySystem(aKeySystem) || IsClearkeyKeySystem(aKeySystem)) {
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ aKeySystem, DecryptionInfo::Software, keySystemConfigs);
+ }
#ifdef MOZ_WMF_CDM
- NS_ConvertUTF8toUTF16(kPlayReadyKeySystemName),
- NS_ConvertUTF8toUTF16(kPlayReadyKeySystemHardware),
- NS_ConvertUTF8toUTF16(kPlayReadyHardwareClearLeadKeySystemName),
- NS_ConvertUTF8toUTF16(kWidevineExperimentKeySystemName),
- NS_ConvertUTF8toUTF16(kWidevineExperiment2KeySystemName),
-#endif
- };
- for (const auto& name : keySystemNames) {
- Unused << KeySystemConfig::CreateKeySystemConfigs(name, keySystemConfigs);
+ if (IsPlayReadyKeySystem(aKeySystem)) {
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ NS_ConvertUTF8toUTF16(kPlayReadyKeySystemName),
+ DecryptionInfo::Software, keySystemConfigs);
+ if (aIsHardwareDecryption) {
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ NS_ConvertUTF8toUTF16(kPlayReadyKeySystemName),
+ DecryptionInfo::Hardware, keySystemConfigs);
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ NS_ConvertUTF8toUTF16(kPlayReadyKeySystemHardware),
+ DecryptionInfo::Hardware, keySystemConfigs);
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ NS_ConvertUTF8toUTF16(kPlayReadyHardwareClearLeadKeySystemName),
+ DecryptionInfo::Hardware, keySystemConfigs);
+ }
+ }
+ // If key system is kWidevineKeySystemName but with hardware decryption
+ // requirement, then we need to check those experiement key systems which are
+ // used for hardware decryption.
+ if (IsWidevineExperimentKeySystem(aKeySystem) ||
+ (IsWidevineKeySystem(aKeySystem) && aIsHardwareDecryption)) {
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ NS_ConvertUTF8toUTF16(kWidevineExperimentKeySystemName),
+ DecryptionInfo::Hardware, keySystemConfigs);
+ Unused << KeySystemConfig::CreateKeySystemConfigs(
+ NS_ConvertUTF8toUTF16(kWidevineExperiment2KeySystemName),
+ DecryptionInfo::Hardware, keySystemConfigs);
}
+#endif
return keySystemConfigs;
}
static bool GetKeySystemConfigs(
- const nsAString& aKeySystem,
+ const nsAString& aKeySystem, bool aIsHardwareDecryption,
nsTArray<KeySystemConfig>& aOutKeySystemConfig) {
bool foundConfigs = false;
- for (auto& config : GetSupportedKeySystems()) {
+ for (auto& config :
+ GetSupportedKeySystems(aKeySystem, aIsHardwareDecryption)) {
if (config.IsSameKeySystem(aKeySystem)) {
aOutKeySystemConfig.AppendElement(std::move(config));
foundConfigs = true;
@@ -263,9 +288,10 @@ static bool GetKeySystemConfigs(
/* static */
bool MediaKeySystemAccess::KeySystemSupportsInitDataType(
- const nsAString& aKeySystem, const nsAString& aInitDataType) {
+ const nsAString& aKeySystem, const nsAString& aInitDataType,
+ bool aIsHardwareDecryption) {
nsTArray<KeySystemConfig> implementations;
- GetKeySystemConfigs(aKeySystem, implementations);
+ GetKeySystemConfigs(aKeySystem, aIsHardwareDecryption, implementations);
bool containInitType = false;
for (const auto& config : implementations) {
if (config.mInitDataTypes.Contains(aInitDataType)) {
@@ -352,15 +378,13 @@ static bool SupportsEncryptionScheme(
static bool ToSessionType(const nsAString& aSessionType,
MediaKeySessionType& aOutType) {
- if (aSessionType.Equals(ToString(MediaKeySessionType::Temporary))) {
- aOutType = MediaKeySessionType::Temporary;
- return true;
- }
- if (aSessionType.Equals(ToString(MediaKeySessionType::Persistent_license))) {
- aOutType = MediaKeySessionType::Persistent_license;
- return true;
+ Maybe<MediaKeySessionType> type =
+ StringToEnum<MediaKeySessionType>(aSessionType);
+ if (type.isNothing()) {
+ return false;
}
- return false;
+ aOutType = type.value();
+ return true;
}
// 5.1.1 Is persistent session type?
@@ -395,6 +419,7 @@ static CodecType GetCodecType(const KeySystemConfig::EMECodecString& aCodec) {
return Audio;
}
if (aCodec.Equals(KeySystemConfig::EME_CODEC_H264) ||
+ aCodec.Equals(KeySystemConfig::EME_CODEC_AV1) ||
aCodec.Equals(KeySystemConfig::EME_CODEC_VP8) ||
aCodec.Equals(KeySystemConfig::EME_CODEC_VP9) ||
aCodec.Equals(KeySystemConfig::EME_CODEC_HEVC)) {
@@ -1040,7 +1065,11 @@ bool MediaKeySystemAccess::GetSupportedConfig(
DecoderDoctorDiagnostics* aDiagnostics, bool aIsPrivateBrowsing,
const std::function<void(const char*)>& aDeprecationLogFn) {
nsTArray<KeySystemConfig> implementations;
- if (!GetKeySystemConfigs(aKeySystem, implementations)) {
+ const bool isHardwareDecryptionRequest =
+ CheckIfHarewareDRMConfigExists(aConfigs) ||
+ DoesKeySystemSupportHardwareDecryption(aKeySystem);
+ if (!GetKeySystemConfigs(aKeySystem, isHardwareDecryptionRequest,
+ implementations)) {
return false;
}
for (const auto& implementation : implementations) {
@@ -1082,7 +1111,7 @@ static nsCString ToCString(const nsString& aString) {
static nsCString ToCString(const MediaKeysRequirement aValue) {
nsCString str("'");
- str.AppendASCII(MediaKeysRequirementValues::GetString(aValue));
+ str.AppendASCII(GetEnumString(aValue));
str.AppendLiteral("'");
return str;
}
diff --git a/dom/media/eme/MediaKeySystemAccess.h b/dom/media/eme/MediaKeySystemAccess.h
index 954ff7adf3..18eec47008 100644
--- a/dom/media/eme/MediaKeySystemAccess.h
+++ b/dom/media/eme/MediaKeySystemAccess.h
@@ -67,7 +67,8 @@ class MediaKeySystemAccess final : public nsISupports, public nsWrapperCache {
const std::function<void(const char*)>& aDeprecationLogFn);
static bool KeySystemSupportsInitDataType(const nsAString& aKeySystem,
- const nsAString& aInitDataType);
+ const nsAString& aInitDataType,
+ bool aIsHardwareDecryption);
static nsCString ToCString(
const Sequence<MediaKeySystemConfiguration>& aConfig);
diff --git a/dom/media/eme/MediaKeySystemAccessManager.cpp b/dom/media/eme/MediaKeySystemAccessManager.cpp
index 2bc12d57d7..8ebe7ceee7 100644
--- a/dom/media/eme/MediaKeySystemAccessManager.cpp
+++ b/dom/media/eme/MediaKeySystemAccessManager.cpp
@@ -412,8 +412,7 @@ void MediaKeySystemAccessManager::RequestMediaKeySystemAccess(
"MediaKeySystemAccess::GetKeySystemStatus(%s) "
"result=%s msg='%s'",
NS_ConvertUTF16toUTF8(aRequest->mKeySystem).get(),
- nsCString(MediaKeySystemStatusValues::GetString(status)).get(),
- message.get());
+ GetEnumString(status).get(), message.get());
LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));
EME_LOG("%s", msg.get());
diff --git a/dom/media/eme/MediaKeys.cpp b/dom/media/eme/MediaKeys.cpp
index c4340885a3..9a3f4bba7a 100644
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -23,7 +23,6 @@
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/WindowContext.h"
#include "mozilla/dom/WindowGlobalChild.h"
-#include "nsContentCID.h"
#include "nsContentTypeParser.h"
#include "nsContentUtils.h"
#include "nsIScriptObjectPrincipal.h"
@@ -429,7 +428,8 @@ class MediaKeysGMPCrashHelper : public GMPCrashHelper {
already_AddRefed<CDMProxy> MediaKeys::CreateCDMProxy() {
const bool isHardwareDecryptionSupported =
- IsHardwareDecryptionSupported(mConfig);
+ IsHardwareDecryptionSupported(mConfig) ||
+ DoesKeySystemSupportHardwareDecryption(mKeySystem);
EME_LOG("MediaKeys[%p]::CreateCDMProxy(), isHardwareDecryptionSupported=%d",
this, isHardwareDecryptionSupported);
RefPtr<CDMProxy> proxy;
@@ -662,8 +662,12 @@ already_AddRefed<MediaKeySession> MediaKeys::CreateSession(
EME_LOG("MediaKeys[%p] Creating session", this);
- RefPtr<MediaKeySession> session = new MediaKeySession(
- GetParentObject(), this, mKeySystem, aSessionType, aRv);
+ const bool isHardwareDecryption =
+ IsHardwareDecryptionSupported(mConfig) ||
+ DoesKeySystemSupportHardwareDecryption(mKeySystem);
+ RefPtr<MediaKeySession> session =
+ new MediaKeySession(GetParentObject(), this, mKeySystem, aSessionType,
+ isHardwareDecryption, aRv);
if (aRv.Failed()) {
return nullptr;
@@ -792,8 +796,7 @@ void MediaKeys::GetSessionsInfo(nsString& sessionsInfo) {
sessionsInfo.AppendLiteral("(kid=");
sessionsInfo.Append(keyID);
sessionsInfo.AppendLiteral(" status=");
- sessionsInfo.AppendASCII(
- MediaKeyStatusValues::GetString(keyStatusMap->GetValueAtIndex(i)));
+ sessionsInfo.AppendASCII(GetEnumString(keyStatusMap->GetValueAtIndex(i)));
sessionsInfo.AppendLiteral(")");
}
sessionsInfo.AppendLiteral(")");
@@ -824,7 +827,7 @@ already_AddRefed<Promise> MediaKeys::GetStatusForPolicy(
}
EME_LOG("GetStatusForPolicy minHdcpVersion = %s.",
- HDCPVersionValues::GetString(aPolicy.mMinHdcpVersion.Value()).data());
+ GetEnumString(aPolicy.mMinHdcpVersion.Value()).get());
mProxy->GetStatusForPolicy(StorePromise(promise),
aPolicy.mMinHdcpVersion.Value());
return promise.forget();
diff --git a/dom/media/eme/mediadrm/MediaDrmCDMCallbackProxy.cpp b/dom/media/eme/mediadrm/MediaDrmCDMCallbackProxy.cpp
index e5431f50fd..f3cfb6c026 100644
--- a/dom/media/eme/mediadrm/MediaDrmCDMCallbackProxy.cpp
+++ b/dom/media/eme/mediadrm/MediaDrmCDMCallbackProxy.cpp
@@ -9,7 +9,6 @@
#include "nsString.h"
#include "mozilla/dom/MediaKeys.h"
#include "mozilla/dom/MediaKeySession.h"
-#include "nsContentCID.h"
#include "nsServiceManagerUtils.h"
#include "MainThreadUtils.h"
#include "mozilla/EMEUtils.h"
diff --git a/dom/media/eme/mediafoundation/WMFCDMImpl.cpp b/dom/media/eme/mediafoundation/WMFCDMImpl.cpp
index 1fe42aa8e2..add978f755 100644
--- a/dom/media/eme/mediafoundation/WMFCDMImpl.cpp
+++ b/dom/media/eme/mediafoundation/WMFCDMImpl.cpp
@@ -15,37 +15,8 @@
namespace mozilla {
-/* static */
-bool WMFCDMImpl::Supports(const nsAString& aKeySystem) {
- MOZ_ASSERT(NS_IsMainThread());
- if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
- return false;
- }
-
- static std::map<nsString, bool> sSupports;
- static bool sSetRunOnShutdown = false;
- if (!sSetRunOnShutdown) {
- GetMainThreadSerialEventTarget()->Dispatch(
- NS_NewRunnableFunction("WMFCDMImpl::Supports", [&] {
- RunOnShutdown([&] { sSupports.clear(); },
- ShutdownPhase::XPCOMShutdown);
- }));
- sSetRunOnShutdown = true;
- }
-
- nsString key(aKeySystem);
- if (const auto& s = sSupports.find(key); s != sSupports.end()) {
- return s->second;
- }
-
- RefPtr<WMFCDMImpl> cdm = MakeRefPtr<WMFCDMImpl>(aKeySystem);
- nsTArray<KeySystemConfig> configs;
- bool s = cdm->GetCapabilities(configs);
- sSupports[key] = s;
- return s;
-}
-
-bool WMFCDMImpl::GetCapabilities(nsTArray<KeySystemConfig>& aOutConfigs) {
+bool WMFCDMImpl::GetCapabilities(bool aIsHardwareDecryption,
+ nsTArray<KeySystemConfig>& aOutConfigs) {
MOZ_ASSERT(NS_IsMainThread());
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
return false;
@@ -67,13 +38,14 @@ bool WMFCDMImpl::GetCapabilities(nsTArray<KeySystemConfig>& aOutConfigs) {
auto keySystem = std::string{NS_ConvertUTF16toUTF8(mKeySystem).get()};
if (auto rv = sKeySystemConfigs.find(keySystem);
rv != sKeySystemConfigs.end()) {
- EME_LOG("Return cached capabilities for %s", keySystem.c_str());
for (const auto& config : rv->second) {
- aOutConfigs.AppendElement(config);
- EME_LOG("-- capabilities (%s)",
- NS_ConvertUTF16toUTF8(config.GetDebugInfo()).get());
+ 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;
+ }
}
- return true;
}
// Not cached result, ask the remote process.
@@ -83,42 +55,33 @@ bool WMFCDMImpl::GetCapabilities(nsTArray<KeySystemConfig>& aOutConfigs) {
mCDM = MakeRefPtr<MFCDMChild>(mKeySystem);
}
bool ok = false;
- static const bool sIsHwSecure[2] = {false, true};
- for (const auto& isHWSecure : sIsHwSecure) {
- media::Await(
- do_AddRef(backgroundTaskQueue), mCDM->GetCapabilities(isHWSecure),
- [&ok, &aOutConfigs, keySystem,
- isHWSecure](const MFCDMCapabilitiesIPDL& capabilities) {
- EME_LOG("capabilities: keySystem=%s (hw-secure=%d)",
- keySystem.c_str(), isHWSecure);
- 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);
- // This is equal to "com.microsoft.playready.recommendation.3000", so
- // we can store it directly without asking the remote process again.
- if (keySystem.compare(kPlayReadyKeySystemName) == 0 && isHWSecure) {
- config->mKeySystem.AssignLiteral(kPlayReadyKeySystemHardware);
- sKeySystemConfigs["com.microsoft.playready.recommendation.3000"]
- .AppendElement(*config);
- }
- ok = true;
- },
- [](nsresult rv) {
- EME_LOG("Fail to get key system capabilities. rv=%x", uint32_t(rv));
- });
- }
+ 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;
}
diff --git a/dom/media/eme/mediafoundation/WMFCDMImpl.h b/dom/media/eme/mediafoundation/WMFCDMImpl.h
index 452629ec84..b7e6308848 100644
--- a/dom/media/eme/mediafoundation/WMFCDMImpl.h
+++ b/dom/media/eme/mediafoundation/WMFCDMImpl.h
@@ -34,9 +34,9 @@ class WMFCDMImpl final {
explicit WMFCDMImpl(const nsAString& aKeySystem) : mKeySystem(aKeySystem) {}
- static bool Supports(const nsAString& aKeySystem);
// TODO: make this async?
- bool GetCapabilities(nsTArray<KeySystemConfig>& aOutConfigs);
+ bool GetCapabilities(bool aIsHardwareDecryption,
+ nsTArray<KeySystemConfig>& aOutConfigs);
using InitPromise = GenericPromise;
struct InitParams {
diff --git a/dom/media/eme/mediafoundation/WMFCDMProxy.cpp b/dom/media/eme/mediafoundation/WMFCDMProxy.cpp
index 21207ecc22..f7e05dfb6a 100644
--- a/dom/media/eme/mediafoundation/WMFCDMProxy.cpp
+++ b/dom/media/eme/mediafoundation/WMFCDMProxy.cpp
@@ -381,8 +381,7 @@ void WMFCDMProxy::GetStatusForPolicy(PromiseId aPromiseId,
RETURN_IF_SHUTDOWN();
EME_LOG("WMFCDMProxy::GetStatusForPolicy(this=%p, pid=%" PRIu32
", minHDCP=%s)",
- this, aPromiseId,
- dom::HDCPVersionValues::GetString(aMinHdcpVersion).data());
+ this, aPromiseId, dom::GetEnumString(aMinHdcpVersion).get());
mCDM->GetStatusForPolicy(aPromiseId, aMinHdcpVersion)
->Then(
mMainThread, __func__,