eme_constants.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_BASE_EME_CONSTANTS_H_
  5. #define MEDIA_BASE_EME_CONSTANTS_H_
  6. #include <stdint.h>
  7. #include "media/base/media_export.h"
  8. #include "media/media_buildflags.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace media {
  11. // Defines values that specify registered Initialization Data Types used
  12. // in Encrypted Media Extensions (EME).
  13. // http://w3c.github.io/encrypted-media/initdata-format-registry.html#registry
  14. enum class EmeInitDataType { UNKNOWN, WEBM, CENC, KEYIDS, MAX = KEYIDS };
  15. // Defines bitmask values that specify codecs used in Encrypted Media Extensions
  16. // (EME). Generally codec profiles are not specified and it is assumed that the
  17. // profile support for encrypted playback is the same as for clear playback.
  18. // For VP9 we have older CDMs only supporting profile 0, while new CDMs could
  19. // support profile 2. Profile 1 and 3 are not supported by EME, see
  20. // https://crbug.com/898298.
  21. enum EmeCodec : uint32_t {
  22. EME_CODEC_NONE = 0,
  23. EME_CODEC_OPUS = 1 << 0,
  24. EME_CODEC_VORBIS = 1 << 1,
  25. EME_CODEC_VP8 = 1 << 2,
  26. EME_CODEC_VP9_PROFILE0 = 1 << 3,
  27. EME_CODEC_AAC = 1 << 4,
  28. EME_CODEC_AVC1 = 1 << 5,
  29. EME_CODEC_VP9_PROFILE2 = 1 << 6, // VP9 profiles 2
  30. EME_CODEC_HEVC_PROFILE_MAIN = 1 << 7,
  31. EME_CODEC_DOLBY_VISION_PROFILE0 = 1 << 8,
  32. EME_CODEC_DOLBY_VISION_PROFILE4 = 1 << 9,
  33. EME_CODEC_DOLBY_VISION_PROFILE5 = 1 << 10,
  34. EME_CODEC_DOLBY_VISION_PROFILE7 = 1 << 11,
  35. EME_CODEC_DOLBY_VISION_PROFILE8 = 1 << 12,
  36. EME_CODEC_DOLBY_VISION_PROFILE9 = 1 << 13,
  37. EME_CODEC_AC3 = 1 << 14,
  38. EME_CODEC_EAC3 = 1 << 15,
  39. EME_CODEC_MPEG_H_AUDIO = 1 << 16,
  40. EME_CODEC_FLAC = 1 << 17,
  41. EME_CODEC_AV1 = 1 << 18,
  42. EME_CODEC_HEVC_PROFILE_MAIN10 = 1 << 19,
  43. EME_CODEC_DTS = 1 << 20,
  44. EME_CODEC_DTSXP2 = 1 << 21,
  45. };
  46. // *_ALL values should only be used for masking, do not use them to specify
  47. // codec support because they may be extended to include more codecs.
  48. using SupportedCodecs = uint32_t;
  49. // Dolby Vision profile 0 and 9 are based on AVC while profile 4, 5, 7 and 8 are
  50. // based on HEVC.
  51. constexpr SupportedCodecs EME_CODEC_DOLBY_VISION_AVC =
  52. EME_CODEC_DOLBY_VISION_PROFILE0 | EME_CODEC_DOLBY_VISION_PROFILE9;
  53. constexpr SupportedCodecs EME_CODEC_DOLBY_VISION_HEVC =
  54. EME_CODEC_DOLBY_VISION_PROFILE4 | EME_CODEC_DOLBY_VISION_PROFILE5 |
  55. EME_CODEC_DOLBY_VISION_PROFILE7 | EME_CODEC_DOLBY_VISION_PROFILE8;
  56. namespace {
  57. constexpr SupportedCodecs GetMp4AudioCodecs() {
  58. SupportedCodecs codecs = EME_CODEC_OPUS | EME_CODEC_FLAC;
  59. #if BUILDFLAG(USE_PROPRIETARY_CODECS)
  60. codecs |= EME_CODEC_AAC;
  61. #if BUILDFLAG(ENABLE_PLATFORM_AC3_EAC3_AUDIO)
  62. codecs |= EME_CODEC_AC3 | EME_CODEC_EAC3;
  63. #endif // BUILDFLAG(ENABLE_PLATFORM_AC3_EAC3_AUDIO)
  64. #if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
  65. codecs |= EME_CODEC_DTS | EME_CODEC_DTSXP2;
  66. #endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
  67. #if BUILDFLAG(ENABLE_PLATFORM_MPEG_H_AUDIO)
  68. codecs |= EME_CODEC_MPEG_H_AUDIO;
  69. #endif // BUILDFLAG(ENABLE_PLATFORM_MPEG_H_AUDIO)
  70. #endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
  71. return codecs;
  72. }
  73. constexpr SupportedCodecs GetMp4VideoCodecs() {
  74. // VP9 codec can be in MP4. Legacy VP9 codec strings ("vp9" and "vp9.0") can
  75. // not be in "video/mp4" mime type, but that is enforced by media::MimeUtil.
  76. SupportedCodecs codecs = EME_CODEC_VP9_PROFILE0 | EME_CODEC_VP9_PROFILE2;
  77. codecs |= EME_CODEC_AV1;
  78. #if BUILDFLAG(USE_PROPRIETARY_CODECS)
  79. codecs |= EME_CODEC_AVC1;
  80. #if BUILDFLAG(ENABLE_PLATFORM_HEVC)
  81. codecs |= EME_CODEC_HEVC_PROFILE_MAIN;
  82. codecs |= EME_CODEC_HEVC_PROFILE_MAIN10;
  83. #endif // BUILDFLAG(ENABLE_PLATFORM_HEVC)
  84. #if BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
  85. codecs |= EME_CODEC_DOLBY_VISION_AVC;
  86. #if BUILDFLAG(ENABLE_PLATFORM_HEVC)
  87. codecs |= EME_CODEC_DOLBY_VISION_HEVC;
  88. #endif // BUILDFLAG(ENABLE_PLATFORM_HEVC)
  89. #endif // BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
  90. #endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
  91. return codecs;
  92. }
  93. } // namespace
  94. constexpr SupportedCodecs EME_CODEC_WEBM_AUDIO_ALL =
  95. EME_CODEC_OPUS | EME_CODEC_VORBIS;
  96. constexpr SupportedCodecs EME_CODEC_WEBM_VIDEO_ALL =
  97. EME_CODEC_VP8 | EME_CODEC_VP9_PROFILE0 | EME_CODEC_VP9_PROFILE2 |
  98. EME_CODEC_AV1;
  99. constexpr SupportedCodecs EME_CODEC_WEBM_ALL =
  100. EME_CODEC_WEBM_AUDIO_ALL | EME_CODEC_WEBM_VIDEO_ALL;
  101. constexpr SupportedCodecs EME_CODEC_MP4_AUDIO_ALL = GetMp4AudioCodecs();
  102. constexpr SupportedCodecs EME_CODEC_MP4_VIDEO_ALL = GetMp4VideoCodecs();
  103. constexpr SupportedCodecs EME_CODEC_MP4_ALL =
  104. EME_CODEC_MP4_AUDIO_ALL | EME_CODEC_MP4_VIDEO_ALL;
  105. constexpr SupportedCodecs EME_CODEC_AUDIO_ALL =
  106. EME_CODEC_WEBM_AUDIO_ALL | EME_CODEC_MP4_AUDIO_ALL;
  107. constexpr SupportedCodecs EME_CODEC_VIDEO_ALL =
  108. EME_CODEC_WEBM_VIDEO_ALL | EME_CODEC_MP4_VIDEO_ALL;
  109. constexpr SupportedCodecs EME_CODEC_ALL =
  110. EME_CODEC_WEBM_ALL | EME_CODEC_MP4_ALL;
  111. #if BUILDFLAG(USE_PROPRIETARY_CODECS)
  112. #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
  113. constexpr SupportedCodecs EME_CODEC_MP2T_VIDEO_ALL = EME_CODEC_AVC1;
  114. static_assert(
  115. (EME_CODEC_MP2T_VIDEO_ALL & EME_CODEC_VIDEO_ALL) ==
  116. EME_CODEC_MP2T_VIDEO_ALL,
  117. "EME_CODEC_MP2T_VIDEO_ALL should be a subset of EME_CODEC_MP4_ALL");
  118. #endif // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
  119. #endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
  120. // Used to declare support for distinctive identifier and persistent state.
  121. // These are purposefully limited to not allow one to require the other, so that
  122. // transitive requirements are not possible. Non-trivial refactoring would be
  123. // required to support transitive requirements.
  124. enum class EmeFeatureSupport {
  125. // Invalid default value.
  126. INVALID,
  127. // Access to the feature is not supported at all.
  128. NOT_SUPPORTED,
  129. // Access to the feature may be requested.
  130. REQUESTABLE,
  131. // Access to the feature cannot be blocked.
  132. ALWAYS_ENABLED,
  133. };
  134. enum class EmeMediaType {
  135. AUDIO,
  136. VIDEO,
  137. };
  138. enum class EmeConfigRuleState {
  139. // To correctly identify the EmeConfig as Supported, we use the enum value
  140. // kUnset for each of the rules so that it is easy to check for, and cannot be
  141. // confused.
  142. kUnset,
  143. // Not Allowed represents when the rule in the collection of EmeConfigRules is
  144. // not allowed by the current system.
  145. kNotAllowed,
  146. // Recommended represents when the rule in the collection of EmeConfigRules is
  147. // recommended by the current system. In our design, the recommended takes a
  148. // second priority and cannot override the NotAllowed or Required value.
  149. kRecommended,
  150. // Required represents when the rule in the collection of EmeConfigRules is
  151. // required by the current system.
  152. kRequired,
  153. };
  154. struct MEDIA_EXPORT EmeConfig {
  155. using Rule = absl::optional<EmeConfig>;
  156. // Refer to the EME spec for definitions on what identifier, persistence, and
  157. // hw_secure_codecs represent.
  158. EmeConfigRuleState identifier = EmeConfigRuleState::kUnset;
  159. EmeConfigRuleState persistence = EmeConfigRuleState::kUnset;
  160. EmeConfigRuleState hw_secure_codecs = EmeConfigRuleState::kUnset;
  161. // To represent an EmeConfig::Rule where the feature is supported without any
  162. // special requirements. This type adds nothing during the AddRule() function.
  163. // Internally, we represent Supported as all the States set to kUnset.
  164. static EmeConfig::Rule SupportedRule() { return EmeConfig(); }
  165. // To represent an EmeConfig::Rule where the feature is not supported.
  166. // Internally, we represent Unsupported as absl::nullopt.
  167. static EmeConfig::Rule UnsupportedRule() { return absl::nullopt; }
  168. };
  169. inline bool operator==(EmeConfig const& lhs, EmeConfig const& rhs) {
  170. return lhs.persistence == rhs.persistence &&
  171. lhs.identifier == rhs.identifier &&
  172. lhs.hw_secure_codecs == rhs.hw_secure_codecs;
  173. }
  174. } // namespace media
  175. #endif // MEDIA_BASE_EME_CONSTANTS_H_