Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: trunk/src/content/renderer/media/crypto/key_systems_info.cc

Issue 23708020: Revert 222074 "Refactor KeySystems code to call a function to po..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_info.h" 5 #include "content/renderer/media/crypto/key_systems_info.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/media/crypto/key_systems.h"
8 #include "third_party/WebKit/public/platform/WebString.h" 9 #include "third_party/WebKit/public/platform/WebString.h"
9 10
10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
11 12
12 // The following must be after widevine_cdm_version.h. 13 // The following must be after widevine_cdm_version.h.
13 14
14 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 15 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
15 #include <gnu/libc-version.h> 16 #include <gnu/libc-version.h>
16 #include "base/version.h" 17 #include "base/version.h"
17 #endif 18 #endif
18 19
19 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 20 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
20 #include "base/command_line.h" 21 #include "base/command_line.h"
21 #include "media/base/media_switches.h" 22 #include "media/base/media_switches.h"
22 #endif 23 #endif
23 24
24 namespace content { 25 namespace content {
25 26
26 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; 27 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
27 28
28 static const char kAudioWebM[] = "audio/webm"; 29 #if defined(ENABLE_PEPPER_CDMS)
29 static const char kVideoWebM[] = "video/webm"; 30 static const char kExternalClearKeyKeySystem[] =
30 static const char kVorbis[] = "vorbis"; 31 "org.chromium.externalclearkey";
31 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; 32 #elif defined(OS_ANDROID)
32 33 static const uint8 kEmptyUuid[16] =
33 static const char kAudioMp4[] = "audio/mp4"; 34 { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
34 static const char kVideoMp4[] = "video/mp4"; 35 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
35 static const char kMp4a[] = "mp4a"; 36 static const uint8 kWidevineUuid[16] =
36 static const char kAvc1[] = "avc1"; 37 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
37 static const char kMp4aAvc1[] = "mp4a,avc1";
38
39 #if defined(WIDEVINE_CDM_AVAILABLE)
40 enum SupportedCodecs {
41 WEBM_VP8_AND_VORBIS = 1 << 0,
42 #if defined(USE_PROPRIETARY_CODECS)
43 MP4_AAC = 1 << 1,
44 MP4_AVC1 = 1 << 2,
45 #endif // defined(USE_PROPRIETARY_CODECS)
46 };
47
48 static void AddWidevineForTypes(
49 SupportedCodecs supported_codecs,
50 std::vector<KeySystemInfo>* concrete_key_systems) {
51 static const char kWidevineParentKeySystem[] = "com.widevine";
52 #if defined(OS_ANDROID)
53 static const uint8 kWidevineUuid[16] = {
54 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
55 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; 38 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
56 #endif 39 #endif
57 40
41 #if defined(WIDEVINE_CDM_AVAILABLE)
42
43 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
44 // The supported codecs depend on what the CDM provides.
45 static const char kWidevineVideoMp4Codecs[] =
46 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \
47 defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
48 "avc1,mp4a";
49 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
50 "avc1";
51 #else
52 ""; // No codec strings are supported.
53 #endif
54
55 static const char kWidevineAudioMp4Codecs[] =
56 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
57 "mp4a";
58 #else
59 ""; // No codec strings are supported.
60 #endif
61 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
62
63 static void RegisterWidevine() {
58 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 64 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
59 Version glibc_version(gnu_get_libc_version()); 65 Version glibc_version(gnu_get_libc_version());
60 DCHECK(glibc_version.IsValid()); 66 DCHECK(glibc_version.IsValid());
61 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) 67 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION))
62 return; 68 return;
63 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 69 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
64 70
65 KeySystemInfo info(kWidevineKeySystem); 71 AddConcreteSupportedKeySystem(
72 kWidevineKeySystem,
73 false,
74 #if defined(ENABLE_PEPPER_CDMS)
75 kWidevineCdmPluginMimeType,
76 #elif defined(OS_ANDROID)
77 kWidevineUuid,
78 #endif // defined(ENABLE_PEPPER_CDMS)
79 "com.widevine");
80 #if !defined(OS_ANDROID)
81 AddSupportedType(kWidevineKeySystem, "video/webm", "vorbis,vp8,vp8.0");
82 AddSupportedType(kWidevineKeySystem, "audio/webm", "vorbis");
83 #endif // !defined(OS_ANDROID)
84 #if defined(USE_PROPRIETARY_CODECS) && \
85 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
86 AddSupportedType(kWidevineKeySystem, "video/mp4", kWidevineVideoMp4Codecs);
87 AddSupportedType(kWidevineKeySystem, "audio/mp4", kWidevineAudioMp4Codecs);
88 #endif // defined(USE_PROPRIETARY_CODECS) &&
89 // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
90 }
91 #endif // WIDEVINE_CDM_AVAILABLE
66 92
67 if (supported_codecs & WEBM_VP8_AND_VORBIS) {
68 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
69 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
70 }
71 93
94 static void RegisterClearKey() {
95 // Clear Key.
96 AddConcreteSupportedKeySystem(
97 kClearKeyKeySystem,
98 true,
99 #if defined(ENABLE_PEPPER_CDMS)
100 std::string(),
101 #elif defined(OS_ANDROID)
102 kEmptyUuid,
103 #endif // defined(ENABLE_PEPPER_CDMS)
104 std::string());
105 AddSupportedType(kClearKeyKeySystem, "video/webm", "vorbis,vp8,vp8.0");
106 AddSupportedType(kClearKeyKeySystem, "audio/webm", "vorbis");
72 #if defined(USE_PROPRIETARY_CODECS) 107 #if defined(USE_PROPRIETARY_CODECS)
73 if (supported_codecs & MP4_AAC) 108 AddSupportedType(kClearKeyKeySystem, "video/mp4", "avc1,mp4a");
74 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); 109 AddSupportedType(kClearKeyKeySystem, "audio/mp4", "mp4a");
75
76 if (supported_codecs & MP4_AVC1) {
77 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1;
78 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs));
79 }
80 #endif // defined(USE_PROPRIETARY_CODECS) 110 #endif // defined(USE_PROPRIETARY_CODECS)
81
82 info.parent_key_system = kWidevineParentKeySystem;
83
84 #if defined(ENABLE_PEPPER_CDMS)
85 info.pepper_type = kWidevineCdmPluginMimeType;
86 #elif defined(OS_ANDROID)
87 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid));
88 #endif // defined(ENABLE_PEPPER_CDMS)
89
90 concrete_key_systems->push_back(info);
91 } 111 }
92 112
93 #if defined(ENABLE_PEPPER_CDMS) 113 #if defined(ENABLE_PEPPER_CDMS)
94 // Supported types are determined at compile time. 114 static void RegisterExternalClearKey() {
95 static void AddPepperBasedWidevine( 115 // External Clear Key (used for testing).
96 std::vector<KeySystemInfo>* concrete_key_systems) { 116 AddConcreteSupportedKeySystem(kExternalClearKeyKeySystem, false,
97 SupportedCodecs supported_codecs = WEBM_VP8_AND_VORBIS; 117 "application/x-ppapi-clearkey-cdm",
98 118 std::string());
119 AddSupportedType(kExternalClearKeyKeySystem,
120 "video/webm", "vorbis,vp8,vp8.0");
121 AddSupportedType(kExternalClearKeyKeySystem, "audio/webm", "vorbis");
99 #if defined(USE_PROPRIETARY_CODECS) 122 #if defined(USE_PROPRIETARY_CODECS)
100 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 123 AddSupportedType(kExternalClearKeyKeySystem, "video/mp4", "avc1,mp4a");
101 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AAC); 124 AddSupportedType(kExternalClearKeyKeySystem, "audio/mp4", "mp4a");
102 #endif
103 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
104 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AVC1);
105 #endif
106 #endif // defined(USE_PROPRIETARY_CODECS) 125 #endif // defined(USE_PROPRIETARY_CODECS)
107
108 AddWidevineForTypes(supported_codecs, concrete_key_systems);
109 }
110 #elif defined(OS_ANDROID)
111 static void AddAndroidWidevine(
112 std::vector<KeySystemInfo>* concrete_key_systems) {
113 SupportedCodecs supported_codecs = MP4_AAC | MP4_AVC1;
114 AddWidevineForTypes(supported_codecs, concrete_key_systems);
115 }
116 #endif // defined(ENABLE_PEPPER_CDMS)
117 #endif // defined(WIDEVINE_CDM_AVAILABLE)
118
119 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
120 KeySystemInfo info(kClearKeyKeySystem);
121
122 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
123 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
124 #if defined(USE_PROPRIETARY_CODECS)
125 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
126 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1));
127 #endif // defined(USE_PROPRIETARY_CODECS)
128
129 info.use_aes_decryptor = true;
130
131 concrete_key_systems->push_back(info);
132 }
133
134 #if defined(ENABLE_PEPPER_CDMS)
135 // External Clear Key (used for testing).
136 static void AddExternalClearKey(
137 std::vector<KeySystemInfo>* concrete_key_systems) {
138 static const char kExternalClearKeyKeySystem[] =
139 "org.chromium.externalclearkey";
140 static const char kExternalClearKeyPepperType[] =
141 "application/x-ppapi-clearkey-cdm";
142
143 KeySystemInfo info(kExternalClearKeyKeySystem);
144
145 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
146 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
147 #if defined(USE_PROPRIETARY_CODECS)
148 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
149 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1));
150 #endif // defined(USE_PROPRIETARY_CODECS)
151
152 info.pepper_type = kExternalClearKeyPepperType;
153
154 concrete_key_systems->push_back(info);
155 } 126 }
156 #endif // defined(ENABLE_PEPPER_CDMS) 127 #endif // defined(ENABLE_PEPPER_CDMS)
157 128
158 void AddKeySystems(std::vector<KeySystemInfo>* key_systems_info) { 129 void RegisterKeySystems() {
159 AddClearKey(key_systems_info); 130 RegisterClearKey();
160 131
161 #if defined(ENABLE_PEPPER_CDMS) 132 #if defined(ENABLE_PEPPER_CDMS)
162 AddExternalClearKey(key_systems_info); 133 RegisterExternalClearKey();
163 #endif 134 #endif
164 135
165 #if defined(WIDEVINE_CDM_AVAILABLE) 136 #if defined(WIDEVINE_CDM_AVAILABLE)
166 #if defined(ENABLE_PEPPER_CDMS) 137 RegisterWidevine();
167 AddPepperBasedWidevine(key_systems_info);
168 #elif defined(OS_ANDROID)
169 AddAndroidWidevine(key_systems_info);
170 #endif
171 #endif 138 #endif
172 } 139 }
173 140
174 bool IsCanPlayTypeSuppressed(const std::string& key_system) { 141 bool IsCanPlayTypeSuppressed(const std::string& key_system) {
175 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 142 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
176 // See http://crbug.com/237627. 143 // See http://crbug.com/237627.
177 if (key_system == kWidevineKeySystem && 144 if (key_system == kWidevineKeySystem &&
178 !CommandLine::ForCurrentProcess()->HasSwitch( 145 !CommandLine::ForCurrentProcess()->HasSwitch(
179 switches::kOverrideEncryptedMediaCanPlayType)) 146 switches::kOverrideEncryptedMediaCanPlayType))
180 return true; 147 return true;
181 #endif 148 #endif
182 return false; 149 return false;
183 } 150 }
184 151
185 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { 152 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) {
186 if (key_system == kClearKeyKeySystem) 153 if (key_system == kClearKeyKeySystem)
187 return "ClearKey"; 154 return "ClearKey";
188 #if defined(WIDEVINE_CDM_AVAILABLE) 155 #if defined(WIDEVINE_CDM_AVAILABLE)
189 if (key_system == kWidevineKeySystem) 156 if (key_system == kWidevineKeySystem)
190 return "Widevine"; 157 return "Widevine";
191 #endif // WIDEVINE_CDM_AVAILABLE 158 #endif // WIDEVINE_CDM_AVAILABLE
192 return "Unknown"; 159 return "Unknown";
193 } 160 }
194 161
195 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698