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 "chrome/renderer/media/chrome_key_systems.h" | 5 #include "chrome/renderer/media/chrome_key_systems.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/render_messages.h" |
| 9 #include "content/public/renderer/render_thread.h" |
8 | 10 |
9 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
10 | 12 |
11 // The following must be after widevine_cdm_version.h. | 13 // The following must be after widevine_cdm_version.h. |
12 | 14 |
13 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 15 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
14 #include <gnu/libc-version.h> | 16 #include <gnu/libc-version.h> |
15 #include "base/version.h" | 17 #include "base/version.h" |
16 #endif | 18 #endif |
17 | 19 |
18 using content::KeySystemInfo; | 20 using content::KeySystemInfo; |
19 | 21 |
20 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 22 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
21 | 23 |
22 static const char kAudioWebM[] = "audio/webm"; | 24 static const char kAudioWebM[] = "audio/webm"; |
23 static const char kVideoWebM[] = "video/webm"; | 25 static const char kVideoWebM[] = "video/webm"; |
24 static const char kVorbis[] = "vorbis"; | 26 static const char kVorbis[] = "vorbis"; |
25 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; | 27 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; |
26 | 28 |
27 static const char kAudioMp4[] = "audio/mp4"; | 29 static const char kAudioMp4[] = "audio/mp4"; |
28 static const char kVideoMp4[] = "video/mp4"; | 30 static const char kVideoMp4[] = "video/mp4"; |
29 static const char kMp4a[] = "mp4a"; | 31 static const char kMp4a[] = "mp4a"; |
30 static const char kAvc1[] = "avc1"; | 32 static const char kAvc1[] = "avc1"; |
31 static const char kMp4aAvc1[] = "mp4a,avc1"; | 33 static const char kMp4aAvc1[] = "mp4a,avc1"; |
32 | 34 |
| 35 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
| 36 KeySystemInfo info(kClearKeyKeySystem); |
| 37 |
| 38 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
| 39 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
| 40 #if defined(USE_PROPRIETARY_CODECS) |
| 41 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 42 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); |
| 43 #endif // defined(USE_PROPRIETARY_CODECS) |
| 44 |
| 45 info.use_aes_decryptor = true; |
| 46 |
| 47 concrete_key_systems->push_back(info); |
| 48 } |
| 49 |
| 50 #if defined(ENABLE_PEPPER_CDMS) |
| 51 static bool IsPepperCdmRegistered(const std::string& pepper_type) { |
| 52 bool is_registered = false; |
| 53 content::RenderThread::Get()->Send( |
| 54 new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType( |
| 55 pepper_type, &is_registered)); |
| 56 |
| 57 return is_registered; |
| 58 } |
| 59 |
| 60 // External Clear Key (used for testing). |
| 61 static void AddExternalClearKey( |
| 62 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 63 static const char kExternalClearKeyKeySystem[] = |
| 64 "org.chromium.externalclearkey"; |
| 65 static const char kExternalClearKeyPepperType[] = |
| 66 "application/x-ppapi-clearkey-cdm"; |
| 67 |
| 68 if (!IsPepperCdmRegistered(kExternalClearKeyPepperType)) |
| 69 return; |
| 70 |
| 71 KeySystemInfo info(kExternalClearKeyKeySystem); |
| 72 |
| 73 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
| 74 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
| 75 #if defined(USE_PROPRIETARY_CODECS) |
| 76 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 77 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); |
| 78 #endif // defined(USE_PROPRIETARY_CODECS) |
| 79 |
| 80 info.pepper_type = kExternalClearKeyPepperType; |
| 81 |
| 82 concrete_key_systems->push_back(info); |
| 83 } |
| 84 #endif // defined(ENABLE_PEPPER_CDMS) |
| 85 |
| 86 |
33 #if defined(WIDEVINE_CDM_AVAILABLE) | 87 #if defined(WIDEVINE_CDM_AVAILABLE) |
34 // Defines bitmask values used to specify supported codecs. | 88 // Defines bitmask values used to specify supported codecs. |
35 // Each value represents a codec within a specific container. | 89 // Each value represents a codec within a specific container. |
36 enum SupportedCodecs { | 90 enum SupportedCodecs { |
37 WEBM_VP8_AND_VORBIS = 1 << 0, | 91 WEBM_VP8_AND_VORBIS = 1 << 0, |
38 #if defined(USE_PROPRIETARY_CODECS) | 92 #if defined(USE_PROPRIETARY_CODECS) |
39 MP4_AAC = 1 << 1, | 93 MP4_AAC = 1 << 1, |
40 MP4_AVC1 = 1 << 2, | 94 MP4_AVC1 = 1 << 2, |
41 #endif // defined(USE_PROPRIETARY_CODECS) | 95 #endif // defined(USE_PROPRIETARY_CODECS) |
42 }; | 96 }; |
43 | 97 |
44 static void AddWidevineWithCodecs( | 98 static void AddWidevineWithCodecs( |
45 SupportedCodecs supported_codecs, | 99 SupportedCodecs supported_codecs, |
46 std::vector<KeySystemInfo>* concrete_key_systems) { | 100 std::vector<KeySystemInfo>* concrete_key_systems) { |
47 static const char kWidevineParentKeySystem[] = "com.widevine"; | 101 static const char kWidevineParentKeySystem[] = "com.widevine"; |
48 #if defined(OS_ANDROID) | 102 #if defined(OS_ANDROID) |
49 static const uint8 kWidevineUuid[16] = { | 103 static const uint8 kWidevineUuid[16] = { |
50 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 104 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
51 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 105 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
52 #endif | 106 #endif |
53 | 107 |
54 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
55 Version glibc_version(gnu_get_libc_version()); | |
56 DCHECK(glibc_version.IsValid()); | |
57 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | |
58 return; | |
59 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
60 | |
61 KeySystemInfo info(kWidevineKeySystem); | 108 KeySystemInfo info(kWidevineKeySystem); |
62 | 109 |
63 if (supported_codecs & WEBM_VP8_AND_VORBIS) { | 110 if (supported_codecs & WEBM_VP8_AND_VORBIS) { |
64 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | 111 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
65 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | 112 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
66 } | 113 } |
67 | 114 |
68 #if defined(USE_PROPRIETARY_CODECS) | 115 #if defined(USE_PROPRIETARY_CODECS) |
69 if (supported_codecs & MP4_AAC) | 116 if (supported_codecs & MP4_AAC) |
70 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | 117 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
(...skipping 12 matching lines...) Expand all Loading... |
83 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); | 130 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); |
84 #endif // defined(ENABLE_PEPPER_CDMS) | 131 #endif // defined(ENABLE_PEPPER_CDMS) |
85 | 132 |
86 concrete_key_systems->push_back(info); | 133 concrete_key_systems->push_back(info); |
87 } | 134 } |
88 | 135 |
89 #if defined(ENABLE_PEPPER_CDMS) | 136 #if defined(ENABLE_PEPPER_CDMS) |
90 // Supported types are determined at compile time. | 137 // Supported types are determined at compile time. |
91 static void AddPepperBasedWidevine( | 138 static void AddPepperBasedWidevine( |
92 std::vector<KeySystemInfo>* concrete_key_systems) { | 139 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 140 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 141 Version glibc_version(gnu_get_libc_version()); |
| 142 DCHECK(glibc_version.IsValid()); |
| 143 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) |
| 144 return; |
| 145 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 146 |
| 147 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType)) { |
| 148 DVLOG(1) << "Widevine CDM is not currently available."; |
| 149 return; |
| 150 } |
| 151 |
93 SupportedCodecs supported_codecs = WEBM_VP8_AND_VORBIS; | 152 SupportedCodecs supported_codecs = WEBM_VP8_AND_VORBIS; |
94 | 153 |
95 #if defined(USE_PROPRIETARY_CODECS) | 154 #if defined(USE_PROPRIETARY_CODECS) |
96 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) | 155 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) |
97 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AAC); | 156 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AAC); |
98 #endif | 157 #endif |
99 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) | 158 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) |
100 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AVC1); | 159 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AVC1); |
101 #endif | 160 #endif |
102 #endif // defined(USE_PROPRIETARY_CODECS) | 161 #endif // defined(USE_PROPRIETARY_CODECS) |
103 | 162 |
104 AddWidevineWithCodecs(supported_codecs, concrete_key_systems); | 163 AddWidevineWithCodecs(supported_codecs, concrete_key_systems); |
105 } | 164 } |
106 #elif defined(OS_ANDROID) | 165 #elif defined(OS_ANDROID) |
107 static void AddAndroidWidevine( | 166 static void AddAndroidWidevine( |
108 std::vector<KeySystemInfo>* concrete_key_systems) { | 167 std::vector<KeySystemInfo>* concrete_key_systems) { |
109 #if defined(USE_PROPRIETARY_CODECS) | 168 #if defined(USE_PROPRIETARY_CODECS) |
110 SupportedCodecs supported_codecs = | 169 SupportedCodecs supported_codecs = |
111 static_cast<SupportedCodecs>(MP4_AAC | MP4_AVC1); | 170 static_cast<SupportedCodecs>(MP4_AAC | MP4_AVC1); |
112 AddWidevineWithCodecs(supported_codecs, concrete_key_systems); | 171 AddWidevineWithCodecs(supported_codecs, concrete_key_systems); |
113 #endif // defined(USE_PROPRIETARY_CODECS) | 172 #endif // defined(USE_PROPRIETARY_CODECS) |
114 } | 173 } |
115 #endif // defined(ENABLE_PEPPER_CDMS) | 174 #endif // defined(ENABLE_PEPPER_CDMS) |
116 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 175 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
117 | 176 |
118 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | |
119 KeySystemInfo info(kClearKeyKeySystem); | |
120 | |
121 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
122 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
123 #if defined(USE_PROPRIETARY_CODECS) | |
124 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | |
125 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); | |
126 #endif // defined(USE_PROPRIETARY_CODECS) | |
127 | |
128 info.use_aes_decryptor = true; | |
129 | |
130 concrete_key_systems->push_back(info); | |
131 } | |
132 | |
133 #if defined(ENABLE_PEPPER_CDMS) | |
134 // External Clear Key (used for testing). | |
135 static void AddExternalClearKey( | |
136 std::vector<KeySystemInfo>* concrete_key_systems) { | |
137 static const char kExternalClearKeyKeySystem[] = | |
138 "org.chromium.externalclearkey"; | |
139 static const char kExternalClearKeyPepperType[] = | |
140 "application/x-ppapi-clearkey-cdm"; | |
141 | |
142 KeySystemInfo info(kExternalClearKeyKeySystem); | |
143 | |
144 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
145 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
146 #if defined(USE_PROPRIETARY_CODECS) | |
147 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | |
148 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); | |
149 #endif // defined(USE_PROPRIETARY_CODECS) | |
150 | |
151 info.pepper_type = kExternalClearKeyPepperType; | |
152 | |
153 concrete_key_systems->push_back(info); | |
154 } | |
155 #endif // defined(ENABLE_PEPPER_CDMS) | |
156 | |
157 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 177 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
158 AddClearKey(key_systems_info); | 178 AddClearKey(key_systems_info); |
159 | 179 |
160 #if defined(ENABLE_PEPPER_CDMS) | 180 #if defined(ENABLE_PEPPER_CDMS) |
161 AddExternalClearKey(key_systems_info); | 181 AddExternalClearKey(key_systems_info); |
162 #endif | 182 #endif |
163 | 183 |
164 #if defined(WIDEVINE_CDM_AVAILABLE) | 184 #if defined(WIDEVINE_CDM_AVAILABLE) |
165 #if defined(ENABLE_PEPPER_CDMS) | 185 #if defined(ENABLE_PEPPER_CDMS) |
166 AddPepperBasedWidevine(key_systems_info); | 186 AddPepperBasedWidevine(key_systems_info); |
167 #elif defined(OS_ANDROID) | 187 #elif defined(OS_ANDROID) |
168 AddAndroidWidevine(key_systems_info); | 188 AddAndroidWidevine(key_systems_info); |
169 #endif | 189 #endif |
170 #endif | 190 #endif |
171 } | 191 } |
OLD | NEW |