| 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/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/sys_byteorder.h" | 22 #include "base/sys_byteorder.h" |
| 23 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
| 24 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
| 25 #include "jni/MediaDrmBridge_jni.h" | 25 #include "jni/MediaDrmBridge_jni.h" |
| 26 #include "media/base/android/media_client_android.h" | 26 #include "media/base/android/media_client_android.h" |
| 27 #include "media/base/android/media_drm_bridge_delegate.h" | 27 #include "media/base/android/media_drm_bridge_delegate.h" |
| 28 #include "media/base/android/provision_fetcher.h" |
| 28 #include "media/base/cdm_key_information.h" | 29 #include "media/base/cdm_key_information.h" |
| 29 | 30 |
| 30 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 31 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 31 | 32 |
| 32 using base::android::AttachCurrentThread; | 33 using base::android::AttachCurrentThread; |
| 33 using base::android::ConvertUTF8ToJavaString; | 34 using base::android::ConvertUTF8ToJavaString; |
| 34 using base::android::ConvertJavaStringToUTF8; | 35 using base::android::ConvertJavaStringToUTF8; |
| 35 using base::android::JavaByteArrayToByteVector; | 36 using base::android::JavaByteArrayToByteVector; |
| 36 using base::android::ScopedJavaGlobalRef; | 37 using base::android::ScopedJavaGlobalRef; |
| 37 using base::android::ScopedJavaLocalRef; | 38 using base::android::ScopedJavaLocalRef; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 // These must be in sync with Android MediaDrm KEY_STATUS_XXX constants: | 52 // These must be in sync with Android MediaDrm KEY_STATUS_XXX constants: |
| 52 // https://developer.android.com/reference/android/media/MediaDrm.KeyStatus.html | 53 // https://developer.android.com/reference/android/media/MediaDrm.KeyStatus.html |
| 53 enum class KeyStatus { | 54 enum class KeyStatus { |
| 54 KEY_STATUS_USABLE = 0, | 55 KEY_STATUS_USABLE = 0, |
| 55 KEY_STATUS_EXPIRED = 1, | 56 KEY_STATUS_EXPIRED = 1, |
| 56 KEY_STATUS_OUTPUT_NOT_ALLOWED = 2, | 57 KEY_STATUS_OUTPUT_NOT_ALLOWED = 2, |
| 57 KEY_STATUS_PENDING = 3, | 58 KEY_STATUS_PENDING = 3, |
| 58 KEY_STATUS_INTERNAL_ERROR = 4, | 59 KEY_STATUS_INTERNAL_ERROR = 4, |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 // Returns string session ID from jbyteArray (byte[] in Java). | 62 // Converts jbyteArray (byte[] in Java) into std::string. |
| 62 std::string GetSessionId(JNIEnv* env, jbyteArray j_session_id) { | 63 std::string AsString(JNIEnv* env, jbyteArray j_byte_array) { |
| 63 std::vector<uint8> session_id_vector; | 64 std::vector<uint8_t> byte_vector; |
| 64 JavaByteArrayToByteVector(env, j_session_id, &session_id_vector); | 65 JavaByteArrayToByteVector(env, j_byte_array, &byte_vector); |
| 65 return std::string(session_id_vector.begin(), session_id_vector.end()); | 66 return std::string(byte_vector.begin(), byte_vector.end()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 const uint8 kWidevineUuid[16] = { | 69 const uint8 kWidevineUuid[16] = { |
| 69 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // | 70 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // |
| 70 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED}; | 71 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED}; |
| 71 | 72 |
| 72 // Convert |init_data_type| to a string supported by MediaDRM. | 73 // Convert |init_data_type| to a string supported by MediaDRM. |
| 73 // "audio"/"video" does not matter, so use "video". | 74 // "audio"/"video" does not matter, so use "video". |
| 74 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) { | 75 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) { |
| 75 // TODO(jrummell/xhwang): EME init data types like "webm" and "cenc" are | 76 // TODO(jrummell/xhwang): EME init data types like "webm" and "cenc" are |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 250 } |
| 250 | 251 |
| 251 // static | 252 // static |
| 252 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | 253 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 253 return g_key_system_manager.Get().GetPlatformKeySystemNames(); | 254 return g_key_system_manager.Get().GetPlatformKeySystemNames(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 // static | 257 // static |
| 257 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( | 258 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( |
| 258 const std::string& key_system, | 259 const std::string& key_system, |
| 260 scoped_ptr<ProvisionFetcher> provision_fetcher, |
| 259 const SessionMessageCB& session_message_cb, | 261 const SessionMessageCB& session_message_cb, |
| 260 const SessionClosedCB& session_closed_cb, | 262 const SessionClosedCB& session_closed_cb, |
| 261 const LegacySessionErrorCB& legacy_session_error_cb, | 263 const LegacySessionErrorCB& legacy_session_error_cb, |
| 262 const SessionKeysChangeCB& session_keys_change_cb, | 264 const SessionKeysChangeCB& session_keys_change_cb, |
| 263 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 265 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 264 DVLOG(1) << __FUNCTION__; | 266 DVLOG(1) << __FUNCTION__; |
| 265 | 267 |
| 266 if (!IsAvailable()) | 268 if (!IsAvailable()) |
| 267 return nullptr; | 269 return nullptr; |
| 268 | 270 |
| 269 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 271 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); |
| 270 if (scheme_uuid.empty()) | 272 if (scheme_uuid.empty()) |
| 271 return nullptr; | 273 return nullptr; |
| 272 | 274 |
| 273 scoped_refptr<MediaDrmBridge> media_drm_bridge( | 275 scoped_refptr<MediaDrmBridge> media_drm_bridge( |
| 274 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, | 276 new MediaDrmBridge(scheme_uuid, provision_fetcher.Pass(), |
| 277 session_message_cb, session_closed_cb, |
| 275 legacy_session_error_cb, session_keys_change_cb, | 278 legacy_session_error_cb, session_keys_change_cb, |
| 276 session_expiration_update_cb)); | 279 session_expiration_update_cb)); |
| 277 | 280 |
| 278 if (media_drm_bridge->j_media_drm_.is_null()) | 281 if (media_drm_bridge->j_media_drm_.is_null()) |
| 279 media_drm_bridge = nullptr; | 282 media_drm_bridge = nullptr; |
| 280 | 283 |
| 281 return media_drm_bridge; | 284 return media_drm_bridge; |
| 282 } | 285 } |
| 283 | 286 |
| 284 // static | 287 // static |
| 285 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 288 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( |
| 286 const std::string& key_system) { | 289 const std::string& key_system, |
| 287 return MediaDrmBridge::Create( | 290 scoped_ptr<ProvisionFetcher> provision_fetcher) { |
| 288 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), | 291 return MediaDrmBridge::Create(key_system, provision_fetcher.Pass(), |
| 289 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 292 SessionMessageCB(), SessionClosedCB(), |
| 293 LegacySessionErrorCB(), SessionKeysChangeCB(), |
| 294 SessionExpirationUpdateCB()); |
| 290 } | 295 } |
| 291 | 296 |
| 292 void MediaDrmBridge::SetServerCertificate( | 297 void MediaDrmBridge::SetServerCertificate( |
| 293 const std::vector<uint8_t>& certificate, | 298 const std::vector<uint8_t>& certificate, |
| 294 scoped_ptr<media::SimpleCdmPromise> promise) { | 299 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 295 DVLOG(2) << __FUNCTION__; | 300 DVLOG(2) << __FUNCTION__; |
| 296 | 301 |
| 297 DCHECK(!certificate.empty()); | 302 DCHECK(!certificate.empty()); |
| 298 | 303 |
| 299 JNIEnv* env = AttachCurrentThread(); | 304 JNIEnv* env = AttachCurrentThread(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 // For Widevine, this depends on the security level. | 461 // For Widevine, this depends on the security level. |
| 457 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) | 462 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) |
| 458 return IsSecureDecoderRequired(GetSecurityLevel()); | 463 return IsSecureDecoderRequired(GetSecurityLevel()); |
| 459 | 464 |
| 460 // For other key systems, assume true. | 465 // For other key systems, assume true. |
| 461 return true; | 466 return true; |
| 462 } | 467 } |
| 463 | 468 |
| 464 void MediaDrmBridge::ResetDeviceCredentials( | 469 void MediaDrmBridge::ResetDeviceCredentials( |
| 465 const ResetCredentialsCB& callback) { | 470 const ResetCredentialsCB& callback) { |
| 471 DVLOG(1) << __FUNCTION__; |
| 472 |
| 466 DCHECK(reset_credentials_cb_.is_null()); | 473 DCHECK(reset_credentials_cb_.is_null()); |
| 467 reset_credentials_cb_ = callback; | 474 reset_credentials_cb_ = callback; |
| 468 JNIEnv* env = AttachCurrentThread(); | 475 JNIEnv* env = AttachCurrentThread(); |
| 469 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 476 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 470 } | 477 } |
| 471 | 478 |
| 472 void MediaDrmBridge::ResolvePromise(uint32_t promise_id) { | 479 void MediaDrmBridge::ResolvePromise(uint32_t promise_id) { |
| 473 DVLOG(2) << __FUNCTION__; | 480 DVLOG(2) << __FUNCTION__; |
| 474 cdm_promise_adapter_->ResolvePromise(promise_id); | 481 cdm_promise_adapter_->ResolvePromise(promise_id); |
| 475 } | 482 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 539 |
| 533 if (media_crypto_ready_cb_.is_null()) | 540 if (media_crypto_ready_cb_.is_null()) |
| 534 return; | 541 return; |
| 535 | 542 |
| 536 task_runner_->PostTask( | 543 task_runner_->PostTask( |
| 537 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyMediaCryptoReady, | 544 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyMediaCryptoReady, |
| 538 weak_factory_.GetWeakPtr(), | 545 weak_factory_.GetWeakPtr(), |
| 539 base::ResetAndReturn(&media_crypto_ready_cb_))); | 546 base::ResetAndReturn(&media_crypto_ready_cb_))); |
| 540 } | 547 } |
| 541 | 548 |
| 549 void MediaDrmBridge::OnStartProvisioning(JNIEnv* env, |
| 550 jobject j_media_drm, |
| 551 jstring j_default_url, |
| 552 jbyteArray j_request_data) { |
| 553 DVLOG(1) << __FUNCTION__; |
| 554 |
| 555 task_runner_->PostTask(FROM_HERE, |
| 556 base::Bind(&MediaDrmBridge::SendProvisioningRequest, |
| 557 weak_factory_.GetWeakPtr(), |
| 558 ConvertJavaStringToUTF8(env, j_default_url), |
| 559 AsString(env, j_request_data))); |
| 560 } |
| 561 |
| 542 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 562 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
| 543 jobject j_media_drm, | 563 jobject j_media_drm, |
| 544 jint j_promise_id) { | 564 jint j_promise_id) { |
| 545 task_runner_->PostTask(FROM_HERE, | 565 task_runner_->PostTask(FROM_HERE, |
| 546 base::Bind(&MediaDrmBridge::ResolvePromise, | 566 base::Bind(&MediaDrmBridge::ResolvePromise, |
| 547 weak_factory_.GetWeakPtr(), j_promise_id)); | 567 weak_factory_.GetWeakPtr(), j_promise_id)); |
| 548 } | 568 } |
| 549 | 569 |
| 550 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 570 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
| 551 jobject j_media_drm, | 571 jobject j_media_drm, |
| 552 jint j_promise_id, | 572 jint j_promise_id, |
| 553 jbyteArray j_session_id) { | 573 jbyteArray j_session_id) { |
| 554 task_runner_->PostTask(FROM_HERE, | 574 task_runner_->PostTask(FROM_HERE, |
| 555 base::Bind(&MediaDrmBridge::ResolvePromiseWithSession, | 575 base::Bind(&MediaDrmBridge::ResolvePromiseWithSession, |
| 556 weak_factory_.GetWeakPtr(), j_promise_id, | 576 weak_factory_.GetWeakPtr(), j_promise_id, |
| 557 GetSessionId(env, j_session_id))); | 577 AsString(env, j_session_id))); |
| 558 } | 578 } |
| 559 | 579 |
| 560 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, | 580 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, |
| 561 jobject j_media_drm, | 581 jobject j_media_drm, |
| 562 jint j_promise_id, | 582 jint j_promise_id, |
| 563 jstring j_error_message) { | 583 jstring j_error_message) { |
| 564 task_runner_->PostTask( | 584 task_runner_->PostTask( |
| 565 FROM_HERE, | 585 FROM_HERE, |
| 566 base::Bind(&MediaDrmBridge::RejectPromise, weak_factory_.GetWeakPtr(), | 586 base::Bind(&MediaDrmBridge::RejectPromise, weak_factory_.GetWeakPtr(), |
| 567 j_promise_id, ConvertJavaStringToUTF8(env, j_error_message))); | 587 j_promise_id, ConvertJavaStringToUTF8(env, j_error_message))); |
| 568 } | 588 } |
| 569 | 589 |
| 570 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, | 590 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, |
| 571 jobject j_media_drm, | 591 jobject j_media_drm, |
| 572 jbyteArray j_session_id, | 592 jbyteArray j_session_id, |
| 573 jint j_message_type, | 593 jint j_message_type, |
| 574 jbyteArray j_message, | 594 jbyteArray j_message, |
| 575 jstring j_legacy_destination_url) { | 595 jstring j_legacy_destination_url) { |
| 576 DVLOG(2) << __FUNCTION__; | 596 DVLOG(2) << __FUNCTION__; |
| 577 | 597 |
| 578 std::vector<uint8> message; | 598 std::vector<uint8> message; |
| 579 JavaByteArrayToByteVector(env, j_message, &message); | 599 JavaByteArrayToByteVector(env, j_message, &message); |
| 580 GURL legacy_destination_url = | 600 GURL legacy_destination_url = |
| 581 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); | 601 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); |
| 582 MediaKeys::MessageType message_type = | 602 MediaKeys::MessageType message_type = |
| 583 GetMessageType(static_cast<RequestType>(j_message_type)); | 603 GetMessageType(static_cast<RequestType>(j_message_type)); |
| 584 | 604 |
| 585 task_runner_->PostTask( | 605 task_runner_->PostTask( |
| 586 FROM_HERE, | 606 FROM_HERE, base::Bind(session_message_cb_, AsString(env, j_session_id), |
| 587 base::Bind(session_message_cb_, GetSessionId(env, j_session_id), | 607 message_type, message, legacy_destination_url)); |
| 588 message_type, message, legacy_destination_url)); | |
| 589 } | 608 } |
| 590 | 609 |
| 591 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, | 610 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, |
| 592 jobject j_media_drm, | 611 jobject j_media_drm, |
| 593 jbyteArray j_session_id) { | 612 jbyteArray j_session_id) { |
| 594 DVLOG(2) << __FUNCTION__; | 613 DVLOG(2) << __FUNCTION__; |
| 595 std::string session_id = GetSessionId(env, j_session_id); | 614 std::string session_id = AsString(env, j_session_id); |
| 596 task_runner_->PostTask(FROM_HERE, base::Bind(session_closed_cb_, session_id)); | 615 task_runner_->PostTask(FROM_HERE, base::Bind(session_closed_cb_, session_id)); |
| 597 } | 616 } |
| 598 | 617 |
| 599 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 618 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
| 600 jobject j_media_drm, | 619 jobject j_media_drm, |
| 601 jbyteArray j_session_id, | 620 jbyteArray j_session_id, |
| 602 jobjectArray j_keys_info, | 621 jobjectArray j_keys_info, |
| 603 bool has_additional_usable_key) { | 622 bool has_additional_usable_key) { |
| 604 DVLOG(2) << __FUNCTION__; | 623 DVLOG(2) << __FUNCTION__; |
| 605 | 624 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 627 | 646 |
| 628 DVLOG(2) << __FUNCTION__ << "Key status change: " | 647 DVLOG(2) << __FUNCTION__ << "Key status change: " |
| 629 << base::HexEncode(&key_id[0], key_id.size()) << ", " | 648 << base::HexEncode(&key_id[0], key_id.size()) << ", " |
| 630 << key_status; | 649 << key_status; |
| 631 | 650 |
| 632 cdm_keys_info.push_back(new CdmKeyInformation(key_id, key_status, 0)); | 651 cdm_keys_info.push_back(new CdmKeyInformation(key_id, key_status, 0)); |
| 633 } | 652 } |
| 634 | 653 |
| 635 task_runner_->PostTask( | 654 task_runner_->PostTask( |
| 636 FROM_HERE, | 655 FROM_HERE, |
| 637 base::Bind(session_keys_change_cb_, GetSessionId(env, j_session_id), | 656 base::Bind(session_keys_change_cb_, AsString(env, j_session_id), |
| 638 has_additional_usable_key, base::Passed(&cdm_keys_info))); | 657 has_additional_usable_key, base::Passed(&cdm_keys_info))); |
| 639 } | 658 } |
| 640 | 659 |
| 641 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 660 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys |
| 642 // will never expire. This will be translated into a NULL base::Time() [2], | 661 // will never expire. This will be translated into a NULL base::Time() [2], |
| 643 // which will then be mapped to a zero Java time [3]. The zero Java time is | 662 // which will then be mapped to a zero Java time [3]. The zero Java time is |
| 644 // passed to Blink which will then be translated to NaN [4], which is what the | 663 // passed to Blink which will then be translated to NaN [4], which is what the |
| 645 // spec uses to indicate that the license will never expire [5]. | 664 // spec uses to indicate that the license will never expire [5]. |
| 646 // [1] | 665 // [1] |
| 647 // http://developer.android.com/reference/android/media/MediaDrm.OnExpirationUpd
ateListener.html | 666 // http://developer.android.com/reference/android/media/MediaDrm.OnExpirationUpd
ateListener.html |
| 648 // [2] See base::Time::FromDoubleT() | 667 // [2] See base::Time::FromDoubleT() |
| 649 // [3] See base::Time::ToJavaTime() | 668 // [3] See base::Time::ToJavaTime() |
| 650 // [4] See MediaKeySession::expirationChanged() | 669 // [4] See MediaKeySession::expirationChanged() |
| 651 // [5] https://github.com/w3c/encrypted-media/issues/58 | 670 // [5] https://github.com/w3c/encrypted-media/issues/58 |
| 652 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, | 671 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, |
| 653 jobject j_media_drm, | 672 jobject j_media_drm, |
| 654 jbyteArray j_session_id, | 673 jbyteArray j_session_id, |
| 655 jlong expiry_time_ms) { | 674 jlong expiry_time_ms) { |
| 656 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; | 675 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; |
| 657 session_expiration_update_cb_.Run( | 676 session_expiration_update_cb_.Run( |
| 658 GetSessionId(env, j_session_id), | 677 AsString(env, j_session_id), |
| 659 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); | 678 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); |
| 660 } | 679 } |
| 661 | 680 |
| 662 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 681 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
| 663 jobject j_media_drm, | 682 jobject j_media_drm, |
| 664 jbyteArray j_session_id, | 683 jbyteArray j_session_id, |
| 665 jstring j_error_message) { | 684 jstring j_error_message) { |
| 666 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 685 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
| 667 | 686 |
| 668 DVLOG(2) << __FUNCTION__ << ": " << error_message; | 687 DVLOG(2) << __FUNCTION__ << ": " << error_message; |
| 669 | 688 |
| 670 task_runner_->PostTask( | 689 task_runner_->PostTask( |
| 671 FROM_HERE, | 690 FROM_HERE, |
| 672 base::Bind(legacy_session_error_cb_, GetSessionId(env, j_session_id), | 691 base::Bind(legacy_session_error_cb_, AsString(env, j_session_id), |
| 673 MediaKeys::UNKNOWN_ERROR, 0, error_message)); | 692 MediaKeys::UNKNOWN_ERROR, 0, error_message)); |
| 674 } | 693 } |
| 675 | 694 |
| 676 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(JNIEnv* env, | 695 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(JNIEnv* env, |
| 677 jobject, | 696 jobject, |
| 678 bool success) { | 697 bool success) { |
| 679 DVLOG(2) << __FUNCTION__ << ": " << success; | 698 DVLOG(2) << __FUNCTION__ << ": success:" << success; |
| 680 DCHECK(!reset_credentials_cb_.is_null()); | 699 DCHECK(!reset_credentials_cb_.is_null()); |
| 681 task_runner_->PostTask( | 700 task_runner_->PostTask( |
| 682 FROM_HERE, | 701 FROM_HERE, |
| 683 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); | 702 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); |
| 684 } | 703 } |
| 685 | 704 |
| 686 // The following are private methods. | 705 // The following are private methods. |
| 687 | 706 |
| 688 MediaDrmBridge::MediaDrmBridge( | 707 MediaDrmBridge::MediaDrmBridge( |
| 689 const std::vector<uint8>& scheme_uuid, | 708 const std::vector<uint8>& scheme_uuid, |
| 709 scoped_ptr<ProvisionFetcher> provision_fetcher, |
| 690 const SessionMessageCB& session_message_cb, | 710 const SessionMessageCB& session_message_cb, |
| 691 const SessionClosedCB& session_closed_cb, | 711 const SessionClosedCB& session_closed_cb, |
| 692 const LegacySessionErrorCB& legacy_session_error_cb, | 712 const LegacySessionErrorCB& legacy_session_error_cb, |
| 693 const SessionKeysChangeCB& session_keys_change_cb, | 713 const SessionKeysChangeCB& session_keys_change_cb, |
| 694 const SessionExpirationUpdateCB& session_expiration_update_cb) | 714 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 695 : scheme_uuid_(scheme_uuid), | 715 : scheme_uuid_(scheme_uuid), |
| 716 provision_fetcher_(provision_fetcher.Pass()), |
| 696 session_message_cb_(session_message_cb), | 717 session_message_cb_(session_message_cb), |
| 697 session_closed_cb_(session_closed_cb), | 718 session_closed_cb_(session_closed_cb), |
| 698 legacy_session_error_cb_(legacy_session_error_cb), | 719 legacy_session_error_cb_(legacy_session_error_cb), |
| 699 session_keys_change_cb_(session_keys_change_cb), | 720 session_keys_change_cb_(session_keys_change_cb), |
| 700 session_expiration_update_cb_(session_expiration_update_cb), | 721 session_expiration_update_cb_(session_expiration_update_cb), |
| 701 cdm_promise_adapter_(new CdmPromiseAdapter()), | 722 cdm_promise_adapter_(new CdmPromiseAdapter()), |
| 702 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 723 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 703 weak_factory_(this) { | 724 weak_factory_(this) { |
| 704 DVLOG(1) << __FUNCTION__; | 725 DVLOG(1) << __FUNCTION__; |
| 705 | 726 |
| 727 DCHECK(provision_fetcher_); |
| 728 |
| 706 JNIEnv* env = AttachCurrentThread(); | 729 JNIEnv* env = AttachCurrentThread(); |
| 707 CHECK(env); | 730 CHECK(env); |
| 708 | 731 |
| 709 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 732 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 710 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 733 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 711 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 734 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 712 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 735 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
| 713 } | 736 } |
| 714 | 737 |
| 715 MediaDrmBridge::~MediaDrmBridge() { | 738 MediaDrmBridge::~MediaDrmBridge() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 DCHECK(!GetMediaCrypto().is_null()); | 772 DCHECK(!GetMediaCrypto().is_null()); |
| 750 | 773 |
| 751 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. | 774 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. |
| 752 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( | 775 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( |
| 753 new ScopedJavaGlobalRef<jobject>()); | 776 new ScopedJavaGlobalRef<jobject>()); |
| 754 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); | 777 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); |
| 755 | 778 |
| 756 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); | 779 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); |
| 757 } | 780 } |
| 758 | 781 |
| 782 void MediaDrmBridge::SendProvisioningRequest(const std::string& default_url, |
| 783 const std::string& request_data) { |
| 784 DVLOG(1) << __FUNCTION__; |
| 785 |
| 786 provision_fetcher_->Retrieve( |
| 787 default_url, request_data, |
| 788 base::Bind(&MediaDrmBridge::ProcessProvisionResponse, |
| 789 weak_factory_.GetWeakPtr())); |
| 790 } |
| 791 |
| 792 void MediaDrmBridge::ProcessProvisionResponse(bool success, |
| 793 const std::string& response) { |
| 794 DVLOG(1) << __FUNCTION__; |
| 795 |
| 796 if (!success) |
| 797 VLOG(1) << "Device provision failure: can't get server response"; |
| 798 |
| 799 JNIEnv* env = AttachCurrentThread(); |
| 800 |
| 801 ScopedJavaLocalRef<jbyteArray> j_response = base::android::ToJavaByteArray( |
| 802 env, reinterpret_cast<const uint8_t*>(response.data()), response.size()); |
| 803 |
| 804 Java_MediaDrmBridge_processProvisionResponse(env, j_media_drm_.obj(), success, |
| 805 j_response.obj()); |
| 806 } |
| 807 |
| 759 } // namespace media | 808 } // namespace media |
| OLD | NEW |