OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/crypto/key_systems.h" | 5 #include "content/renderer/media/crypto/key_systems.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
16 #include "content/public/common/eme_constants.h" | |
17 #include "content/public/renderer/content_renderer_client.h" | 16 #include "content/public/renderer/content_renderer_client.h" |
18 #include "content/public/renderer/key_system_info.h" | |
19 #include "content/renderer/media/crypto/key_systems_support_uma.h" | 17 #include "content/renderer/media/crypto/key_systems_support_uma.h" |
| 18 #include "media/base/eme_constants.h" |
| 19 #include "media/base/key_system_info.h" |
20 | 20 |
21 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
22 #include "media/base/android/media_codec_bridge.h" | 22 #include "media/base/android/media_codec_bridge.h" |
23 #endif | 23 #endif |
24 | 24 |
25 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 25 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
| 29 using media::EmeCodec; |
| 30 using media::EmeInitDataType; |
| 31 using media::KeySystemInfo; |
| 32 using media::SupportedInitDataTypes; |
| 33 using media::SupportedCodecs; |
| 34 |
29 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 35 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
30 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 36 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
31 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; | 37 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; |
32 | 38 |
33 struct NamedInitDataType { | 39 struct NamedInitDataType { |
34 const char* name; | 40 const char* name; |
35 EmeInitDataType type; | 41 EmeInitDataType type; |
36 }; | 42 }; |
37 | 43 |
38 // Mapping between initialization data types names and enum values. When adding | 44 // Mapping between initialization data types names and enum values. When adding |
39 // entries, make sure to update IsSaneInitDataTypeWithContainer(). | 45 // entries, make sure to update IsSaneInitDataTypeWithContainer(). |
40 static NamedInitDataType kInitDataTypeNames[] = { | 46 static NamedInitDataType kInitDataTypeNames[] = { |
41 {"webm", EME_INIT_DATA_TYPE_WEBM}, | 47 {"webm", media::EME_INIT_DATA_TYPE_WEBM}, |
42 #if defined(USE_PROPRIETARY_CODECS) | 48 #if defined(USE_PROPRIETARY_CODECS) |
43 {"cenc", EME_INIT_DATA_TYPE_CENC} | 49 {"cenc", media::EME_INIT_DATA_TYPE_CENC} |
44 #endif // defined(USE_PROPRIETARY_CODECS) | 50 #endif // defined(USE_PROPRIETARY_CODECS) |
45 }; | 51 }; |
46 | 52 |
47 struct NamedCodec { | 53 struct NamedCodec { |
48 const char* name; | 54 const char* name; |
49 EmeCodec type; | 55 EmeCodec type; |
50 }; | 56 }; |
51 | 57 |
52 // Mapping between containers and their codecs. | 58 // Mapping between containers and their codecs. |
53 // Only audio codec can belong to a "audio/*" container. Both audio and video | 59 // Only audio codec can belong to a "audio/*" container. Both audio and video |
54 // codecs can belong to a "video/*" container. | 60 // codecs can belong to a "video/*" container. |
55 static NamedCodec kContainerToCodecMasks[] = { | 61 static NamedCodec kContainerToCodecMasks[] = { |
56 {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL}, | 62 {"audio/webm", media::EME_CODEC_WEBM_AUDIO_ALL}, |
57 {"video/webm", EME_CODEC_WEBM_ALL}, | 63 {"video/webm", media::EME_CODEC_WEBM_ALL}, |
58 #if defined(USE_PROPRIETARY_CODECS) | 64 #if defined(USE_PROPRIETARY_CODECS) |
59 {"audio/mp4", EME_CODEC_MP4_AUDIO_ALL}, | 65 {"audio/mp4", media::EME_CODEC_MP4_AUDIO_ALL}, |
60 {"video/mp4", EME_CODEC_MP4_ALL} | 66 {"video/mp4", media::EME_CODEC_MP4_ALL} |
61 #endif // defined(USE_PROPRIETARY_CODECS) | 67 #endif // defined(USE_PROPRIETARY_CODECS) |
62 }; | 68 }; |
63 | 69 |
64 // Mapping between codec names and enum values. | 70 // Mapping between codec names and enum values. |
65 static NamedCodec kCodecStrings[] = { | 71 static NamedCodec kCodecStrings[] = { |
66 {"vorbis", EME_CODEC_WEBM_VORBIS}, | 72 {"vorbis", media::EME_CODEC_WEBM_VORBIS}, |
67 {"vp8", EME_CODEC_WEBM_VP8}, | 73 {"vp8", media::EME_CODEC_WEBM_VP8}, |
68 {"vp8.0", EME_CODEC_WEBM_VP8}, | 74 {"vp8.0", media::EME_CODEC_WEBM_VP8}, |
69 {"vp9", EME_CODEC_WEBM_VP9}, | 75 {"vp9", media::EME_CODEC_WEBM_VP9}, |
70 {"vp9.0", EME_CODEC_WEBM_VP9}, | 76 {"vp9.0", media::EME_CODEC_WEBM_VP9}, |
71 #if defined(USE_PROPRIETARY_CODECS) | 77 #if defined(USE_PROPRIETARY_CODECS) |
72 {"mp4a", EME_CODEC_MP4_AAC}, | 78 {"mp4a", media::EME_CODEC_MP4_AAC}, |
73 {"avc1", EME_CODEC_MP4_AVC1}, | 79 {"avc1", media::EME_CODEC_MP4_AVC1}, |
74 {"avc3", EME_CODEC_MP4_AVC1} | 80 {"avc3", media::EME_CODEC_MP4_AVC1} |
75 #endif // defined(USE_PROPRIETARY_CODECS) | 81 #endif // defined(USE_PROPRIETARY_CODECS) |
76 }; | 82 }; |
77 | 83 |
78 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | 84 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
79 KeySystemInfo info(kClearKeyKeySystem); | 85 KeySystemInfo info(kClearKeyKeySystem); |
80 | 86 |
81 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: | 87 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: |
82 // http://developer.android.com/guide/appendix/media-formats.html | 88 // http://developer.android.com/guide/appendix/media-formats.html |
83 // VP9 support is device dependent. | 89 // VP9 support is device dependent. |
84 | 90 |
85 info.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM; | 91 info.supported_init_data_types = media::EME_INIT_DATA_TYPE_WEBM; |
86 info.supported_codecs = EME_CODEC_WEBM_ALL; | 92 info.supported_codecs = media::EME_CODEC_WEBM_ALL; |
87 | 93 |
88 #if defined(OS_ANDROID) | 94 #if defined(OS_ANDROID) |
89 // Temporarily disable VP9 support for Android. | 95 // Temporarily disable VP9 support for Android. |
90 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. | 96 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. |
91 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; | 97 info.supported_codecs &= ~media::EME_CODEC_WEBM_VP9; |
92 #endif // defined(OS_ANDROID) | 98 #endif // defined(OS_ANDROID) |
93 | 99 |
94 #if defined(USE_PROPRIETARY_CODECS) | 100 #if defined(USE_PROPRIETARY_CODECS) |
95 info.supported_init_data_types |= EME_INIT_DATA_TYPE_CENC; | 101 info.supported_init_data_types |= media::EME_INIT_DATA_TYPE_CENC; |
96 info.supported_codecs |= EME_CODEC_MP4_ALL; | 102 info.supported_codecs |= media::EME_CODEC_MP4_ALL; |
97 #endif // defined(USE_PROPRIETARY_CODECS) | 103 #endif // defined(USE_PROPRIETARY_CODECS) |
98 | 104 |
99 info.use_aes_decryptor = true; | 105 info.use_aes_decryptor = true; |
100 | 106 |
101 concrete_key_systems->push_back(info); | 107 concrete_key_systems->push_back(info); |
102 } | 108 } |
103 | 109 |
104 class KeySystems { | 110 class KeySystems { |
105 public: | 111 public: |
106 static KeySystems& GetInstance(); | 112 static KeySystems& GetInstance(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 const std::string& pepper_type, | 148 const std::string& pepper_type, |
143 #endif | 149 #endif |
144 SupportedInitDataTypes supported_init_data_types, | 150 SupportedInitDataTypes supported_init_data_types, |
145 SupportedCodecs supported_codecs, | 151 SupportedCodecs supported_codecs, |
146 const std::string& parent_key_system); | 152 const std::string& parent_key_system); |
147 | 153 |
148 friend struct base::DefaultLazyInstanceTraits<KeySystems>; | 154 friend struct base::DefaultLazyInstanceTraits<KeySystems>; |
149 | 155 |
150 struct KeySystemProperties { | 156 struct KeySystemProperties { |
151 KeySystemProperties() | 157 KeySystemProperties() |
152 : use_aes_decryptor(false), supported_codecs(EME_CODEC_NONE) {} | 158 : use_aes_decryptor(false), supported_codecs(media::EME_CODEC_NONE) {} |
153 | 159 |
154 bool use_aes_decryptor; | 160 bool use_aes_decryptor; |
155 #if defined(ENABLE_PEPPER_CDMS) | 161 #if defined(ENABLE_PEPPER_CDMS) |
156 std::string pepper_type; | 162 std::string pepper_type; |
157 #endif | 163 #endif |
158 SupportedInitDataTypes supported_init_data_types; | 164 SupportedInitDataTypes supported_init_data_types; |
159 SupportedCodecs supported_codecs; | 165 SupportedCodecs supported_codecs; |
160 }; | 166 }; |
161 | 167 |
162 typedef base::hash_map<std::string, KeySystemProperties> | 168 typedef base::hash_map<std::string, KeySystemProperties> |
163 KeySystemPropertiesMap; | 169 KeySystemPropertiesMap; |
164 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; | 170 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; |
165 typedef base::hash_map<std::string, SupportedCodecs> ContainerCodecsMap; | 171 typedef base::hash_map<std::string, SupportedCodecs> ContainerCodecsMap; |
166 typedef base::hash_map<std::string, EmeCodec> CodecsMap; | 172 typedef base::hash_map<std::string, EmeCodec> CodecsMap; |
167 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; | 173 typedef base::hash_map<std::string, media::EmeInitDataType> InitDataTypesMap; |
168 | 174 |
169 KeySystems(); | 175 KeySystems(); |
170 ~KeySystems() {} | 176 ~KeySystems() {} |
171 | 177 |
172 EmeInitDataType GetInitDataTypeForName( | 178 EmeInitDataType GetInitDataTypeForName( |
173 const std::string& init_data_type) const; | 179 const std::string& init_data_type) const; |
174 // TODO(sandersd): Separate container enum from codec mask value. | 180 // TODO(sandersd): Separate container enum from codec mask value. |
175 // http://crbug.com/417440 | 181 // http://crbug.com/417440 |
176 SupportedCodecs GetCodecMaskForContainer( | 182 SupportedCodecs GetCodecMaskForContainer( |
177 const std::string& container) const; | 183 const std::string& container) const; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); | 254 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); |
249 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 255 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
250 } | 256 } |
251 | 257 |
252 EmeInitDataType KeySystems::GetInitDataTypeForName( | 258 EmeInitDataType KeySystems::GetInitDataTypeForName( |
253 const std::string& init_data_type) const { | 259 const std::string& init_data_type) const { |
254 InitDataTypesMap::const_iterator iter = | 260 InitDataTypesMap::const_iterator iter = |
255 init_data_type_name_map_.find(init_data_type); | 261 init_data_type_name_map_.find(init_data_type); |
256 if (iter != init_data_type_name_map_.end()) | 262 if (iter != init_data_type_name_map_.end()) |
257 return iter->second; | 263 return iter->second; |
258 return EME_INIT_DATA_TYPE_NONE; | 264 return media::EME_INIT_DATA_TYPE_NONE; |
259 } | 265 } |
260 | 266 |
261 SupportedCodecs KeySystems::GetCodecMaskForContainer( | 267 SupportedCodecs KeySystems::GetCodecMaskForContainer( |
262 const std::string& container) const { | 268 const std::string& container) const { |
263 ContainerCodecsMap::const_iterator iter = | 269 ContainerCodecsMap::const_iterator iter = |
264 container_to_codec_mask_map_.find(container); | 270 container_to_codec_mask_map_.find(container); |
265 if (iter != container_to_codec_mask_map_.end()) | 271 if (iter != container_to_codec_mask_map_.end()) |
266 return iter->second; | 272 return iter->second; |
267 return EME_CODEC_NONE; | 273 return media::EME_CODEC_NONE; |
268 } | 274 } |
269 | 275 |
270 EmeCodec KeySystems::GetCodecForString(const std::string& codec) const { | 276 EmeCodec KeySystems::GetCodecForString(const std::string& codec) const { |
271 CodecsMap::const_iterator iter = codec_string_map_.find(codec); | 277 CodecsMap::const_iterator iter = codec_string_map_.find(codec); |
272 if (iter != codec_string_map_.end()) | 278 if (iter != codec_string_map_.end()) |
273 return iter->second; | 279 return iter->second; |
274 return EME_CODEC_NONE; | 280 return media::EME_CODEC_NONE; |
275 } | 281 } |
276 | 282 |
277 const std::string& KeySystems::GetConcreteKeySystemName( | 283 const std::string& KeySystems::GetConcreteKeySystemName( |
278 const std::string& key_system) const { | 284 const std::string& key_system) const { |
279 ParentKeySystemMap::const_iterator iter = | 285 ParentKeySystemMap::const_iterator iter = |
280 parent_key_system_map_.find(key_system); | 286 parent_key_system_map_.find(key_system); |
281 if (iter != parent_key_system_map_.end()) | 287 if (iter != parent_key_system_map_.end()) |
282 return iter->second; | 288 return iter->second; |
283 return key_system; | 289 return key_system; |
284 } | 290 } |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 CONTENT_EXPORT void AddContainerMask(const std::string& container, | 641 CONTENT_EXPORT void AddContainerMask(const std::string& container, |
636 uint32 mask) { | 642 uint32 mask) { |
637 KeySystems::GetInstance().AddContainerMask(container, mask); | 643 KeySystems::GetInstance().AddContainerMask(container, mask); |
638 } | 644 } |
639 | 645 |
640 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { | 646 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
641 KeySystems::GetInstance().AddCodecMask(codec, mask); | 647 KeySystems::GetInstance().AddCodecMask(codec, mask); |
642 } | 648 } |
643 | 649 |
644 } // namespace content | 650 } // namespace content |
OLD | NEW |