Backed out changeset be38251ea56b (bug 1888540) for causing failures on test_TopSites...
[gecko.git] / media / wmf-clearkey / WMFClearKeyCDMFactory.cpp
blob6ec253850d22d3836a48e8e4898cc12c29331e36
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "WMFClearKeyCDMFactory.h"
7 #include <string>
9 #include <Mferror.h>
11 #include "WMFClearKeyCDMAccess.h"
12 #include "WMFClearKeyUtils.h"
14 namespace mozilla {
16 using Microsoft::WRL::MakeAndInitialize;
18 ActivatableClass(WMFClearKeyCDMFactory);
20 bool isRequiringHDCP22OrAbove(LPCWSTR aType) {
21 if (aType == nullptr || *aType == L'\0') {
22 return false;
25 // The HDCP value follows the feature value in
26 // https://docs.microsoft.com/en-us/uwp/api/windows.media.protection.protectioncapabilities.istypesupported?view=winrt-19041
27 // - 1 (on without HDCP 2.2 Type 1 restriction)
28 // - 2 (on with HDCP 2.2 Type 1 restriction)
29 std::wstring wstr(aType);
30 std::string hdcpStr(wstr.begin(), wstr.end());
31 return wstr.find(L"hdcp=2") != std::string::npos;
34 STDMETHODIMP_(BOOL)
35 WMFClearKeyCDMFactory::IsTypeSupported(_In_ LPCWSTR aKeySystem,
36 _In_opt_ LPCWSTR aContentType) {
37 // For testing, return support for most of cases. Only returns false for some
38 // special cases.
40 bool needHDCP22OrAbove = isRequiringHDCP22OrAbove(aContentType);
41 ENTRY_LOG_ARGS("Need-HDCP2.2+=%d", needHDCP22OrAbove);
43 // As the API design of the Media Foundation, we can only know whether the
44 // requester is asking for HDCP 2.2+ or not, we can't know the exact HDCP
45 // version which is used in getStatusPolicy web api. Therefore, we pretend
46 // ourselves only having HDCP 2.1 compliant.
47 if (needHDCP22OrAbove) {
48 return false;
50 return true;
53 STDMETHODIMP
54 WMFClearKeyCDMFactory::CreateContentDecryptionModuleAccess(
55 LPCWSTR aKeySystem, IPropertyStore** aConfigurations,
56 DWORD aNumConfigurations, IMFContentDecryptionModuleAccess** aCdmAccess) {
57 ENTRY_LOG();
58 if (aKeySystem == nullptr || aKeySystem[0] == L'\0') {
59 ENTRY_LOG_ARGS("Key system is null or empty");
60 return MF_TYPE_ERR;
63 if (aNumConfigurations == 0) {
64 ENTRY_LOG_ARGS("No available configration");
65 return MF_TYPE_ERR;
68 if (!IsTypeSupported(aKeySystem, nullptr)) {
69 ENTRY_LOG_ARGS("Not supported type");
70 return MF_NOT_SUPPORTED_ERR;
73 RETURN_IF_FAILED((
74 MakeAndInitialize<WMFClearKeyCDMAccess, IMFContentDecryptionModuleAccess>(
75 aCdmAccess)));
76 ENTRY_LOG_ARGS("Created CDM access!");
77 return S_OK;
80 #undef LOG
82 } // namespace mozilla