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

Side by Side Diff: media/base/android/media_drm_bridge.cc

Issue 962793005: Adds MediaClientAndroid to support embedder/MediaDrmBridge interaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "media/base/android/media_drm_bridge.h" 5 #include "media/base/android/media_drm_bridge.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/message_loop/message_loop_proxy.h" 17 #include "base/message_loop/message_loop_proxy.h"
18 #include "base/numerics/safe_conversions.h"
19 #include "base/stl_util.h" 18 #include "base/stl_util.h"
20 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
21 #include "base/sys_byteorder.h" 20 #include "base/sys_byteorder.h"
22 #include "base/sys_info.h" 21 #include "base/sys_info.h"
23 #include "jni/MediaDrmBridge_jni.h" 22 #include "jni/MediaDrmBridge_jni.h"
23 #include "media/base/android/media_client_android.h"
24 #include "media/base/android/media_drm_bridge_delegate.h"
24 #include "media/base/cdm_key_information.h" 25 #include "media/base/cdm_key_information.h"
25 26
26 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 27 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
27 28
28 using base::android::AttachCurrentThread; 29 using base::android::AttachCurrentThread;
29 using base::android::ConvertUTF8ToJavaString; 30 using base::android::ConvertUTF8ToJavaString;
30 using base::android::ConvertJavaStringToUTF8; 31 using base::android::ConvertJavaStringToUTF8;
31 using base::android::JavaByteArrayToByteVector; 32 using base::android::JavaByteArrayToByteVector;
32 using base::android::ScopedJavaLocalRef; 33 using base::android::ScopedJavaLocalRef;
33 34
34 namespace media { 35 namespace media {
35 36
36 namespace { 37 namespace {
37 38
38 // DrmBridge supports session expiration event but doesn't provide detailed 39 // DrmBridge supports session expiration event but doesn't provide detailed
39 // status for each key ID, which is required by the EME spec. Use a dummy key ID 40 // status for each key ID, which is required by the EME spec. Use a dummy key ID
40 // here to report session expiration info. 41 // here to report session expiration info.
41 const char kDummyKeyId[] = "Dummy Key Id"; 42 const char kDummyKeyId[] = "Dummy Key Id";
42 43
43 uint32 ReadUint32(const uint8_t* data) {
44 uint32 value = 0;
45 for (int i = 0; i < 4; ++i)
46 value = (value << 8) | data[i];
47 return value;
48 }
49
50 uint64 ReadUint64(const uint8_t* data) {
51 uint64 value = 0;
52 for (int i = 0; i < 8; ++i)
53 value = (value << 8) | data[i];
54 return value;
55 }
56
57 // Returns string session ID from jbyteArray (byte[] in Java). 44 // Returns string session ID from jbyteArray (byte[] in Java).
58 std::string GetSessionId(JNIEnv* env, jbyteArray j_session_id) { 45 std::string GetSessionId(JNIEnv* env, jbyteArray j_session_id) {
59 std::vector<uint8> session_id_vector; 46 std::vector<uint8> session_id_vector;
60 JavaByteArrayToByteVector(env, j_session_id, &session_id_vector); 47 JavaByteArrayToByteVector(env, j_session_id, &session_id_vector);
61 return std::string(session_id_vector.begin(), session_id_vector.end()); 48 return std::string(session_id_vector.begin(), session_id_vector.end());
62 } 49 }
63 50
64 // The structure of an ISO CENC Protection System Specific Header (PSSH) box is
65 // as follows. (See ISO/IEC FDIS 23001-7:2011(E).)
66 // Note: ISO boxes use big-endian values.
67 //
68 // PSSH {
69 // uint32 Size
70 // uint32 Type
71 // uint64 LargeSize # Field is only present if value(Size) == 1.
72 // uint32 VersionAndFlags
73 // uint8[16] SystemId
74 // uint32 DataSize
75 // uint8[DataSize] Data
76 // }
77 const int kBoxHeaderSize = 8; // Box's header contains Size and Type.
78 const int kBoxLargeSizeSize = 8;
79 const int kPsshVersionFlagSize = 4;
80 const int kPsshSystemIdSize = 16;
81 const int kPsshDataSizeSize = 4;
82 const uint32 kTencType = 0x74656e63;
83 const uint32 kPsshType = 0x70737368;
84 const uint8 kWidevineUuid[16] = { 51 const uint8 kWidevineUuid[16] = {
85 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, 52 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
86 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; 53 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
87 54
88 typedef std::vector<uint8> UUID;
89
90 // Tries to find a PSSH box whose "SystemId" is |uuid| in |data|, parses the
91 // "Data" of the box and put it in |pssh_data|. Returns true if such a box is
92 // found and successfully parsed. Returns false otherwise.
93 // Notes:
94 // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box
95 // will be set in |pssh_data|.
96 // 2, Only PSSH and TENC boxes are allowed in |data|. TENC boxes are skipped.
97 bool GetPsshData(const std::vector<uint8_t>& data,
98 const UUID& uuid,
99 std::vector<uint8>* pssh_data) {
100 int bytes_left = base::checked_cast<int>(data.size());
101 const uint8_t* cur = &data[0];
102 const uint8_t* data_end = cur + bytes_left;
103
104 while (bytes_left > 0) {
105 const uint8* box_head = cur;
106
107 if (bytes_left < kBoxHeaderSize)
108 return false;
109
110 uint64_t box_size = ReadUint32(cur);
111 uint32 type = ReadUint32(cur + 4);
112 cur += kBoxHeaderSize;
113 bytes_left -= kBoxHeaderSize;
114
115 if (box_size == 1) { // LargeSize is present.
116 if (bytes_left < kBoxLargeSizeSize)
117 return false;
118
119 box_size = ReadUint64(cur);
120 cur += kBoxLargeSizeSize;
121 bytes_left -= kBoxLargeSizeSize;
122 } else if (box_size == 0) {
123 box_size = bytes_left + kBoxHeaderSize;
124 }
125
126 const uint8* box_end = box_head + box_size;
127 if (data_end < box_end)
128 return false;
129
130 if (type == kTencType) {
131 // Skip 'tenc' box.
132 cur = box_end;
133 bytes_left = data_end - cur;
134 continue;
135 } else if (type != kPsshType) {
136 return false;
137 }
138
139 const int kPsshBoxMinimumSize =
140 kPsshVersionFlagSize + kPsshSystemIdSize + kPsshDataSizeSize;
141 if (box_end < cur + kPsshBoxMinimumSize)
142 return false;
143
144 uint32 version_and_flags = ReadUint32(cur);
145 cur += kPsshVersionFlagSize;
146 bytes_left -= kPsshVersionFlagSize;
147 if (version_and_flags != 0)
148 return false;
149
150 DCHECK_GE(bytes_left, kPsshSystemIdSize);
151 if (!std::equal(uuid.begin(), uuid.end(), cur)) {
152 cur = box_end;
153 bytes_left = data_end - cur;
154 continue;
155 }
156
157 cur += kPsshSystemIdSize;
158 bytes_left -= kPsshSystemIdSize;
159
160 uint32 data_size = ReadUint32(cur);
161 cur += kPsshDataSizeSize;
162 bytes_left -= kPsshDataSizeSize;
163
164 if (box_end < cur + data_size)
165 return false;
166
167 pssh_data->assign(cur, cur + data_size);
168 return true;
169 }
170
171 return false;
172 }
173
174 // Convert |init_data_type| to a string supported by MediaDRM. 55 // Convert |init_data_type| to a string supported by MediaDRM.
175 // "audio"/"video" does not matter, so use "video". 56 // "audio"/"video" does not matter, so use "video".
176 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) { 57 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) {
177 // TODO(jrummell): API level >=20 supports "webm" and "cenc", so switch 58 // TODO(jrummell): API level >=20 supports "webm" and "cenc", so switch
178 // to those strings. 59 // to those strings.
179 switch (init_data_type) { 60 switch (init_data_type) {
180 case media::EmeInitDataType::WEBM: 61 case media::EmeInitDataType::WEBM:
181 return "video/webm"; 62 return "video/webm";
182 case media::EmeInitDataType::CENC: 63 case media::EmeInitDataType::CENC:
183 return "video/mp4"; 64 return "video/mp4";
184 default: 65 default:
185 NOTREACHED(); 66 NOTREACHED();
186 return "video/unknown"; 67 return "video/unknown";
187 } 68 }
188 } 69 }
189 70
190 class KeySystemUuidManager { 71 class KeySystemManager {
xhwang 2015/04/28 05:25:11 I wonder whether we still need this class, which l
xhwang 2015/04/28 17:06:10 If not, maybe we can do something like: MediaClie
gunsch 2015/04/28 18:50:51 Right now, I assume that MediaClientAndroid is opt
xhwang 2015/04/28 19:00:38 Agreed. That makes sense and is good layering. Ho
gunsch 2015/04/28 19:56:32 I guess I'm unclear on the API you're asking for:
191 public: 72 public:
192 KeySystemUuidManager(); 73 KeySystemManager();
193 UUID GetUUID(const std::string& key_system); 74 UUID GetUUID(const std::string& key_system);
194 void AddMapping(const std::string& key_system, const UUID& uuid);
195 std::vector<std::string> GetPlatformKeySystemNames(); 75 std::vector<std::string> GetPlatformKeySystemNames();
196 76
197 private: 77 private:
198 typedef base::hash_map<std::string, UUID> KeySystemUuidMap; 78 typedef base::hash_map<std::string, UUID> KeySystemUuidMap;
199 79
80 void AddMappingsFromMediaClient();
81
200 KeySystemUuidMap key_system_uuid_map_; 82 KeySystemUuidMap key_system_uuid_map_;
201 83
202 DISALLOW_COPY_AND_ASSIGN(KeySystemUuidManager); 84 DISALLOW_COPY_AND_ASSIGN(KeySystemManager);
203 }; 85 };
204 86
205 KeySystemUuidManager::KeySystemUuidManager() { 87 KeySystemManager::KeySystemManager() {
206 // Widevine is always supported in Android. 88 // Widevine is always supported in Android.
207 key_system_uuid_map_[kWidevineKeySystem] = 89 key_system_uuid_map_[kWidevineKeySystem] =
208 UUID(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); 90 UUID(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid));
91 AddMappingsFromMediaClient();
209 } 92 }
210 93
211 UUID KeySystemUuidManager::GetUUID(const std::string& key_system) { 94 UUID KeySystemManager::GetUUID(const std::string& key_system) {
212 KeySystemUuidMap::iterator it = key_system_uuid_map_.find(key_system); 95 KeySystemUuidMap::iterator it = key_system_uuid_map_.find(key_system);
213 if (it == key_system_uuid_map_.end()) 96 if (it == key_system_uuid_map_.end())
214 return UUID(); 97 return UUID();
215 return it->second; 98 return it->second;
216 } 99 }
217 100
218 void KeySystemUuidManager::AddMapping(const std::string& key_system, 101 void KeySystemManager::AddMappingsFromMediaClient() {
219 const UUID& uuid) { 102 MediaClientAndroid* client = GetMediaClientAndroid();
220 KeySystemUuidMap::iterator it = key_system_uuid_map_.find(key_system); 103 if (!client)
221 DCHECK(it == key_system_uuid_map_.end())
222 << "Shouldn't overwrite an existing key system.";
223 if (it != key_system_uuid_map_.end())
224 return; 104 return;
225 key_system_uuid_map_[key_system] = uuid; 105 base::hash_map<std::string, UUID> mappings =
xhwang 2015/04/28 17:06:10 Use KeySystemUuidMap
gunsch 2015/04/28 18:50:51 Done.
106 client->GetKeySystemUUIDMappings();
107 for (const auto& mapping : mappings) {
108 key_system_uuid_map_[mapping.first] = mapping.second;
109 }
226 } 110 }
227 111
228 std::vector<std::string> KeySystemUuidManager::GetPlatformKeySystemNames() { 112 std::vector<std::string> KeySystemManager::GetPlatformKeySystemNames() {
229 std::vector<std::string> key_systems; 113 std::vector<std::string> key_systems;
230 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin(); 114 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin();
231 it != key_system_uuid_map_.end(); ++it) { 115 it != key_system_uuid_map_.end(); ++it) {
232 // Rule out the key system handled by Chrome explicitly. 116 // Rule out the key system handled by Chrome explicitly.
233 if (it->first != kWidevineKeySystem) 117 if (it->first != kWidevineKeySystem)
234 key_systems.push_back(it->first); 118 key_systems.push_back(it->first);
235 } 119 }
236 return key_systems; 120 return key_systems;
237 } 121 }
238 122
239 base::LazyInstance<KeySystemUuidManager>::Leaky g_key_system_uuid_manager = 123 base::LazyInstance<KeySystemManager>::Leaky g_key_system_manager =
240 LAZY_INSTANCE_INITIALIZER; 124 LAZY_INSTANCE_INITIALIZER;
241 125
242 // Checks whether |key_system| is supported with |container_mime_type|. Only 126 // Checks whether |key_system| is supported with |container_mime_type|. Only
243 // checks |key_system| support if |container_mime_type| is empty. 127 // checks |key_system| support if |container_mime_type| is empty.
244 // TODO(xhwang): The |container_mime_type| is not the same as contentType in 128 // TODO(xhwang): The |container_mime_type| is not the same as contentType in
245 // the EME spec. Revisit this once the spec issue with initData type is 129 // the EME spec. Revisit this once the spec issue with initData type is
246 // resolved. 130 // resolved.
247 bool IsKeySystemSupportedWithTypeImpl(const std::string& key_system, 131 bool IsKeySystemSupportedWithTypeImpl(const std::string& key_system,
248 const std::string& container_mime_type) { 132 const std::string& container_mime_type) {
249 if (!MediaDrmBridge::IsAvailable()) 133 if (!MediaDrmBridge::IsAvailable())
250 return false; 134 return false;
251 135
252 UUID scheme_uuid = g_key_system_uuid_manager.Get().GetUUID(key_system); 136 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system);
253 if (scheme_uuid.empty()) 137 if (scheme_uuid.empty())
254 return false; 138 return false;
255 139
256 JNIEnv* env = AttachCurrentThread(); 140 JNIEnv* env = AttachCurrentThread();
257 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = 141 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid =
258 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); 142 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size());
259 ScopedJavaLocalRef<jstring> j_container_mime_type = 143 ScopedJavaLocalRef<jstring> j_container_mime_type =
260 ConvertUTF8ToJavaString(env, container_mime_type); 144 ConvertUTF8ToJavaString(env, container_mime_type);
261 return Java_MediaDrmBridge_isCryptoSchemeSupported( 145 return Java_MediaDrmBridge_isCryptoSchemeSupported(
262 env, j_scheme_uuid.obj(), j_container_mime_type.obj()); 146 env, j_scheme_uuid.obj(), j_container_mime_type.obj());
(...skipping 17 matching lines...) Expand all
280 case MediaDrmBridge::SECURITY_LEVEL_1: 164 case MediaDrmBridge::SECURITY_LEVEL_1:
281 return "L1"; 165 return "L1";
282 case MediaDrmBridge::SECURITY_LEVEL_3: 166 case MediaDrmBridge::SECURITY_LEVEL_3:
283 return "L3"; 167 return "L3";
284 } 168 }
285 return ""; 169 return "";
286 } 170 }
287 171
288 } // namespace 172 } // namespace
289 173
290 // Called by Java.
291 static void AddKeySystemUuidMapping(JNIEnv* env,
292 jclass clazz,
293 jstring j_key_system,
294 jobject j_buffer) {
295 std::string key_system = ConvertJavaStringToUTF8(env, j_key_system);
296 uint8* buffer = static_cast<uint8*>(env->GetDirectBufferAddress(j_buffer));
297 UUID uuid(buffer, buffer + 16);
298 g_key_system_uuid_manager.Get().AddMapping(key_system, uuid);
299 }
300
301 // static 174 // static
302 bool MediaDrmBridge::IsAvailable() { 175 bool MediaDrmBridge::IsAvailable() {
303 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19) 176 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19)
304 return false; 177 return false;
305 178
306 int32 os_major_version = 0; 179 int32 os_major_version = 0;
307 int32 os_minor_version = 0; 180 int32 os_minor_version = 0;
308 int32 os_bugfix_version = 0; 181 int32 os_bugfix_version = 0;
309 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, 182 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
310 &os_minor_version, 183 &os_minor_version,
311 &os_bugfix_version); 184 &os_bugfix_version);
312 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) 185 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0)
313 return false; 186 return false;
314 187
315 return true; 188 return true;
316 } 189 }
317 190
318 // TODO(ddorwin): This is specific to Widevine. http://crbug.com/459400 191 // TODO(ddorwin): This is specific to Widevine. http://crbug.com/459400
319 // static 192 // static
320 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { 193 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) {
321 DCHECK(IsAvailable()); 194 DCHECK(IsAvailable());
322 return SECURITY_LEVEL_1 == security_level; 195 return SECURITY_LEVEL_1 == security_level;
323 } 196 }
324 197
325 // static 198 // static
326 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { 199 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() {
327 return g_key_system_uuid_manager.Get().GetPlatformKeySystemNames(); 200 return g_key_system_manager.Get().GetPlatformKeySystemNames();
328 } 201 }
329 202
330 // static 203 // static
331 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { 204 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) {
332 DCHECK(!key_system.empty()); 205 DCHECK(!key_system.empty());
333 return IsKeySystemSupportedWithTypeImpl(key_system, ""); 206 return IsKeySystemSupportedWithTypeImpl(key_system, "");
334 } 207 }
335 208
336 // static 209 // static
337 bool MediaDrmBridge::IsKeySystemSupportedWithType( 210 bool MediaDrmBridge::IsKeySystemSupportedWithType(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 const std::string& key_system, 251 const std::string& key_system,
379 const SessionMessageCB& session_message_cb, 252 const SessionMessageCB& session_message_cb,
380 const SessionClosedCB& session_closed_cb, 253 const SessionClosedCB& session_closed_cb,
381 const LegacySessionErrorCB& legacy_session_error_cb, 254 const LegacySessionErrorCB& legacy_session_error_cb,
382 const SessionKeysChangeCB& session_keys_change_cb, 255 const SessionKeysChangeCB& session_keys_change_cb,
383 const SessionExpirationUpdateCB& /* session_expiration_update_cb */) { 256 const SessionExpirationUpdateCB& /* session_expiration_update_cb */) {
384 scoped_ptr<MediaDrmBridge> media_drm_bridge; 257 scoped_ptr<MediaDrmBridge> media_drm_bridge;
385 if (!IsAvailable()) 258 if (!IsAvailable())
386 return media_drm_bridge.Pass(); 259 return media_drm_bridge.Pass();
387 260
388 UUID scheme_uuid = g_key_system_uuid_manager.Get().GetUUID(key_system); 261 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system);
389 if (scheme_uuid.empty()) 262 if (scheme_uuid.empty())
390 return media_drm_bridge.Pass(); 263 return media_drm_bridge.Pass();
391 264
392 media_drm_bridge.reset( 265 media_drm_bridge.reset(
393 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, 266 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb,
394 legacy_session_error_cb, session_keys_change_cb)); 267 legacy_session_error_cb, session_keys_change_cb));
395 268
396 if (media_drm_bridge->j_media_drm_.is_null()) 269 if (media_drm_bridge->j_media_drm_.is_null())
397 media_drm_bridge.reset(); 270 media_drm_bridge.reset();
398 271
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 DVLOG(1) << __FUNCTION__; 315 DVLOG(1) << __FUNCTION__;
443 316
444 if (session_type != media::MediaKeys::TEMPORARY_SESSION) { 317 if (session_type != media::MediaKeys::TEMPORARY_SESSION) {
445 promise->reject(NOT_SUPPORTED_ERROR, 0, 318 promise->reject(NOT_SUPPORTED_ERROR, 0,
446 "Only the temporary session type is supported."); 319 "Only the temporary session type is supported.");
447 return; 320 return;
448 } 321 }
449 322
450 JNIEnv* env = AttachCurrentThread(); 323 JNIEnv* env = AttachCurrentThread();
451 ScopedJavaLocalRef<jbyteArray> j_init_data; 324 ScopedJavaLocalRef<jbyteArray> j_init_data;
325 ScopedJavaLocalRef<jobjectArray> j_optional_parameters;
452 326
453 // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as 327 MediaClientAndroid* client = GetMediaClientAndroid();
454 // the init data when using MP4 container. 328 if (client) {
455 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && 329 MediaDrmBridgeDelegate* delegate =
456 init_data_type == media::EmeInitDataType::CENC) { 330 client->GetMediaDrmBridgeDelegate(scheme_uuid_);
457 std::vector<uint8> pssh_data; 331 if (delegate) {
458 if (!GetPsshData(init_data, scheme_uuid_, &pssh_data)) { 332 std::vector<uint8> init_data_from_delegate;
459 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid PSSH data."); 333 std::vector<std::string> optional_parameters_from_delegate;
460 return; 334 if (!delegate->OnCreateSession(init_data_type, init_data,
335 &init_data_from_delegate,
336 &optional_parameters_from_delegate)) {
337 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid init data.");
338 }
339 j_init_data = base::android::ToJavaByteArray(
340 env, vector_as_array(&init_data_from_delegate),
341 init_data_from_delegate.size());
342 if (!optional_parameters_from_delegate.empty()) {
343 j_optional_parameters = base::android::ToJavaArrayOfStrings(
344 env, optional_parameters_from_delegate);
345 }
461 } 346 }
462 j_init_data = base::android::ToJavaByteArray( 347 }
463 env, vector_as_array(&pssh_data), pssh_data.size()); 348
464 } else { 349 if (j_init_data.is_null()) {
465 j_init_data = base::android::ToJavaByteArray( 350 j_init_data = base::android::ToJavaByteArray(
466 env, vector_as_array(&init_data), init_data.size()); 351 env, vector_as_array(&init_data), init_data.size());
467 } 352 }
468 353
469 ScopedJavaLocalRef<jstring> j_mime = 354 ScopedJavaLocalRef<jstring> j_mime =
470 ConvertUTF8ToJavaString(env, ConvertInitDataType(init_data_type)); 355 ConvertUTF8ToJavaString(env, ConvertInitDataType(init_data_type));
471 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); 356 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass());
472 Java_MediaDrmBridge_createSession(env, j_media_drm_.obj(), j_init_data.obj(), 357 Java_MediaDrmBridge_createSession(env, j_media_drm_.obj(), j_init_data.obj(),
473 j_mime.obj(), promise_id); 358 j_mime.obj(), j_optional_parameters.obj(),
359 promise_id);
474 } 360 }
475 361
476 void MediaDrmBridge::LoadSession( 362 void MediaDrmBridge::LoadSession(
477 SessionType session_type, 363 SessionType session_type,
478 const std::string& session_id, 364 const std::string& session_id,
479 scoped_ptr<media::NewSessionCdmPromise> promise) { 365 scoped_ptr<media::NewSessionCdmPromise> promise) {
480 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); 366 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported.");
481 } 367 }
482 368
483 void MediaDrmBridge::UpdateSession( 369 void MediaDrmBridge::UpdateSession(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 JNIEnv* env = AttachCurrentThread(); 543 JNIEnv* env = AttachCurrentThread();
658 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); 544 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj());
659 } 545 }
660 546
661 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( 547 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(
662 JNIEnv* env, jobject, bool success) { 548 JNIEnv* env, jobject, bool success) {
663 base::ResetAndReturn(&reset_credentials_cb_).Run(success); 549 base::ResetAndReturn(&reset_credentials_cb_).Run(success);
664 } 550 }
665 551
666 } // namespace media 552 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698