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

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

Issue 23678008: Refactor KeySystems code to call a function to populate the info. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase - includes reimplementation of part of r221548 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"
9 #include "third_party/WebKit/public/platform/WebString.h" 8 #include "third_party/WebKit/public/platform/WebString.h"
10 9
11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
12 11
13 // The following must be after widevine_cdm_version.h. 12 // The following must be after widevine_cdm_version.h.
14 13
15 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 14 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
16 #include <gnu/libc-version.h> 15 #include <gnu/libc-version.h>
17 #include "base/version.h" 16 #include "base/version.h"
18 #endif 17 #endif
19 18
20 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 19 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
21 #include "base/command_line.h" 20 #include "base/command_line.h"
22 #include "media/base/media_switches.h" 21 #include "media/base/media_switches.h"
23 #endif 22 #endif
24 23
25 namespace content { 24 namespace content {
26 25
27 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; 26 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
28 27
29 #if defined(ENABLE_PEPPER_CDMS) 28 static const char kAudioWebM[] = "audio/webm";
30 static const char kExternalClearKeyKeySystem[] = 29 static const char kVideoWebM[] = "video/webm";
31 "org.chromium.externalclearkey"; 30 static const char kVorbis[] = "vorbis";
32 #elif defined(OS_ANDROID) 31 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0";
33 static const uint8 kEmptyUuid[16] = 32
34 { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 33 static const char kAudioMp4[] = "audio/mp4";
35 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; 34 static const char kVideoMp4[] = "video/mp4";
36 static const uint8 kWidevineUuid[16] = 35 static const char kMp4a[] = "mp4a";
37 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, 36 static const char kAvc1[] = "avc1";
37 static const char kMp4aAvc1[] = "mp4a,avc1";
38
39 #if defined(WIDEVINE_CDM_AVAILABLE)
40 enum SupportedCodecs {
41 WEBM_VP8_AND_VORBIS = 1,
scherkus (not reviewing) 2013/09/06 19:29:59 nit: 1 << 0
ddorwin 2013/09/06 21:34:50 Done.
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,
38 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; 55 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
39 #endif 56 #endif
40 57
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() {
64 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 58 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
65 Version glibc_version(gnu_get_libc_version()); 59 Version glibc_version(gnu_get_libc_version());
66 DCHECK(glibc_version.IsValid()); 60 DCHECK(glibc_version.IsValid());
67 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) 61 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION))
68 return; 62 return;
69 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 63 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
70 64
71 AddConcreteSupportedKeySystem( 65 KeySystemInfo info(kWidevineKeySystem);
72 kWidevineKeySystem, 66
73 false, 67 const bool is_webm_vp8_and_vorbis_supported =
scherkus (not reviewing) 2013/09/06 19:29:59 if we moved to using enums for readability, why no
ddorwin 2013/09/06 21:34:50 I find it easier to read (and we avoid duplicating
68 supported_codecs & WEBM_VP8_AND_VORBIS;
69 if (is_webm_vp8_and_vorbis_supported) {
70 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
71 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
72 }
73
74 #if defined(USE_PROPRIETARY_CODECS)
75 const bool is_aac_supported = supported_codecs & MP4_AAC;
76 const bool is_avc1_supported = supported_codecs & MP4_AVC1;
77
78 if (is_aac_supported)
79 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
ddorwin 2013/09/06 18:30:00 Note: audio/mp4 without a codec is no longer suppo
scherkus (not reviewing) 2013/09/06 19:29:59 SGTM
80
81 if (is_avc1_supported) {
82 const char* video_codecs = is_aac_supported ? kMp4aAvc1 : kAvc1;
83 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs));
ddorwin 2013/09/06 18:30:00 Note: video/mp4 without a codec or with only mp4a
scherkus (not reviewing) 2013/09/06 19:29:59 SGTM
84 }
85 #endif // defined(USE_PROPRIETARY_CODECS)
86
87 info.parent_key_system = kWidevineParentKeySystem;
88
74 #if defined(ENABLE_PEPPER_CDMS) 89 #if defined(ENABLE_PEPPER_CDMS)
75 kWidevineCdmPluginMimeType, 90 info.pepper_type = kWidevineCdmPluginMimeType;
76 #elif defined(OS_ANDROID) 91 #elif defined(OS_ANDROID)
77 kWidevineUuid, 92 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid));
78 #endif // defined(ENABLE_PEPPER_CDMS) 93 #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
92 94
93 95 concrete_key_systems->push_back(info);
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");
107 #if defined(USE_PROPRIETARY_CODECS)
108 AddSupportedType(kClearKeyKeySystem, "video/mp4", "avc1,mp4a");
109 AddSupportedType(kClearKeyKeySystem, "audio/mp4", "mp4a");
110 #endif // defined(USE_PROPRIETARY_CODECS)
111 } 96 }
112 97
113 #if defined(ENABLE_PEPPER_CDMS) 98 #if defined(ENABLE_PEPPER_CDMS)
114 static void RegisterExternalClearKey() { 99 // Supported types are determined at compile time.
115 // External Clear Key (used for testing). 100 static void AddPepperBasedWidevine(
116 AddConcreteSupportedKeySystem(kExternalClearKeyKeySystem, false, 101 std::vector<KeySystemInfo>* concrete_key_systems) {
117 "application/x-ppapi-clearkey-cdm", 102 SupportedCodecs supported_codecs = WEBM_VP8_AND_VORBIS;
118 std::string()); 103
119 AddSupportedType(kExternalClearKeyKeySystem,
120 "video/webm", "vorbis,vp8,vp8.0");
121 AddSupportedType(kExternalClearKeyKeySystem, "audio/webm", "vorbis");
122 #if defined(USE_PROPRIETARY_CODECS) 104 #if defined(USE_PROPRIETARY_CODECS)
123 AddSupportedType(kExternalClearKeyKeySystem, "video/mp4", "avc1,mp4a"); 105 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
124 AddSupportedType(kExternalClearKeyKeySystem, "audio/mp4", "mp4a"); 106 supported_codecs |= MP4_AAC;
107 #endif
108 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
109 supported_codecs |= MP4_AVC1;
110 #endif
125 #endif // defined(USE_PROPRIETARY_CODECS) 111 #endif // defined(USE_PROPRIETARY_CODECS)
112
113 AddWidevineForTypes(supported_codecs, concrete_key_systems);
114 }
115 #elif defined(OS_ANDROID)
116 static void AddAndroidWidevine(
117 std::vector<KeySystemInfo>* concrete_key_systems) {
118 SupportedCodecs supported_codecs = MP4_AAC | MP4_AVC1;
119 AddWidevineForTypes(supported_codecs, concrete_key_systems);
126 } 120 }
127 #endif // defined(ENABLE_PEPPER_CDMS) 121 #endif // defined(ENABLE_PEPPER_CDMS)
122 #endif // defined(WIDEVINE_CDM_AVAILABLE)
128 123
129 void RegisterKeySystems() { 124 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
130 RegisterClearKey(); 125 KeySystemInfo info(kClearKeyKeySystem);
126
127 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
128 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
129 #if defined(USE_PROPRIETARY_CODECS)
130 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
131 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1));
132 #endif // defined(USE_PROPRIETARY_CODECS)
133
134 info.use_aes_decryptor = true;
135
136 concrete_key_systems->push_back(info);
137 }
131 138
132 #if defined(ENABLE_PEPPER_CDMS) 139 #if defined(ENABLE_PEPPER_CDMS)
133 RegisterExternalClearKey(); 140 // External Clear Key (used for testing).
141 static void AddExternalClearKey(
142 std::vector<KeySystemInfo>* concrete_key_systems) {
143 static const char kExternalClearKeyKeySystem[] =
144 "org.chromium.externalclearkey";
145 static const char kExternalClearKeyPepperType[] =
146 "application/x-ppapi-clearkey-cdm";
147
148 KeySystemInfo info(kExternalClearKeyKeySystem);
149
150 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
151 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
152 #if defined(USE_PROPRIETARY_CODECS)
153 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
154 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1));
155 #endif // defined(USE_PROPRIETARY_CODECS)
156
157 info.pepper_type = kExternalClearKeyPepperType;
158
159 concrete_key_systems->push_back(info);
160 }
161 #elif defined(OS_ANDROID)
162 AddAndroidWidevine(key_systems_info);
scherkus (not reviewing) 2013/09/06 19:29:59 does this compile? it doesn't appear to be in any
ddorwin 2013/09/06 21:34:50 Oops. Accidental paste.
163 #endif // defined(ENABLE_PEPPER_CDMS)
164
165 void AddKeySystems(std::vector<KeySystemInfo>* key_systems_info) {
166 AddClearKey(key_systems_info);
167
168 #if defined(ENABLE_PEPPER_CDMS)
169 AddExternalClearKey(key_systems_info);
134 #endif 170 #endif
135 171
136 #if defined(WIDEVINE_CDM_AVAILABLE) 172 #if defined(WIDEVINE_CDM_AVAILABLE)
137 RegisterWidevine(); 173 #if defined(ENABLE_PEPPER_CDMS)
174 AddPepperBasedWidevine(key_systems_info);
175 #elif defined(OS_ANDROID)
176 AddAndroidWidevine(key_systems_info);
177 #endif
138 #endif 178 #endif
139 } 179 }
140 180
141 bool IsCanPlayTypeSuppressed(const std::string& key_system) { 181 bool IsCanPlayTypeSuppressed(const std::string& key_system) {
142 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 182 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
143 // See http://crbug.com/237627. 183 // See http://crbug.com/237627.
144 if (key_system == kWidevineKeySystem && 184 if (key_system == kWidevineKeySystem &&
145 !CommandLine::ForCurrentProcess()->HasSwitch( 185 !CommandLine::ForCurrentProcess()->HasSwitch(
146 switches::kOverrideEncryptedMediaCanPlayType)) 186 switches::kOverrideEncryptedMediaCanPlayType))
147 return true; 187 return true;
148 #endif 188 #endif
149 return false; 189 return false;
150 } 190 }
151 191
152 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { 192 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) {
153 if (key_system == kClearKeyKeySystem) 193 if (key_system == kClearKeyKeySystem)
154 return "ClearKey"; 194 return "ClearKey";
155 #if defined(WIDEVINE_CDM_AVAILABLE) 195 #if defined(WIDEVINE_CDM_AVAILABLE)
156 if (key_system == kWidevineKeySystem) 196 if (key_system == kWidevineKeySystem)
157 return "Widevine"; 197 return "Widevine";
158 #endif // WIDEVINE_CDM_AVAILABLE 198 #endif // WIDEVINE_CDM_AVAILABLE
159 return "Unknown"; 199 return "Unknown";
160 } 200 }
161 201
162 } // namespace content 202 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/crypto/key_systems_info.h ('k') | content/renderer/media/crypto/key_systems_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698