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

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: add missing file 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";
38 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; 37 static const char kMp4aAvc1[] = "mp4a,avc1";
38
39 #if defined(WIDEVINE_CDM_AVAILABLE)
40 static void AddWidevineForTypes(
41 bool is_webm_vp8_and_vorbis_supported,
42 #if defined(USE_PROPRIETARY_CODECS)
43 bool is_mp4_supported,
44 bool is_aac_supported,
45 bool is_avc1_supported,
46 #endif // defined(USE_PROPRIETARY_CODECS)
47 std::vector<KeySystemInfo>* concrete_key_systems) {
48 static const char kWidevineParentKeySystem[] = "com.widevine";
49 #if defined(OS_ANDROID)
50 static const uint8 kWidevineUuid[16] =
51 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
xhwang 2013/09/04 21:48:40 Move "{" to the previous line?
ddorwin 2013/09/06 18:30:00 Done.
52 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
39 #endif 53 #endif
40 54
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) 55 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
65 Version glibc_version(gnu_get_libc_version()); 56 Version glibc_version(gnu_get_libc_version());
66 DCHECK(glibc_version.IsValid()); 57 DCHECK(glibc_version.IsValid());
67 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) 58 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION))
68 return; 59 return;
69 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) 60 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
70 61
71 AddConcreteSupportedKeySystem( 62 KeySystemInfo info(kWidevineKeySystem);
72 kWidevineKeySystem, 63
73 false, 64 if (is_webm_vp8_and_vorbis_supported) {
65 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
66 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
67 }
68
69 #if defined(USE_PROPRIETARY_CODECS)
70 DCHECK(!is_mp4_supported || (!is_aac_supported && !is_aac_supported));
71 if (is_mp4_supported) {
72 const char* video_codecs = is_avc1_supported ?
73 (is_aac_supported ? kMp4aAvc1 : kAvc1) :
74 "";
75 const char* audio_codecs = is_aac_supported ? kMp4a : "";
76
77 info.supported_types.push_back(std::make_pair(kAudioMp4, audio_codecs));
78 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs));
79 }
80 #endif // defined(USE_PROPRIETARY_CODECS)
81
82 info.parent_key_system = kWidevineParentKeySystem;
83
74 #if defined(ENABLE_PEPPER_CDMS) 84 #if defined(ENABLE_PEPPER_CDMS)
75 kWidevineCdmPluginMimeType, 85 info.pepper_type = kWidevineCdmPluginMimeType;
76 #elif defined(OS_ANDROID) 86 #elif defined(OS_ANDROID)
77 kWidevineUuid, 87 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid));
78 #endif // defined(ENABLE_PEPPER_CDMS) 88 #endif // defined(ENABLE_PEPPER_CDMS)
79 "com.widevine");
80 AddSupportedType(kWidevineKeySystem, "video/webm", "vorbis,vp8,vp8.0");
81 AddSupportedType(kWidevineKeySystem, "audio/webm", "vorbis");
82 #if defined(USE_PROPRIETARY_CODECS) && \
83 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
84 AddSupportedType(kWidevineKeySystem, "video/mp4", kWidevineVideoMp4Codecs);
85 AddSupportedType(kWidevineKeySystem, "audio/mp4", kWidevineAudioMp4Codecs);
86 #endif // defined(USE_PROPRIETARY_CODECS) &&
87 // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
88 }
89 #endif // WIDEVINE_CDM_AVAILABLE
90 89
91 90 concrete_key_systems->push_back(info);
92 static void RegisterClearKey() {
93 // Clear Key.
94 AddConcreteSupportedKeySystem(
95 kClearKeyKeySystem,
96 true,
97 #if defined(ENABLE_PEPPER_CDMS)
98 std::string(),
99 #elif defined(OS_ANDROID)
100 kEmptyUuid,
101 #endif // defined(ENABLE_PEPPER_CDMS)
102 std::string());
103 AddSupportedType(kClearKeyKeySystem, "video/webm", "vorbis,vp8,vp8.0");
104 AddSupportedType(kClearKeyKeySystem, "audio/webm", "vorbis");
105 #if defined(USE_PROPRIETARY_CODECS)
106 AddSupportedType(kClearKeyKeySystem, "video/mp4", "avc1,mp4a");
107 AddSupportedType(kClearKeyKeySystem, "audio/mp4", "mp4a");
108 #endif // defined(USE_PROPRIETARY_CODECS)
109 } 91 }
110 92
111 #if defined(ENABLE_PEPPER_CDMS) 93 #if defined(ENABLE_PEPPER_CDMS)
112 static void RegisterExternalClearKey() { 94 // Supported types are determined at compile time.
113 // External Clear Key (used for testing). 95 static void AddPepperBasedWidevine(
114 AddConcreteSupportedKeySystem(kExternalClearKeyKeySystem, false, 96 std::vector<KeySystemInfo>* concrete_key_systems) {
115 "application/x-ppapi-clearkey-cdm", 97 AddWidevineForTypes(true, // WebM, VP8 & Vorbis.
116 std::string());
117 AddSupportedType(kExternalClearKeyKeySystem,
118 "video/webm", "vorbis,vp8,vp8.0");
119 AddSupportedType(kExternalClearKeyKeySystem, "audio/webm", "vorbis");
120 #if defined(USE_PROPRIETARY_CODECS) 98 #if defined(USE_PROPRIETARY_CODECS)
121 AddSupportedType(kExternalClearKeyKeySystem, "video/mp4", "avc1,mp4a"); 99 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
122 AddSupportedType(kExternalClearKeyKeySystem, "audio/mp4", "mp4a"); 100 true, // MP4.
101 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
102 true, // AAC.
103 #else
104 false, // No AAC.
105 #endif
106 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
107 true, // AVC1.
xhwang 2013/09/04 21:48:40 Shall we define bit flags for these? e.g. CDM_SUPP
ddorwin 2013/09/06 18:30:00 Done.
108 #else
109 false, // No AVC1.
110 #endif
111 #else
112 false, false, false, // No MP4 codecs.
113 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
123 #endif // defined(USE_PROPRIETARY_CODECS) 114 #endif // defined(USE_PROPRIETARY_CODECS)
115 concrete_key_systems);
116 }
117 #endif // defined(ENABLE_PEPPER_CDMS)
118 #endif // defined(WIDEVINE_CDM_AVAILABLE)
119
120 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
121 KeySystemInfo info(kClearKeyKeySystem);
122
123 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
124 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
125 #if defined(USE_PROPRIETARY_CODECS)
126 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
127 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1));
128 #endif // defined(USE_PROPRIETARY_CODECS)
129
130 info.use_aes_decryptor = true;
131
132 concrete_key_systems->push_back(info);
133 }
134
135 #if defined(ENABLE_PEPPER_CDMS)
136 // External Clear Key (used for testing).
137 static void AddExternalClearKey(
138 std::vector<KeySystemInfo>* concrete_key_systems) {
139 static const char kExternalClearKeyKeySystem[] =
140 "org.chromium.externalclearkey";
141 static const char kExternalClearKeyPepperType[] =
142 "application/x-ppapi-clearkey-cdm";
143
144 KeySystemInfo info(kExternalClearKeyKeySystem);
145
146 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
147 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
148 #if defined(USE_PROPRIETARY_CODECS)
149 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
150 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1));
151 #endif // defined(USE_PROPRIETARY_CODECS)
152
153 info.pepper_type = kExternalClearKeyPepperType;
154
155 concrete_key_systems->push_back(info);
124 } 156 }
125 #endif // defined(ENABLE_PEPPER_CDMS) 157 #endif // defined(ENABLE_PEPPER_CDMS)
126 158
127 void RegisterKeySystems() { 159 void AddKeySystems(std::vector<KeySystemInfo>* key_systems_info) {
128 RegisterClearKey(); 160 AddClearKey(key_systems_info);
129 161
130 #if defined(ENABLE_PEPPER_CDMS) 162 #if defined(ENABLE_PEPPER_CDMS)
131 RegisterExternalClearKey(); 163 AddExternalClearKey(key_systems_info);
132 #endif 164 #endif
133 165
134 #if defined(WIDEVINE_CDM_AVAILABLE) 166 #if defined(WIDEVINE_CDM_AVAILABLE)
135 RegisterWidevine(); 167 #if defined(ENABLE_PEPPER_CDMS)
168 AddPepperBasedWidevine(key_systems_info);
169 #else
170 #error TODO(ddorwin): Need to check the platform
171 #endif
136 #endif 172 #endif
137 } 173 }
138 174
139 bool IsCanPlayTypeSuppressed(const std::string& key_system) { 175 bool IsCanPlayTypeSuppressed(const std::string& key_system) {
140 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 176 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
141 // See http://crbug.com/237627. 177 // See http://crbug.com/237627.
142 if (key_system == kWidevineKeySystem && 178 if (key_system == kWidevineKeySystem &&
143 !CommandLine::ForCurrentProcess()->HasSwitch( 179 !CommandLine::ForCurrentProcess()->HasSwitch(
144 switches::kOverrideEncryptedMediaCanPlayType)) 180 switches::kOverrideEncryptedMediaCanPlayType))
145 return true; 181 return true;
146 #endif 182 #endif
147 return false; 183 return false;
148 } 184 }
149 185
150 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { 186 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) {
151 if (key_system == kClearKeyKeySystem) 187 if (key_system == kClearKeyKeySystem)
152 return "ClearKey"; 188 return "ClearKey";
153 #if defined(WIDEVINE_CDM_AVAILABLE) 189 #if defined(WIDEVINE_CDM_AVAILABLE)
154 if (key_system == kWidevineKeySystem) 190 if (key_system == kWidevineKeySystem)
155 return "Widevine"; 191 return "Widevine";
156 #endif // WIDEVINE_CDM_AVAILABLE 192 #endif // WIDEVINE_CDM_AVAILABLE
157 return "Unknown"; 193 return "Unknown";
158 } 194 }
159 195
160 } // namespace content 196 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698