EMEUtils.h (3513B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef EME_LOG_H_ 8 #define EME_LOG_H_ 9 10 #include "mozilla/Logging.h" 11 #include "mozilla/dom/BufferSourceBindingFwd.h" 12 #include "mozilla/dom/MediaKeyStatusMapBinding.h" 13 #include "mozilla/dom/MediaKeySystemAccessBinding.h" 14 #include "nsString.h" 15 #include "nsTArray.h" 16 17 namespace mozilla { 18 19 enum class CryptoScheme : uint8_t; 20 #ifdef MOZ_WMF_CDM 21 class MFCDMCapabilitiesIPDL; 22 #endif 23 struct KeySystemConfig; 24 25 namespace dom { 26 class Document; 27 } // namespace dom 28 29 #ifndef EME_LOG 30 LogModule* GetEMELog(); 31 # define EME_LOG(...) \ 32 MOZ_LOG(GetEMELog(), mozilla::LogLevel::Debug, (__VA_ARGS__)) 33 # define EME_LOG_ENABLED() MOZ_LOG_TEST(GetEMELog(), mozilla::LogLevel::Debug) 34 #endif 35 36 #ifndef EME_VERBOSE_LOG 37 LogModule* GetEMEVerboseLog(); 38 # define EME_VERBOSE_LOG(...) \ 39 MOZ_LOG(GetEMEVerboseLog(), mozilla::LogLevel::Debug, (__VA_ARGS__)) 40 #else 41 # ifndef EME_LOG 42 # define EME_LOG(...) 43 # endif 44 45 # ifndef EME_VERBOSE_LOG 46 # define EME_VERBOSE_LOG(...) 47 # endif 48 #endif 49 50 // Helper function to extract a copy of data coming in from JS in an 51 // (ArrayBuffer or ArrayBufferView) IDL typed function argument. 52 // 53 // Only call this on a properly initialized ArrayBufferViewOrArrayBuffer. 54 void CopyArrayBufferViewOrArrayBufferData( 55 const dom::BufferSource& aBufferOrView, nsTArray<uint8_t>& aOutData); 56 57 nsString KeySystemToProxyName(const nsAString& aKeySystem); 58 59 bool IsClearkeyKeySystem(const nsAString& aKeySystem); 60 61 bool IsWidevineKeySystem(const nsAString& aKeySystem); 62 63 #ifdef MOZ_WMF_CDM 64 bool IsMediaFoundationCDMPlaybackEnabled(); 65 66 bool IsPlayReadyEnabled(); 67 68 bool IsPlayReadyKeySystemAndSupported(const nsAString& aKeySystem); 69 70 bool IsWidevineHardwareDecryptionEnabled(); 71 72 bool IsWidevineExperimentKeySystemAndSupported(const nsAString& aKeySystem); 73 74 bool IsWMFClearKeySystemAndSupported(const nsAString& aKeySystem); 75 #endif 76 77 // Note: Primetime is now unsupported, but we leave it in the enum so 78 // that the telemetry enum values are not changed; doing so would break 79 // existing telemetry probes. 80 enum CDMType { 81 eClearKey = 0, 82 ePrimetime = 1, // Note: Unsupported. 83 eWidevine = 2, 84 eUnknown = 3 85 }; 86 87 CDMType ToCDMTypeTelemetryEnum(const nsString& aKeySystem); 88 89 const char* ToMediaKeyStatusStr(dom::MediaKeyStatus aStatus); 90 91 // Return true if given config supports hardware decryption (SL3000 or L1). 92 bool IsHardwareDecryptionSupported( 93 const dom::MediaKeySystemConfiguration& aConfig); 94 bool IsHardwareDecryptionSupported(const KeySystemConfig& aConfig); 95 96 #ifdef MOZ_WMF_CDM 97 void MFCDMCapabilitiesIPDLToKeySystemConfig( 98 const MFCDMCapabilitiesIPDL& aCDMConfig, KeySystemConfig& aKeySystemConfig); 99 #endif 100 101 bool DoesKeySystemSupportClearLead(const nsAString& aKeySystem); 102 103 // Return true if there is any config in the given configs has hardware DRM 104 // associated robustness. 105 bool CheckIfHarewareDRMConfigExists( 106 const nsTArray<dom::MediaKeySystemConfiguration>& aConfigs); 107 108 bool DoesKeySystemSupportHardwareDecryption(const nsAString& aKeySystem); 109 110 void DeprecationWarningLog(const dom::Document* aDocument, 111 const char* aMsgName); 112 113 Maybe<nsCString> GetOrigin(const dom::Document* aDocument); 114 115 } // namespace mozilla 116 117 #endif // EME_LOG_H_