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