OLD | NEW |
---|---|
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/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/sys_byteorder.h" | 19 #include "base/sys_byteorder.h" |
20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
21 #include "jni/MediaDrmBridge_jni.h" | 21 #include "jni/MediaDrmBridge_jni.h" |
22 #include "media/base/cdm_key_information.h" | |
22 | 23 |
23 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 24 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
24 | 25 |
25 using base::android::AttachCurrentThread; | 26 using base::android::AttachCurrentThread; |
26 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
27 using base::android::ConvertJavaStringToUTF8; | 28 using base::android::ConvertJavaStringToUTF8; |
28 using base::android::JavaByteArrayToByteVector; | 29 using base::android::JavaByteArrayToByteVector; |
29 using base::android::ScopedJavaLocalRef; | 30 using base::android::ScopedJavaLocalRef; |
30 | 31 |
31 namespace media { | 32 namespace media { |
(...skipping 29 matching lines...) Expand all Loading... | |
61 const int kBoxLargeSizeSize = 8; | 62 const int kBoxLargeSizeSize = 8; |
62 const int kPsshVersionFlagSize = 4; | 63 const int kPsshVersionFlagSize = 4; |
63 const int kPsshSystemIdSize = 16; | 64 const int kPsshSystemIdSize = 16; |
64 const int kPsshDataSizeSize = 4; | 65 const int kPsshDataSizeSize = 4; |
65 const uint32 kTencType = 0x74656e63; | 66 const uint32 kTencType = 0x74656e63; |
66 const uint32 kPsshType = 0x70737368; | 67 const uint32 kPsshType = 0x70737368; |
67 const uint8 kWidevineUuid[16] = { | 68 const uint8 kWidevineUuid[16] = { |
68 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 69 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
69 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 70 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
70 | 71 |
72 // DrmBridge supports session expiration event but doesn't provide detailed | |
73 // status for each key ID, which is required by the EME spec. Use a dummy key ID | |
74 // here to report session expiration info. | |
75 const char kDummyKeyId[] = "Dummy Key Id"; | |
76 | |
71 typedef std::vector<uint8> UUID; | 77 typedef std::vector<uint8> UUID; |
72 | 78 |
73 class KeySystemUuidManager { | 79 class KeySystemUuidManager { |
74 public: | 80 public: |
75 KeySystemUuidManager(); | 81 KeySystemUuidManager(); |
76 UUID GetUUID(const std::string& key_system); | 82 UUID GetUUID(const std::string& key_system); |
77 void AddMapping(const std::string& key_system, const UUID& uuid); | 83 void AddMapping(const std::string& key_system, const UUID& uuid); |
78 std::vector<std::string> GetPlatformKeySystemNames(); | 84 std::vector<std::string> GetPlatformKeySystemNames(); |
79 | 85 |
80 private: | 86 private: |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 252 |
247 JNIEnv* env = AttachCurrentThread(); | 253 JNIEnv* env = AttachCurrentThread(); |
248 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 254 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
249 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 255 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
250 ScopedJavaLocalRef<jstring> j_container_mime_type = | 256 ScopedJavaLocalRef<jstring> j_container_mime_type = |
251 ConvertUTF8ToJavaString(env, container_mime_type); | 257 ConvertUTF8ToJavaString(env, container_mime_type); |
252 return Java_MediaDrmBridge_isCryptoSchemeSupported( | 258 return Java_MediaDrmBridge_isCryptoSchemeSupported( |
253 env, j_scheme_uuid.obj(), j_container_mime_type.obj()); | 259 env, j_scheme_uuid.obj(), j_container_mime_type.obj()); |
254 } | 260 } |
255 | 261 |
262 // Returns string session ID from jbyteArray (byte[] in Java). | |
263 static std::string GetSessionId(JNIEnv* env, jbyteArray j_session_id) { | |
264 std::vector<uint8> session_id_vector; | |
265 JavaByteArrayToByteVector(env, j_session_id, &session_id_vector); | |
266 return std::string(session_id_vector.begin(), session_id_vector.end()); | |
267 } | |
268 | |
269 // Similar to string_as_array() in stl_util.h. Cannot use string_as_array() | |
270 // directly because we are dealing with const strings. | |
271 static const uint8_t* StringAsArray(const std::string& str) { | |
272 return str.empty() ? nullptr | |
273 : reinterpret_cast<const uint8_t*>(&*str.begin()); | |
jrummell
2015/01/15 18:56:23
std::string has const char* data() const; Can you
xhwang
2015/01/15 19:37:26
Good point. I thought this would avoid a possible
| |
274 } | |
275 | |
256 // static | 276 // static |
257 bool MediaDrmBridge::IsAvailable() { | 277 bool MediaDrmBridge::IsAvailable() { |
258 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19) | 278 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19) |
259 return false; | 279 return false; |
260 | 280 |
261 int32 os_major_version = 0; | 281 int32 os_major_version = 0; |
262 int32 os_minor_version = 0; | 282 int32 os_minor_version = 0; |
263 int32 os_bugfix_version = 0; | 283 int32 os_bugfix_version = 0; |
264 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 284 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
265 &os_minor_version, | 285 &os_minor_version, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 const std::string& key_system, | 335 const std::string& key_system, |
316 const std::string& container_mime_type) { | 336 const std::string& container_mime_type) { |
317 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 337 DCHECK(!key_system.empty() && !container_mime_type.empty()); |
318 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); | 338 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); |
319 } | 339 } |
320 | 340 |
321 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { | 341 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { |
322 return RegisterNativesImpl(env); | 342 return RegisterNativesImpl(env); |
323 } | 343 } |
324 | 344 |
325 MediaDrmBridge::MediaDrmBridge(const std::vector<uint8>& scheme_uuid, | 345 MediaDrmBridge::MediaDrmBridge( |
326 const SessionCreatedCB& session_created_cb, | 346 const std::vector<uint8>& scheme_uuid, |
327 const SessionMessageCB& session_message_cb, | 347 const SessionMessageCB& session_message_cb, |
328 const SessionReadyCB& session_ready_cb, | 348 const SessionClosedCB& session_closed_cb, |
329 const SessionClosedCB& session_closed_cb, | 349 const SessionErrorCB& session_error_cb, |
330 const SessionErrorCB& session_error_cb) | 350 const SessionKeysChangeCB& session_keys_change_cb) |
331 : scheme_uuid_(scheme_uuid), | 351 : scheme_uuid_(scheme_uuid), |
332 session_created_cb_(session_created_cb), | |
333 session_message_cb_(session_message_cb), | 352 session_message_cb_(session_message_cb), |
334 session_ready_cb_(session_ready_cb), | |
335 session_closed_cb_(session_closed_cb), | 353 session_closed_cb_(session_closed_cb), |
336 session_error_cb_(session_error_cb) { | 354 session_error_cb_(session_error_cb), |
355 session_keys_change_cb_(session_keys_change_cb) { | |
337 JNIEnv* env = AttachCurrentThread(); | 356 JNIEnv* env = AttachCurrentThread(); |
338 CHECK(env); | 357 CHECK(env); |
339 | 358 |
340 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 359 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
341 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 360 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
342 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 361 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
343 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 362 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
344 } | 363 } |
345 | 364 |
346 MediaDrmBridge::~MediaDrmBridge() { | 365 MediaDrmBridge::~MediaDrmBridge() { |
347 JNIEnv* env = AttachCurrentThread(); | 366 JNIEnv* env = AttachCurrentThread(); |
348 player_tracker_.NotifyCdmUnset(); | 367 player_tracker_.NotifyCdmUnset(); |
349 if (!j_media_drm_.is_null()) | 368 if (!j_media_drm_.is_null()) |
350 Java_MediaDrmBridge_release(env, j_media_drm_.obj()); | 369 Java_MediaDrmBridge_release(env, j_media_drm_.obj()); |
351 } | 370 } |
352 | 371 |
353 // static | 372 // static |
373 // TODO(xhwang): Enable SessionExpirationUpdateCB when it is supported. | |
354 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( | 374 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( |
355 const std::string& key_system, | 375 const std::string& key_system, |
356 const SessionCreatedCB& session_created_cb, | |
357 const SessionMessageCB& session_message_cb, | 376 const SessionMessageCB& session_message_cb, |
358 const SessionReadyCB& session_ready_cb, | |
359 const SessionClosedCB& session_closed_cb, | 377 const SessionClosedCB& session_closed_cb, |
360 const SessionErrorCB& session_error_cb) { | 378 const SessionErrorCB& session_error_cb, |
379 const SessionKeysChangeCB& session_keys_change_cb, | |
380 const SessionExpirationUpdateCB& /* session_expiration_update_cb */) { | |
361 scoped_ptr<MediaDrmBridge> media_drm_bridge; | 381 scoped_ptr<MediaDrmBridge> media_drm_bridge; |
362 if (!IsAvailable()) | 382 if (!IsAvailable()) |
363 return media_drm_bridge.Pass(); | 383 return media_drm_bridge.Pass(); |
364 | 384 |
365 UUID scheme_uuid = g_key_system_uuid_manager.Get().GetUUID(key_system); | 385 UUID scheme_uuid = g_key_system_uuid_manager.Get().GetUUID(key_system); |
366 if (scheme_uuid.empty()) | 386 if (scheme_uuid.empty()) |
367 return media_drm_bridge.Pass(); | 387 return media_drm_bridge.Pass(); |
368 | 388 |
369 media_drm_bridge.reset(new MediaDrmBridge(scheme_uuid, | 389 media_drm_bridge.reset(new MediaDrmBridge(scheme_uuid, session_message_cb, |
370 session_created_cb, | 390 session_closed_cb, session_error_cb, |
371 session_message_cb, | 391 session_keys_change_cb)); |
372 session_ready_cb, | |
373 session_closed_cb, | |
374 session_error_cb)); | |
375 | 392 |
376 if (media_drm_bridge->j_media_drm_.is_null()) | 393 if (media_drm_bridge->j_media_drm_.is_null()) |
377 media_drm_bridge.reset(); | 394 media_drm_bridge.reset(); |
378 | 395 |
379 return media_drm_bridge.Pass(); | 396 return media_drm_bridge.Pass(); |
380 } | 397 } |
381 | 398 |
382 // static | 399 // static |
383 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateSessionless( | 400 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateSessionless( |
jrummell
2015/01/15 18:56:23
less? Is this just the old code needed a different
xhwang
2015/01/15 19:37:26
lol, I agree this name is confusing. Changed to Cr
| |
384 const std::string& key_system) { | 401 const std::string& key_system) { |
385 return MediaDrmBridge::Create(key_system, | 402 return MediaDrmBridge::Create( |
386 SessionCreatedCB(), | 403 key_system, SessionMessageCB(), SessionClosedCB(), SessionErrorCB(), |
387 SessionMessageCB(), | 404 SessionKeysChangeCB(), SessionExpirationUpdateCB()); |
388 SessionReadyCB(), | |
389 SessionClosedCB(), | |
390 SessionErrorCB()); | |
391 } | 405 } |
392 | 406 |
393 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { | 407 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { |
394 JNIEnv* env = AttachCurrentThread(); | 408 JNIEnv* env = AttachCurrentThread(); |
395 | 409 |
396 std::string security_level_str = GetSecurityLevelString(security_level); | 410 std::string security_level_str = GetSecurityLevelString(security_level); |
397 if (security_level_str.empty()) | 411 if (security_level_str.empty()) |
398 return false; | 412 return false; |
399 | 413 |
400 ScopedJavaLocalRef<jstring> j_security_level = | 414 ScopedJavaLocalRef<jstring> j_security_level = |
401 ConvertUTF8ToJavaString(env, security_level_str); | 415 ConvertUTF8ToJavaString(env, security_level_str); |
402 return Java_MediaDrmBridge_setSecurityLevel( | 416 return Java_MediaDrmBridge_setSecurityLevel( |
403 env, j_media_drm_.obj(), j_security_level.obj()); | 417 env, j_media_drm_.obj(), j_security_level.obj()); |
404 } | 418 } |
405 | 419 |
406 bool MediaDrmBridge::CreateSession(uint32 session_id, | 420 void MediaDrmBridge::SetServerCertificate( |
407 const std::string& content_type, | 421 const uint8* certificate_data, |
408 const uint8* init_data, | 422 int certificate_data_length, |
409 int init_data_length) { | 423 scoped_ptr<media::SimpleCdmPromise> promise) { |
424 promise->reject(NOT_SUPPORTED_ERROR, 0, | |
425 "SetServerCertificate() is not supported."); | |
426 } | |
427 | |
428 void MediaDrmBridge::CreateSessionAndGenerateRequest( | |
429 SessionType session_type, | |
430 const std::string& init_data_type, | |
431 const uint8* init_data, | |
432 int init_data_length, | |
433 scoped_ptr<media::NewSessionCdmPromise> promise) { | |
410 DVLOG(1) << __FUNCTION__; | 434 DVLOG(1) << __FUNCTION__; |
411 | 435 |
412 DCHECK(!session_created_cb_.is_null()) | 436 if (session_type != media::MediaKeys::TEMPORARY_SESSION) { |
413 << "CreateSession called on a sessionless MediaDrmBridge object."; | 437 promise->reject(NOT_SUPPORTED_ERROR, 0, |
438 "Only temporary session is supported."); | |
ddorwin
2015/01/15 17:36:52
ditto
xhwang
2015/01/15 19:03:44
Done.
| |
439 return; | |
440 } | |
414 | 441 |
415 JNIEnv* env = AttachCurrentThread(); | 442 JNIEnv* env = AttachCurrentThread(); |
416 ScopedJavaLocalRef<jbyteArray> j_init_data; | 443 ScopedJavaLocalRef<jbyteArray> j_init_data; |
417 // Caller should always use "video/*" content types. | 444 // Caller should always use "video/*" content types. |
418 DCHECK_EQ(0u, content_type.find("video/")); | 445 DCHECK_EQ(0u, init_data_type.find("video/")); |
419 | 446 |
420 // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as | 447 // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as |
421 // the init data when using MP4 container. | 448 // the init data when using MP4 container. |
422 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && | 449 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && |
423 content_type == "video/mp4") { | 450 init_data_type == "video/mp4") { |
424 std::vector<uint8> pssh_data; | 451 std::vector<uint8> pssh_data; |
425 if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) | 452 if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) { |
426 return false; | 453 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid PSSH data."); |
454 return; | |
455 } | |
427 j_init_data = | 456 j_init_data = |
428 base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); | 457 base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); |
429 } else { | 458 } else { |
430 j_init_data = | 459 j_init_data = |
431 base::android::ToJavaByteArray(env, init_data, init_data_length); | 460 base::android::ToJavaByteArray(env, init_data, init_data_length); |
432 } | 461 } |
433 | 462 |
434 ScopedJavaLocalRef<jstring> j_mime = | 463 ScopedJavaLocalRef<jstring> j_mime = |
435 ConvertUTF8ToJavaString(env, content_type); | 464 ConvertUTF8ToJavaString(env, init_data_type); |
436 Java_MediaDrmBridge_createSession( | 465 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); |
437 env, j_media_drm_.obj(), session_id, j_init_data.obj(), j_mime.obj()); | 466 Java_MediaDrmBridge_createSession(env, j_media_drm_.obj(), j_init_data.obj(), |
438 return true; | 467 j_mime.obj(), promise_id); |
439 } | 468 } |
440 | 469 |
441 void MediaDrmBridge::LoadSession(uint32 session_id, | 470 void MediaDrmBridge::LoadSession( |
442 const std::string& web_session_id) { | 471 SessionType session_type, |
443 // MediaDrmBridge doesn't support loading sessions. | 472 const std::string& session_id, |
444 NOTREACHED(); | 473 scoped_ptr<media::NewSessionCdmPromise> promise) { |
474 NOTREACHED() << "Persistent session not supported"; | |
475 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); | |
qinmin
2015/01/15 18:17:25
do we need this if it is NOTREACHED?
xhwang
2015/01/15 19:03:44
When we use MediaDrmBridge with mojo, we need to r
| |
445 } | 476 } |
446 | 477 |
447 void MediaDrmBridge::UpdateSession(uint32 session_id, | 478 void MediaDrmBridge::UpdateSession( |
448 const uint8* response, | 479 const std::string& session_id, |
449 int response_length) { | 480 const uint8* response, |
481 int response_length, | |
482 scoped_ptr<media::SimpleCdmPromise> promise) { | |
450 DVLOG(1) << __FUNCTION__; | 483 DVLOG(1) << __FUNCTION__; |
451 | 484 |
452 DCHECK(!session_ready_cb_.is_null()) | |
453 << __FUNCTION__ << " called on a sessionless MediaDrmBridge object."; | |
454 | |
455 JNIEnv* env = AttachCurrentThread(); | 485 JNIEnv* env = AttachCurrentThread(); |
456 ScopedJavaLocalRef<jbyteArray> j_response = | 486 ScopedJavaLocalRef<jbyteArray> j_response = |
457 base::android::ToJavaByteArray(env, response, response_length); | 487 base::android::ToJavaByteArray(env, response, response_length); |
458 Java_MediaDrmBridge_updateSession( | 488 ScopedJavaLocalRef<jbyteArray> j_session_id = base::android::ToJavaByteArray( |
459 env, j_media_drm_.obj(), session_id, j_response.obj()); | 489 env, StringAsArray(session_id), session_id.size()); |
490 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | |
491 Java_MediaDrmBridge_updateSession(env, j_media_drm_.obj(), j_session_id.obj(), | |
492 j_response.obj(), promise_id); | |
460 } | 493 } |
461 | 494 |
462 void MediaDrmBridge::ReleaseSession(uint32 session_id) { | 495 void MediaDrmBridge::CloseSession(const std::string& session_id, |
496 scoped_ptr<media::SimpleCdmPromise> promise) { | |
463 DVLOG(1) << __FUNCTION__; | 497 DVLOG(1) << __FUNCTION__; |
498 JNIEnv* env = AttachCurrentThread(); | |
499 ScopedJavaLocalRef<jbyteArray> j_session_id = base::android::ToJavaByteArray( | |
500 env, StringAsArray(session_id), session_id.size()); | |
501 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | |
502 Java_MediaDrmBridge_closeSession(env, j_media_drm_.obj(), j_session_id.obj(), | |
503 promise_id); | |
504 } | |
464 | 505 |
465 DCHECK(!session_closed_cb_.is_null()) | 506 void MediaDrmBridge::RemoveSession( |
466 << __FUNCTION__ << " called on a sessionless MediaDrmBridge object."; | 507 const std::string& session_id, |
508 scoped_ptr<media::SimpleCdmPromise> promise) { | |
509 NOTREACHED() << "Persistent session not supported."; | |
510 promise->reject(NOT_SUPPORTED_ERROR, 0, "RemoveSession() is not supported."); | |
qinmin
2015/01/15 18:17:25
ditto
xhwang
2015/01/15 19:03:44
ditto
| |
511 } | |
467 | 512 |
468 JNIEnv* env = AttachCurrentThread(); | 513 CdmContext* MediaDrmBridge::GetCdmContext() { |
469 Java_MediaDrmBridge_releaseSession(env, j_media_drm_.obj(), session_id); | 514 NOTREACHED(); |
515 return nullptr; | |
470 } | 516 } |
471 | 517 |
472 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, | 518 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, |
473 const base::Closure& cdm_unset_cb) { | 519 const base::Closure& cdm_unset_cb) { |
474 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); | 520 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); |
475 } | 521 } |
476 | 522 |
477 void MediaDrmBridge::UnregisterPlayer(int registration_id) { | 523 void MediaDrmBridge::UnregisterPlayer(int registration_id) { |
478 player_tracker_.UnregisterPlayer(registration_id); | 524 player_tracker_.UnregisterPlayer(registration_id); |
479 } | 525 } |
(...skipping 13 matching lines...) Expand all Loading... | |
493 | 539 |
494 media_crypto_ready_cb_ = closure; | 540 media_crypto_ready_cb_ = closure; |
495 } | 541 } |
496 | 542 |
497 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { | 543 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { |
498 DCHECK(!GetMediaCrypto().is_null()); | 544 DCHECK(!GetMediaCrypto().is_null()); |
499 if (!media_crypto_ready_cb_.is_null()) | 545 if (!media_crypto_ready_cb_.is_null()) |
500 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); | 546 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); |
501 } | 547 } |
502 | 548 |
503 void MediaDrmBridge::OnSessionCreated(JNIEnv* env, | 549 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
504 jobject j_media_drm, | 550 jobject j_media_drm, |
505 jint j_session_id, | 551 jint j_promise_id) { |
506 jstring j_web_session_id) { | 552 cdm_promise_adapter_.ResolvePromise(j_promise_id); |
507 uint32 session_id = j_session_id; | 553 } |
508 std::string web_session_id = ConvertJavaStringToUTF8(env, j_web_session_id); | 554 |
509 session_created_cb_.Run(session_id, web_session_id); | 555 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
556 jobject j_media_drm, | |
557 jint j_promise_id, | |
558 jbyteArray j_session_id) { | |
559 cdm_promise_adapter_.ResolvePromise(j_promise_id, | |
560 GetSessionId(env, j_session_id)); | |
561 } | |
562 | |
563 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, | |
564 jobject j_media_drm, | |
565 jint j_promise_id, | |
566 jstring j_error_message) { | |
567 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | |
568 cdm_promise_adapter_.RejectPromise(j_promise_id, MediaKeys::UNKNOWN_ERROR, 0, | |
569 error_message); | |
510 } | 570 } |
511 | 571 |
512 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, | 572 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, |
513 jobject j_media_drm, | 573 jobject j_media_drm, |
514 jint j_session_id, | 574 jbyteArray j_session_id, |
515 jbyteArray j_message, | 575 jbyteArray j_message, |
516 jstring j_destination_url) { | 576 jstring j_legacy_destination_url) { |
517 uint32 session_id = j_session_id; | |
518 std::vector<uint8> message; | 577 std::vector<uint8> message; |
519 JavaByteArrayToByteVector(env, j_message, &message); | 578 JavaByteArrayToByteVector(env, j_message, &message); |
520 GURL destination_gurl = GURL(ConvertJavaStringToUTF8(env, j_destination_url)); | 579 GURL legacy_destination_url = |
521 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) { | 580 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); |
522 DLOG(WARNING) << "SessionMessage destination_url is invalid : " | 581 // Note: Message type is not supported in MediaDrm. Do our best guess here. |
523 << destination_gurl.possibly_invalid_spec(); | 582 media::MediaKeys::MessageType message_type = |
524 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 583 legacy_destination_url.is_empty() ? media::MediaKeys::LICENSE_REQUEST |
525 } | 584 : media::MediaKeys::LICENSE_RENEWAL; |
526 session_message_cb_.Run(session_id, message, destination_gurl); | |
527 } | |
528 | 585 |
529 void MediaDrmBridge::OnSessionReady(JNIEnv* env, | 586 session_message_cb_.Run(GetSessionId(env, j_session_id), message_type, |
530 jobject j_media_drm, | 587 message, legacy_destination_url); |
531 jint j_session_id) { | |
532 uint32 session_id = j_session_id; | |
533 session_ready_cb_.Run(session_id); | |
534 // TODO(xhwang/jrummell): Move this when usableKeyIds/keyschange are | |
535 // implemented. | |
536 player_tracker_.NotifyNewKey(); | |
537 } | 588 } |
538 | 589 |
539 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, | 590 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, |
540 jobject j_media_drm, | 591 jobject j_media_drm, |
541 jint j_session_id) { | 592 jbyteArray j_session_id) { |
542 uint32 session_id = j_session_id; | 593 session_closed_cb_.Run(GetSessionId(env, j_session_id)); |
543 session_closed_cb_.Run(session_id); | |
544 } | 594 } |
545 | 595 |
546 void MediaDrmBridge::OnSessionError(JNIEnv* env, | 596 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
547 jobject j_media_drm, | 597 jobject j_media_drm, |
548 jint j_session_id) { | 598 jbyteArray j_session_id, |
549 uint32 session_id = j_session_id; | 599 bool has_additional_usable_key, |
550 session_error_cb_.Run(session_id, MediaKeys::kUnknownError, 0); | 600 jint j_key_status) { |
601 if (has_additional_usable_key) | |
602 player_tracker_.NotifyNewKey(); | |
603 | |
604 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | |
605 cdm_key_information->key_id.assign(kDummyKeyId, | |
606 kDummyKeyId + sizeof(kDummyKeyId)); | |
607 cdm_key_information->status = | |
608 static_cast<CdmKeyInformation::KeyStatus>(j_key_status); | |
609 CdmKeysInfo cdm_keys_info; | |
610 cdm_keys_info.push_back(cdm_key_information.release()); | |
611 | |
612 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), | |
613 has_additional_usable_key, cdm_keys_info.Pass()); | |
614 } | |
615 | |
616 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | |
617 jobject j_media_drm, | |
618 jbyteArray j_session_id, | |
619 jstring j_error_message) { | |
620 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | |
621 session_error_cb_.Run(GetSessionId(env, j_session_id), | |
622 MediaKeys::UNKNOWN_ERROR, 0, error_message); | |
551 } | 623 } |
552 | 624 |
553 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { | 625 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { |
554 JNIEnv* env = AttachCurrentThread(); | 626 JNIEnv* env = AttachCurrentThread(); |
555 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); | 627 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); |
556 } | 628 } |
557 | 629 |
558 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 630 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
559 JNIEnv* env = AttachCurrentThread(); | 631 JNIEnv* env = AttachCurrentThread(); |
560 ScopedJavaLocalRef<jstring> j_security_level = | 632 ScopedJavaLocalRef<jstring> j_security_level = |
(...skipping 14 matching lines...) Expand all Loading... | |
575 JNIEnv* env = AttachCurrentThread(); | 647 JNIEnv* env = AttachCurrentThread(); |
576 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 648 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
577 } | 649 } |
578 | 650 |
579 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 651 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
580 JNIEnv* env, jobject, bool success) { | 652 JNIEnv* env, jobject, bool success) { |
581 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 653 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
582 } | 654 } |
583 | 655 |
584 } // namespace media | 656 } // namespace media |
OLD | NEW |