| 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(new MediaDrmBridge( |
| 274 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, | 276 scheme_uuid, provision_fetcher.Pass(), session_message_cb, |
| 275 legacy_session_error_cb, session_keys_change_cb, | 277 session_closed_cb, legacy_session_error_cb, session_keys_change_cb, |
| 276 session_expiration_update_cb)); | 278 session_expiration_update_cb)); |
| 277 | 279 |
| 278 if (media_drm_bridge->j_media_drm_.is_null()) | 280 if (media_drm_bridge->j_media_drm_.is_null()) |
| 279 media_drm_bridge = nullptr; | 281 media_drm_bridge = nullptr; |
| 280 | 282 |
| 281 return media_drm_bridge; | 283 return media_drm_bridge; |
| 282 } | 284 } |
| 283 | 285 |
| 284 // static | 286 // static |
| 285 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 287 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( |
| 286 const std::string& key_system) { | 288 const std::string& key_system, |
| 287 return MediaDrmBridge::Create( | 289 scoped_ptr<ProvisionFetcher> provision_fetcher) { |
| 288 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), | 290 return MediaDrmBridge::Create(key_system, provision_fetcher.Pass(), |
| 289 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 291 SessionMessageCB(), SessionClosedCB(), |
| 292 LegacySessionErrorCB(), SessionKeysChangeCB(), |
| 293 SessionExpirationUpdateCB()); |
| 290 } | 294 } |
| 291 | 295 |
| 292 void MediaDrmBridge::SetServerCertificate( | 296 void MediaDrmBridge::SetServerCertificate( |
| 293 const std::vector<uint8_t>& certificate, | 297 const std::vector<uint8_t>& certificate, |
| 294 scoped_ptr<media::SimpleCdmPromise> promise) { | 298 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 295 DVLOG(2) << __FUNCTION__; | 299 DVLOG(2) << __FUNCTION__; |
| 296 | 300 |
| 297 DCHECK(!certificate.empty()); | 301 DCHECK(!certificate.empty()); |
| 298 | 302 |
| 299 JNIEnv* env = AttachCurrentThread(); | 303 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. | 460 // For Widevine, this depends on the security level. |
| 457 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) | 461 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) |
| 458 return IsSecureDecoderRequired(GetSecurityLevel()); | 462 return IsSecureDecoderRequired(GetSecurityLevel()); |
| 459 | 463 |
| 460 // For other key systems, assume true. | 464 // For other key systems, assume true. |
| 461 return true; | 465 return true; |
| 462 } | 466 } |
| 463 | 467 |
| 464 void MediaDrmBridge::ResetDeviceCredentials( | 468 void MediaDrmBridge::ResetDeviceCredentials( |
| 465 const ResetCredentialsCB& callback) { | 469 const ResetCredentialsCB& callback) { |
| 470 DVLOG(1) << __FUNCTION__; |
| 471 |
| 466 DCHECK(reset_credentials_cb_.is_null()); | 472 DCHECK(reset_credentials_cb_.is_null()); |
| 467 reset_credentials_cb_ = callback; | 473 reset_credentials_cb_ = callback; |
| 468 JNIEnv* env = AttachCurrentThread(); | 474 JNIEnv* env = AttachCurrentThread(); |
| 469 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 475 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 470 } | 476 } |
| 471 | 477 |
| 472 void MediaDrmBridge::ResolvePromise(uint32_t promise_id) { | 478 void MediaDrmBridge::ResolvePromise(uint32_t promise_id) { |
| 473 DVLOG(2) << __FUNCTION__; | 479 DVLOG(2) << __FUNCTION__; |
| 474 cdm_promise_adapter_->ResolvePromise(promise_id); | 480 cdm_promise_adapter_->ResolvePromise(promise_id); |
| 475 } | 481 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 538 |
| 533 if (media_crypto_ready_cb_.is_null()) | 539 if (media_crypto_ready_cb_.is_null()) |
| 534 return; | 540 return; |
| 535 | 541 |
| 536 task_runner_->PostTask( | 542 task_runner_->PostTask( |
| 537 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyMediaCryptoReady, | 543 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyMediaCryptoReady, |
| 538 weak_factory_.GetWeakPtr(), | 544 weak_factory_.GetWeakPtr(), |
| 539 base::ResetAndReturn(&media_crypto_ready_cb_))); | 545 base::ResetAndReturn(&media_crypto_ready_cb_))); |
| 540 } | 546 } |
| 541 | 547 |
| 548 void MediaDrmBridge::OnStartProvisioning(JNIEnv* env, |
| 549 jobject j_media_drm, |
| 550 jstring j_default_url, |
| 551 jbyteArray j_request_data) { |
| 552 DVLOG(1) << __FUNCTION__; |
| 553 |
| 554 task_runner_->PostTask(FROM_HERE, |
| 555 base::Bind(&MediaDrmBridge::SendProvisioningRequest, |
| 556 weak_factory_.GetWeakPtr(), |
| 557 ConvertJavaStringToUTF8(env, j_default_url), |
| 558 AsString(env, j_request_data))); |
| 559 } |
| 560 |
| 542 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 561 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
| 543 jobject j_media_drm, | 562 jobject j_media_drm, |
| 544 jint j_promise_id) { | 563 jint j_promise_id) { |
| 545 task_runner_->PostTask(FROM_HERE, | 564 task_runner_->PostTask(FROM_HERE, |
| 546 base::Bind(&MediaDrmBridge::ResolvePromise, | 565 base::Bind(&MediaDrmBridge::ResolvePromise, |
| 547 weak_factory_.GetWeakPtr(), j_promise_id)); | 566 weak_factory_.GetWeakPtr(), j_promise_id)); |
| 548 } | 567 } |
| 549 | 568 |
| 550 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 569 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
| 551 jobject j_media_drm, | 570 jobject j_media_drm, |
| 552 jint j_promise_id, | 571 jint j_promise_id, |
| 553 jbyteArray j_session_id) { | 572 jbyteArray j_session_id) { |
| 554 task_runner_->PostTask(FROM_HERE, | 573 task_runner_->PostTask(FROM_HERE, |
| 555 base::Bind(&MediaDrmBridge::ResolvePromiseWithSession, | 574 base::Bind(&MediaDrmBridge::ResolvePromiseWithSession, |
| 556 weak_factory_.GetWeakPtr(), j_promise_id, | 575 weak_factory_.GetWeakPtr(), j_promise_id, |
| 557 GetSessionId(env, j_session_id))); | 576 AsString(env, j_session_id))); |
| 558 } | 577 } |
| 559 | 578 |
| 560 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, | 579 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, |
| 561 jobject j_media_drm, | 580 jobject j_media_drm, |
| 562 jint j_promise_id, | 581 jint j_promise_id, |
| 563 jstring j_error_message) { | 582 jstring j_error_message) { |
| 564 task_runner_->PostTask( | 583 task_runner_->PostTask( |
| 565 FROM_HERE, | 584 FROM_HERE, |
| 566 base::Bind(&MediaDrmBridge::RejectPromise, weak_factory_.GetWeakPtr(), | 585 base::Bind(&MediaDrmBridge::RejectPromise, weak_factory_.GetWeakPtr(), |
| 567 j_promise_id, ConvertJavaStringToUTF8(env, j_error_message))); | 586 j_promise_id, ConvertJavaStringToUTF8(env, j_error_message))); |
| 568 } | 587 } |
| 569 | 588 |
| 570 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, | 589 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, |
| 571 jobject j_media_drm, | 590 jobject j_media_drm, |
| 572 jbyteArray j_session_id, | 591 jbyteArray j_session_id, |
| 573 jint j_message_type, | 592 jint j_message_type, |
| 574 jbyteArray j_message, | 593 jbyteArray j_message, |
| 575 jstring j_legacy_destination_url) { | 594 jstring j_legacy_destination_url) { |
| 576 DVLOG(2) << __FUNCTION__; | 595 DVLOG(2) << __FUNCTION__; |
| 577 | 596 |
| 578 std::vector<uint8> message; | 597 std::vector<uint8> message; |
| 579 JavaByteArrayToByteVector(env, j_message, &message); | 598 JavaByteArrayToByteVector(env, j_message, &message); |
| 580 GURL legacy_destination_url = | 599 GURL legacy_destination_url = |
| 581 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); | 600 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); |
| 582 MediaKeys::MessageType message_type = | 601 MediaKeys::MessageType message_type = |
| 583 GetMessageType(static_cast<RequestType>(j_message_type)); | 602 GetMessageType(static_cast<RequestType>(j_message_type)); |
| 584 | 603 |
| 585 task_runner_->PostTask( | 604 task_runner_->PostTask( |
| 586 FROM_HERE, | 605 FROM_HERE, base::Bind(session_message_cb_, AsString(env, j_session_id), |
| 587 base::Bind(session_message_cb_, GetSessionId(env, j_session_id), | 606 message_type, message, legacy_destination_url)); |
| 588 message_type, message, legacy_destination_url)); | |
| 589 } | 607 } |
| 590 | 608 |
| 591 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, | 609 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, |
| 592 jobject j_media_drm, | 610 jobject j_media_drm, |
| 593 jbyteArray j_session_id) { | 611 jbyteArray j_session_id) { |
| 594 DVLOG(2) << __FUNCTION__; | 612 DVLOG(2) << __FUNCTION__; |
| 595 std::string session_id = GetSessionId(env, j_session_id); | 613 std::string session_id = AsString(env, j_session_id); |
| 596 task_runner_->PostTask(FROM_HERE, base::Bind(session_closed_cb_, session_id)); | 614 task_runner_->PostTask(FROM_HERE, base::Bind(session_closed_cb_, session_id)); |
| 597 } | 615 } |
| 598 | 616 |
| 599 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 617 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
| 600 jobject j_media_drm, | 618 jobject j_media_drm, |
| 601 jbyteArray j_session_id, | 619 jbyteArray j_session_id, |
| 602 jobjectArray j_keys_info, | 620 jobjectArray j_keys_info, |
| 603 bool has_additional_usable_key) { | 621 bool has_additional_usable_key) { |
| 604 DVLOG(2) << __FUNCTION__; | 622 DVLOG(2) << __FUNCTION__; |
| 605 | 623 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 627 | 645 |
| 628 DVLOG(2) << __FUNCTION__ << "Key status change: " | 646 DVLOG(2) << __FUNCTION__ << "Key status change: " |
| 629 << base::HexEncode(&key_id[0], key_id.size()) << ", " | 647 << base::HexEncode(&key_id[0], key_id.size()) << ", " |
| 630 << key_status; | 648 << key_status; |
| 631 | 649 |
| 632 cdm_keys_info.push_back(new CdmKeyInformation(key_id, key_status, 0)); | 650 cdm_keys_info.push_back(new CdmKeyInformation(key_id, key_status, 0)); |
| 633 } | 651 } |
| 634 | 652 |
| 635 task_runner_->PostTask( | 653 task_runner_->PostTask( |
| 636 FROM_HERE, | 654 FROM_HERE, |
| 637 base::Bind(session_keys_change_cb_, GetSessionId(env, j_session_id), | 655 base::Bind(session_keys_change_cb_, AsString(env, j_session_id), |
| 638 has_additional_usable_key, base::Passed(&cdm_keys_info))); | 656 has_additional_usable_key, base::Passed(&cdm_keys_info))); |
| 639 } | 657 } |
| 640 | 658 |
| 641 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 659 // 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], | 660 // 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 | 661 // 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 | 662 // 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]. | 663 // spec uses to indicate that the license will never expire [5]. |
| 646 // [1] | 664 // [1] |
| 647 // http://developer.android.com/reference/android/media/MediaDrm.OnExpirationUpd
ateListener.html | 665 // http://developer.android.com/reference/android/media/MediaDrm.OnExpirationUpd
ateListener.html |
| 648 // [2] See base::Time::FromDoubleT() | 666 // [2] See base::Time::FromDoubleT() |
| 649 // [3] See base::Time::ToJavaTime() | 667 // [3] See base::Time::ToJavaTime() |
| 650 // [4] See MediaKeySession::expirationChanged() | 668 // [4] See MediaKeySession::expirationChanged() |
| 651 // [5] https://github.com/w3c/encrypted-media/issues/58 | 669 // [5] https://github.com/w3c/encrypted-media/issues/58 |
| 652 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, | 670 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, |
| 653 jobject j_media_drm, | 671 jobject j_media_drm, |
| 654 jbyteArray j_session_id, | 672 jbyteArray j_session_id, |
| 655 jlong expiry_time_ms) { | 673 jlong expiry_time_ms) { |
| 656 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; | 674 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; |
| 657 session_expiration_update_cb_.Run( | 675 session_expiration_update_cb_.Run( |
| 658 GetSessionId(env, j_session_id), | 676 AsString(env, j_session_id), |
| 659 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); | 677 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); |
| 660 } | 678 } |
| 661 | 679 |
| 662 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 680 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
| 663 jobject j_media_drm, | 681 jobject j_media_drm, |
| 664 jbyteArray j_session_id, | 682 jbyteArray j_session_id, |
| 665 jstring j_error_message) { | 683 jstring j_error_message) { |
| 666 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 684 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
| 667 | 685 |
| 668 DVLOG(2) << __FUNCTION__ << ": " << error_message; | 686 DVLOG(2) << __FUNCTION__ << ": " << error_message; |
| 669 | 687 |
| 670 task_runner_->PostTask( | 688 task_runner_->PostTask( |
| 671 FROM_HERE, | 689 FROM_HERE, |
| 672 base::Bind(legacy_session_error_cb_, GetSessionId(env, j_session_id), | 690 base::Bind(legacy_session_error_cb_, AsString(env, j_session_id), |
| 673 MediaKeys::UNKNOWN_ERROR, 0, error_message)); | 691 MediaKeys::UNKNOWN_ERROR, 0, error_message)); |
| 674 } | 692 } |
| 675 | 693 |
| 676 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(JNIEnv* env, | 694 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(JNIEnv* env, |
| 677 jobject, | 695 jobject, |
| 678 bool success) { | 696 bool success) { |
| 679 DVLOG(2) << __FUNCTION__ << ": " << success; | 697 DVLOG(2) << __FUNCTION__ << ": success:" << success; |
| 680 DCHECK(!reset_credentials_cb_.is_null()); | 698 DCHECK(!reset_credentials_cb_.is_null()); |
| 681 task_runner_->PostTask( | 699 task_runner_->PostTask( |
| 682 FROM_HERE, | 700 FROM_HERE, |
| 683 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); | 701 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); |
| 684 } | 702 } |
| 685 | 703 |
| 686 // The following are private methods. | 704 // The following are private methods. |
| 687 | 705 |
| 688 MediaDrmBridge::MediaDrmBridge( | 706 MediaDrmBridge::MediaDrmBridge( |
| 689 const std::vector<uint8>& scheme_uuid, | 707 const std::vector<uint8>& scheme_uuid, |
| 708 scoped_ptr<ProvisionFetcher> provision_fetcher, |
| 690 const SessionMessageCB& session_message_cb, | 709 const SessionMessageCB& session_message_cb, |
| 691 const SessionClosedCB& session_closed_cb, | 710 const SessionClosedCB& session_closed_cb, |
| 692 const LegacySessionErrorCB& legacy_session_error_cb, | 711 const LegacySessionErrorCB& legacy_session_error_cb, |
| 693 const SessionKeysChangeCB& session_keys_change_cb, | 712 const SessionKeysChangeCB& session_keys_change_cb, |
| 694 const SessionExpirationUpdateCB& session_expiration_update_cb) | 713 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 695 : scheme_uuid_(scheme_uuid), | 714 : scheme_uuid_(scheme_uuid), |
| 715 provision_fetcher_(provision_fetcher.Pass()), |
| 696 session_message_cb_(session_message_cb), | 716 session_message_cb_(session_message_cb), |
| 697 session_closed_cb_(session_closed_cb), | 717 session_closed_cb_(session_closed_cb), |
| 698 legacy_session_error_cb_(legacy_session_error_cb), | 718 legacy_session_error_cb_(legacy_session_error_cb), |
| 699 session_keys_change_cb_(session_keys_change_cb), | 719 session_keys_change_cb_(session_keys_change_cb), |
| 700 session_expiration_update_cb_(session_expiration_update_cb), | 720 session_expiration_update_cb_(session_expiration_update_cb), |
| 701 cdm_promise_adapter_(new CdmPromiseAdapter()), | 721 cdm_promise_adapter_(new CdmPromiseAdapter()), |
| 702 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 722 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 703 weak_factory_(this) { | 723 weak_factory_(this) { |
| 704 DVLOG(1) << __FUNCTION__; | 724 DVLOG(1) << __FUNCTION__; |
| 705 | 725 |
| 726 DCHECK(provision_fetcher_); |
| 727 |
| 706 JNIEnv* env = AttachCurrentThread(); | 728 JNIEnv* env = AttachCurrentThread(); |
| 707 CHECK(env); | 729 CHECK(env); |
| 708 | 730 |
| 709 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 731 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 710 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 732 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 711 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 733 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 712 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 734 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
| 713 } | 735 } |
| 714 | 736 |
| 715 MediaDrmBridge::~MediaDrmBridge() { | 737 MediaDrmBridge::~MediaDrmBridge() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 DCHECK(!GetMediaCrypto().is_null()); | 771 DCHECK(!GetMediaCrypto().is_null()); |
| 750 | 772 |
| 751 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. | 773 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. |
| 752 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( | 774 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( |
| 753 new ScopedJavaGlobalRef<jobject>()); | 775 new ScopedJavaGlobalRef<jobject>()); |
| 754 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); | 776 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); |
| 755 | 777 |
| 756 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); | 778 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); |
| 757 } | 779 } |
| 758 | 780 |
| 781 void MediaDrmBridge::SendProvisioningRequest(const std::string& default_url, |
| 782 const std::string& request_data) { |
| 783 DVLOG(1) << __FUNCTION__; |
| 784 |
| 785 provision_fetcher_->Retrieve( |
| 786 default_url, request_data, |
| 787 base::Bind(&MediaDrmBridge::ProcessProvisionResponse, |
| 788 weak_factory_.GetWeakPtr())); |
| 789 } |
| 790 |
| 791 void MediaDrmBridge::ProcessProvisionResponse(bool success, |
| 792 const std::string& response) { |
| 793 DVLOG(1) << __FUNCTION__; |
| 794 |
| 795 if (!success) |
| 796 VLOG(1) << "Device provision failure: can't get server response"; |
| 797 |
| 798 JNIEnv* env = AttachCurrentThread(); |
| 799 |
| 800 ScopedJavaLocalRef<jbyteArray> j_response = base::android::ToJavaByteArray( |
| 801 env, reinterpret_cast<const uint8_t*>(response.data()), response.size()); |
| 802 |
| 803 Java_MediaDrmBridge_processProvisionResponse(env, j_media_drm_.obj(), success, |
| 804 j_response.obj()); |
| 805 } |
| 806 |
| 759 } // namespace media | 807 } // namespace media |
| OLD | NEW |