tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WMFClearKeyCDMFactory.cpp (2842B)


      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/. */
      4 
      5 #include "WMFClearKeyCDMFactory.h"
      6 
      7 #include <string>
      8 
      9 #include <Mferror.h>
     10 
     11 #include "WMFClearKeyCDMAccess.h"
     12 #include "WMFClearKeyUtils.h"
     13 
     14 namespace mozilla {
     15 
     16 using Microsoft::WRL::MakeAndInitialize;
     17 
     18 ActivatableClass(WMFClearKeyCDMFactory);
     19 
     20 static bool isRequiringHDCP22OrAbove(LPCWSTR aType) {
     21  if (aType == nullptr || *aType == L'\0') {
     22    return false;
     23  }
     24 
     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;
     32 }
     33 
     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.
     39 
     40  bool needHDCP22OrAbove = isRequiringHDCP22OrAbove(aContentType);
     41  ENTRY_LOG_ARGS("Need-HDCP2.2+=%d", needHDCP22OrAbove);
     42 
     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  return !needHDCP22OrAbove;
     48 }
     49 
     50 STDMETHODIMP
     51 WMFClearKeyCDMFactory::CreateContentDecryptionModuleAccess(
     52    LPCWSTR aKeySystem, IPropertyStore** aConfigurations,
     53    DWORD aNumConfigurations, IMFContentDecryptionModuleAccess** aCdmAccess) {
     54  ENTRY_LOG();
     55  if (aKeySystem == nullptr || aKeySystem[0] == L'\0') {
     56    ENTRY_LOG_ARGS("Key system is null or empty");
     57    return MF_TYPE_ERR;
     58  }
     59 
     60  if (aNumConfigurations == 0) {
     61    ENTRY_LOG_ARGS("No available configration");
     62    return MF_TYPE_ERR;
     63  }
     64 
     65  if (!IsTypeSupported(aKeySystem, nullptr)) {
     66    ENTRY_LOG_ARGS("Not supported type");
     67    return MF_NOT_SUPPORTED_ERR;
     68  }
     69 
     70  RETURN_IF_FAILED((
     71      MakeAndInitialize<WMFClearKeyCDMAccess, IMFContentDecryptionModuleAccess>(
     72          aCdmAccess)));
     73  ENTRY_LOG_ARGS("Created CDM access!");
     74  return S_OK;
     75 }
     76 
     77 STDMETHODIMP WMFClearKeyCDMFactory::IsTypeSupportedEx(
     78    BSTR aType, BSTR aKeySystem, MF_MEDIA_ENGINE_CANPLAY* aPAnswer) {
     79  if (!aPAnswer) {
     80    return E_POINTER;
     81  }
     82  *aPAnswer = IsTypeSupported(aKeySystem, aType)
     83                  ? MF_MEDIA_ENGINE_CANPLAY_PROBABLY
     84                  : MF_MEDIA_ENGINE_CANPLAY_NOT_SUPPORTED;
     85  return S_OK;
     86 }
     87 
     88 #undef LOG
     89 
     90 }  // namespace mozilla