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/media_task_runner.h" | 28 #include "media/base/android/media_task_runner.h" |
| 29 #include "media/base/cdm_key_information.h" | 29 #include "media/base/cdm_key_information.h" |
| 30 #include "media/base/provision_fetcher.h" | |
| 30 | 31 |
| 31 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 32 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 32 | 33 |
| 33 using base::android::AttachCurrentThread; | 34 using base::android::AttachCurrentThread; |
| 34 using base::android::ConvertUTF8ToJavaString; | 35 using base::android::ConvertUTF8ToJavaString; |
| 35 using base::android::ConvertJavaStringToUTF8; | 36 using base::android::ConvertJavaStringToUTF8; |
| 36 using base::android::JavaByteArrayToByteVector; | 37 using base::android::JavaByteArrayToByteVector; |
| 37 using base::android::ScopedJavaGlobalRef; | 38 using base::android::ScopedJavaGlobalRef; |
| 38 using base::android::ScopedJavaLocalRef; | 39 using base::android::ScopedJavaLocalRef; |
| 39 | 40 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 52 // These must be in sync with Android MediaDrm KEY_STATUS_XXX constants: | 53 // These must be in sync with Android MediaDrm KEY_STATUS_XXX constants: |
| 53 // https://developer.android.com/reference/android/media/MediaDrm.KeyStatus.html | 54 // https://developer.android.com/reference/android/media/MediaDrm.KeyStatus.html |
| 54 enum class KeyStatus { | 55 enum class KeyStatus { |
| 55 KEY_STATUS_USABLE = 0, | 56 KEY_STATUS_USABLE = 0, |
| 56 KEY_STATUS_EXPIRED = 1, | 57 KEY_STATUS_EXPIRED = 1, |
| 57 KEY_STATUS_OUTPUT_NOT_ALLOWED = 2, | 58 KEY_STATUS_OUTPUT_NOT_ALLOWED = 2, |
| 58 KEY_STATUS_PENDING = 3, | 59 KEY_STATUS_PENDING = 3, |
| 59 KEY_STATUS_INTERNAL_ERROR = 4, | 60 KEY_STATUS_INTERNAL_ERROR = 4, |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 // Returns string session ID from jbyteArray (byte[] in Java). | 63 // Converts jbyteArray (byte[] in Java) into std::string. |
| 63 std::string GetSessionId(JNIEnv* env, jbyteArray j_session_id) { | 64 std::string AsString(JNIEnv* env, jbyteArray j_byte_array) { |
| 64 std::vector<uint8> session_id_vector; | 65 std::vector<uint8_t> byte_vector; |
| 65 JavaByteArrayToByteVector(env, j_session_id, &session_id_vector); | 66 JavaByteArrayToByteVector(env, j_byte_array, &byte_vector); |
| 66 return std::string(session_id_vector.begin(), session_id_vector.end()); | 67 return std::string(byte_vector.begin(), byte_vector.end()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 const uint8 kWidevineUuid[16] = { | 70 const uint8 kWidevineUuid[16] = { |
| 70 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // | 71 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // |
| 71 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED}; | 72 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED}; |
| 72 | 73 |
| 73 // Convert |init_data_type| to a string supported by MediaDRM. | 74 // Convert |init_data_type| to a string supported by MediaDRM. |
| 74 // "audio"/"video" does not matter, so use "video". | 75 // "audio"/"video" does not matter, so use "video". |
| 75 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) { | 76 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) { |
| 76 // TODO(jrummell/xhwang): EME init data types like "webm" and "cenc" are | 77 // TODO(jrummell/xhwang): EME init data types like "webm" and "cenc" are |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 } | 282 } |
| 282 | 283 |
| 283 // static | 284 // static |
| 284 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | 285 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 285 return g_key_system_manager.Get().GetPlatformKeySystemNames(); | 286 return g_key_system_manager.Get().GetPlatformKeySystemNames(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 // static | 289 // static |
| 289 ScopedMediaDrmBridgePtr MediaDrmBridge::Create( | 290 ScopedMediaDrmBridgePtr MediaDrmBridge::Create( |
| 290 const std::string& key_system, | 291 const std::string& key_system, |
| 292 scoped_ptr<ProvisionFetcher> provision_fetcher, | |
| 291 const SessionMessageCB& session_message_cb, | 293 const SessionMessageCB& session_message_cb, |
| 292 const SessionClosedCB& session_closed_cb, | 294 const SessionClosedCB& session_closed_cb, |
| 293 const LegacySessionErrorCB& legacy_session_error_cb, | 295 const LegacySessionErrorCB& legacy_session_error_cb, |
| 294 const SessionKeysChangeCB& session_keys_change_cb, | 296 const SessionKeysChangeCB& session_keys_change_cb, |
| 295 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 297 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 296 DVLOG(1) << __FUNCTION__; | 298 DVLOG(1) << __FUNCTION__; |
| 297 | 299 |
| 298 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge; | 300 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge; |
| 299 if (!IsAvailable()) | 301 if (!IsAvailable()) |
| 300 return media_drm_bridge.Pass(); | 302 return media_drm_bridge.Pass(); |
| 301 | 303 |
| 302 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 304 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); |
| 303 if (scheme_uuid.empty()) | 305 if (scheme_uuid.empty()) |
| 304 return media_drm_bridge.Pass(); | 306 return media_drm_bridge.Pass(); |
| 305 | 307 |
| 306 media_drm_bridge.reset( | 308 media_drm_bridge.reset(new MediaDrmBridge( |
| 307 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, | 309 scheme_uuid, provision_fetcher.Pass(), session_message_cb, |
| 308 legacy_session_error_cb, session_keys_change_cb, | 310 session_closed_cb, legacy_session_error_cb, session_keys_change_cb, |
| 309 session_expiration_update_cb)); | 311 session_expiration_update_cb)); |
| 310 | 312 |
| 311 if (media_drm_bridge->j_media_drm_.is_null()) | 313 if (media_drm_bridge->j_media_drm_.is_null()) |
| 312 media_drm_bridge.reset(); | 314 media_drm_bridge.reset(); |
| 313 | 315 |
| 314 return media_drm_bridge.Pass(); | 316 return media_drm_bridge.Pass(); |
| 315 } | 317 } |
| 316 | 318 |
| 317 // static | 319 // static |
| 318 ScopedMediaDrmBridgePtr MediaDrmBridge::CreateWithoutSessionSupport( | 320 ScopedMediaDrmBridgePtr MediaDrmBridge::CreateWithoutSessionSupport( |
| 319 const std::string& key_system) { | 321 const std::string& key_system) { |
| 320 return MediaDrmBridge::Create( | 322 scoped_ptr<ProvisionFetcher> provision_fetcher = |
| 321 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), | 323 GetMediaClientAndroid()->CreateDefaultFetcher(); |
| 322 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 324 |
| 325 DCHECK(provision_fetcher); | |
| 326 | |
| 327 return MediaDrmBridge::Create(key_system, provision_fetcher.Pass(), | |
| 328 SessionMessageCB(), SessionClosedCB(), | |
| 329 LegacySessionErrorCB(), SessionKeysChangeCB(), | |
| 330 SessionExpirationUpdateCB()); | |
| 323 } | 331 } |
| 324 | 332 |
| 325 base::WeakPtr<MediaDrmBridge> MediaDrmBridge::WeakPtr() { | 333 base::WeakPtr<MediaDrmBridge> MediaDrmBridge::WeakPtr() { |
| 326 return weak_factory_.GetWeakPtr(); | 334 return weak_factory_.GetWeakPtr(); |
| 327 } | 335 } |
| 328 | 336 |
| 329 void MediaDrmBridge::SetServerCertificate( | 337 void MediaDrmBridge::SetServerCertificate( |
| 330 const std::vector<uint8_t>& certificate, | 338 const std::vector<uint8_t>& certificate, |
| 331 scoped_ptr<media::SimpleCdmPromise> promise) { | 339 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 332 DVLOG(2) << __FUNCTION__; | 340 DVLOG(2) << __FUNCTION__; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 // For Widevine, this depends on the security level. | 495 // For Widevine, this depends on the security level. |
| 488 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) | 496 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) |
| 489 return IsSecureDecoderRequired(GetSecurityLevel()); | 497 return IsSecureDecoderRequired(GetSecurityLevel()); |
| 490 | 498 |
| 491 // For other key systems, assume true. | 499 // For other key systems, assume true. |
| 492 return true; | 500 return true; |
| 493 } | 501 } |
| 494 | 502 |
| 495 void MediaDrmBridge::ResetDeviceCredentials( | 503 void MediaDrmBridge::ResetDeviceCredentials( |
| 496 const ResetCredentialsCB& callback) { | 504 const ResetCredentialsCB& callback) { |
| 505 DVLOG(1) << __FUNCTION__; | |
| 506 | |
| 497 DCHECK(reset_credentials_cb_.is_null()); | 507 DCHECK(reset_credentials_cb_.is_null()); |
| 498 reset_credentials_cb_ = callback; | 508 reset_credentials_cb_ = callback; |
| 499 JNIEnv* env = AttachCurrentThread(); | 509 JNIEnv* env = AttachCurrentThread(); |
| 500 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 510 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 501 } | 511 } |
| 502 | 512 |
| 503 void MediaDrmBridge::ResolvePromise(uint32_t promise_id) { | 513 void MediaDrmBridge::ResolvePromise(uint32_t promise_id) { |
| 504 DVLOG(2) << __FUNCTION__; | 514 DVLOG(2) << __FUNCTION__; |
| 505 cdm_promise_adapter_->ResolvePromise(promise_id); | 515 cdm_promise_adapter_->ResolvePromise(promise_id); |
| 506 } | 516 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 DVLOG(1) << __FUNCTION__; | 565 DVLOG(1) << __FUNCTION__; |
| 556 | 566 |
| 557 if (media_crypto_ready_cb_.is_null()) | 567 if (media_crypto_ready_cb_.is_null()) |
| 558 return; | 568 return; |
| 559 | 569 |
| 560 task_runner_->PostTask( | 570 task_runner_->PostTask( |
| 561 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyMediaCryptoReady, WeakPtr(), | 571 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyMediaCryptoReady, WeakPtr(), |
| 562 base::ResetAndReturn(&media_crypto_ready_cb_))); | 572 base::ResetAndReturn(&media_crypto_ready_cb_))); |
| 563 } | 573 } |
| 564 | 574 |
| 575 void MediaDrmBridge::OnStartProvisioning(JNIEnv* env, | |
| 576 jobject j_media_drm, | |
| 577 jstring j_default_url, | |
| 578 jbyteArray j_request_data) { | |
| 579 DVLOG(1) << __FUNCTION__; | |
| 580 | |
| 581 task_runner_->PostTask( | |
| 582 FROM_HERE, base::Bind(&MediaDrmBridge::SendProvisioningRequest, WeakPtr(), | |
| 583 ConvertJavaStringToUTF8(env, j_default_url), | |
| 584 AsString(env, j_request_data))); | |
| 585 } | |
| 586 | |
| 565 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 587 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
| 566 jobject j_media_drm, | 588 jobject j_media_drm, |
| 567 jint j_promise_id) { | 589 jint j_promise_id) { |
| 568 task_runner_->PostTask(FROM_HERE, base::Bind(&MediaDrmBridge::ResolvePromise, | 590 task_runner_->PostTask(FROM_HERE, base::Bind(&MediaDrmBridge::ResolvePromise, |
| 569 WeakPtr(), j_promise_id)); | 591 WeakPtr(), j_promise_id)); |
| 570 } | 592 } |
| 571 | 593 |
| 572 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 594 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
| 573 jobject j_media_drm, | 595 jobject j_media_drm, |
| 574 jint j_promise_id, | 596 jint j_promise_id, |
| 575 jbyteArray j_session_id) { | 597 jbyteArray j_session_id) { |
| 576 task_runner_->PostTask( | 598 task_runner_->PostTask( |
| 577 FROM_HERE, | 599 FROM_HERE, |
| 578 base::Bind(&MediaDrmBridge::ResolvePromiseWithSession, WeakPtr(), | 600 base::Bind(&MediaDrmBridge::ResolvePromiseWithSession, WeakPtr(), |
| 579 j_promise_id, GetSessionId(env, j_session_id))); | 601 j_promise_id, AsString(env, j_session_id))); |
| 580 } | 602 } |
| 581 | 603 |
| 582 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, | 604 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, |
| 583 jobject j_media_drm, | 605 jobject j_media_drm, |
| 584 jint j_promise_id, | 606 jint j_promise_id, |
| 585 jstring j_error_message) { | 607 jstring j_error_message) { |
| 586 task_runner_->PostTask( | 608 task_runner_->PostTask( |
| 587 FROM_HERE, | 609 FROM_HERE, |
| 588 base::Bind(&MediaDrmBridge::RejectPromise, WeakPtr(), j_promise_id, | 610 base::Bind(&MediaDrmBridge::RejectPromise, WeakPtr(), j_promise_id, |
| 589 ConvertJavaStringToUTF8(env, j_error_message))); | 611 ConvertJavaStringToUTF8(env, j_error_message))); |
| 590 } | 612 } |
| 591 | 613 |
| 592 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, | 614 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, |
| 593 jobject j_media_drm, | 615 jobject j_media_drm, |
| 594 jbyteArray j_session_id, | 616 jbyteArray j_session_id, |
| 595 jint j_message_type, | 617 jint j_message_type, |
| 596 jbyteArray j_message, | 618 jbyteArray j_message, |
| 597 jstring j_legacy_destination_url) { | 619 jstring j_legacy_destination_url) { |
| 598 DVLOG(2) << __FUNCTION__; | 620 DVLOG(2) << __FUNCTION__; |
| 599 | 621 |
| 600 std::vector<uint8> message; | 622 std::vector<uint8> message; |
| 601 JavaByteArrayToByteVector(env, j_message, &message); | 623 JavaByteArrayToByteVector(env, j_message, &message); |
| 602 GURL legacy_destination_url = | 624 GURL legacy_destination_url = |
| 603 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); | 625 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); |
| 604 MediaKeys::MessageType message_type = | 626 MediaKeys::MessageType message_type = |
| 605 GetMessageType(static_cast<RequestType>(j_message_type)); | 627 GetMessageType(static_cast<RequestType>(j_message_type)); |
| 606 | 628 |
| 607 task_runner_->PostTask( | 629 task_runner_->PostTask( |
| 608 FROM_HERE, | 630 FROM_HERE, base::Bind(session_message_cb_, AsString(env, j_session_id), |
| 609 base::Bind(session_message_cb_, GetSessionId(env, j_session_id), | 631 message_type, message, legacy_destination_url)); |
| 610 message_type, message, legacy_destination_url)); | |
| 611 } | 632 } |
| 612 | 633 |
| 613 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, | 634 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, |
| 614 jobject j_media_drm, | 635 jobject j_media_drm, |
| 615 jbyteArray j_session_id) { | 636 jbyteArray j_session_id) { |
| 616 DVLOG(2) << __FUNCTION__; | 637 DVLOG(2) << __FUNCTION__; |
| 617 std::string session_id = GetSessionId(env, j_session_id); | 638 std::string session_id = AsString(env, j_session_id); |
| 618 task_runner_->PostTask(FROM_HERE, base::Bind(session_closed_cb_, session_id)); | 639 task_runner_->PostTask(FROM_HERE, base::Bind(session_closed_cb_, session_id)); |
| 619 } | 640 } |
| 620 | 641 |
| 621 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 642 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
| 622 jobject j_media_drm, | 643 jobject j_media_drm, |
| 623 jbyteArray j_session_id, | 644 jbyteArray j_session_id, |
| 624 jobjectArray j_keys_info, | 645 jobjectArray j_keys_info, |
| 625 bool has_additional_usable_key) { | 646 bool has_additional_usable_key) { |
| 626 DVLOG(2) << __FUNCTION__; | 647 DVLOG(2) << __FUNCTION__; |
| 627 | 648 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 654 // TODO(xhwang): Update CdmKeyInformation to take key_id and status in the | 675 // TODO(xhwang): Update CdmKeyInformation to take key_id and status in the |
| 655 // constructor. | 676 // constructor. |
| 656 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | 677 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); |
| 657 cdm_key_information->key_id = key_id; | 678 cdm_key_information->key_id = key_id; |
| 658 cdm_key_information->status = key_status; | 679 cdm_key_information->status = key_status; |
| 659 cdm_keys_info.push_back(cdm_key_information.release()); | 680 cdm_keys_info.push_back(cdm_key_information.release()); |
| 660 } | 681 } |
| 661 | 682 |
| 662 task_runner_->PostTask( | 683 task_runner_->PostTask( |
| 663 FROM_HERE, | 684 FROM_HERE, |
| 664 base::Bind(session_keys_change_cb_, GetSessionId(env, j_session_id), | 685 base::Bind(session_keys_change_cb_, AsString(env, j_session_id), |
| 665 has_additional_usable_key, base::Passed(&cdm_keys_info))); | 686 has_additional_usable_key, base::Passed(&cdm_keys_info))); |
| 666 } | 687 } |
| 667 | 688 |
| 668 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 689 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys |
| 669 // will never expire. This will be translated into a NULL base::Time() [2], | 690 // will never expire. This will be translated into a NULL base::Time() [2], |
| 670 // which will then be mapped to a zero Java time [3]. The zero Java time is | 691 // which will then be mapped to a zero Java time [3]. The zero Java time is |
| 671 // passed to Blink which will then be translated to NaN [4], which is what the | 692 // passed to Blink which will then be translated to NaN [4], which is what the |
| 672 // spec uses to indicate that the license will never expire [5]. | 693 // spec uses to indicate that the license will never expire [5]. |
| 673 // [1] | 694 // [1] |
| 674 // http://developer.android.com/reference/android/media/MediaDrm.OnExpirationUpd ateListener.html | 695 // http://developer.android.com/reference/android/media/MediaDrm.OnExpirationUpd ateListener.html |
| 675 // [2] See base::Time::FromDoubleT() | 696 // [2] See base::Time::FromDoubleT() |
| 676 // [3] See base::Time::ToJavaTime() | 697 // [3] See base::Time::ToJavaTime() |
| 677 // [4] See MediaKeySession::expirationChanged() | 698 // [4] See MediaKeySession::expirationChanged() |
| 678 // [5] https://github.com/w3c/encrypted-media/issues/58 | 699 // [5] https://github.com/w3c/encrypted-media/issues/58 |
| 679 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, | 700 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, |
| 680 jobject j_media_drm, | 701 jobject j_media_drm, |
| 681 jbyteArray j_session_id, | 702 jbyteArray j_session_id, |
| 682 jlong expiry_time_ms) { | 703 jlong expiry_time_ms) { |
| 683 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; | 704 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; |
| 684 session_expiration_update_cb_.Run( | 705 session_expiration_update_cb_.Run( |
| 685 GetSessionId(env, j_session_id), | 706 AsString(env, j_session_id), |
| 686 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); | 707 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); |
| 687 } | 708 } |
| 688 | 709 |
| 689 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 710 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
| 690 jobject j_media_drm, | 711 jobject j_media_drm, |
| 691 jbyteArray j_session_id, | 712 jbyteArray j_session_id, |
| 692 jstring j_error_message) { | 713 jstring j_error_message) { |
| 693 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 714 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
| 694 | 715 |
| 695 DVLOG(2) << __FUNCTION__ << ": " << error_message; | 716 DVLOG(2) << __FUNCTION__ << ": " << error_message; |
| 696 | 717 |
| 697 task_runner_->PostTask( | 718 task_runner_->PostTask( |
| 698 FROM_HERE, | 719 FROM_HERE, |
| 699 base::Bind(legacy_session_error_cb_, GetSessionId(env, j_session_id), | 720 base::Bind(legacy_session_error_cb_, AsString(env, j_session_id), |
| 700 MediaKeys::UNKNOWN_ERROR, 0, error_message)); | 721 MediaKeys::UNKNOWN_ERROR, 0, error_message)); |
| 701 } | 722 } |
| 702 | 723 |
| 703 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(JNIEnv* env, | 724 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(JNIEnv* env, |
| 704 jobject, | 725 jobject, |
| 705 bool success) { | 726 bool success) { |
| 706 DVLOG(2) << __FUNCTION__ << ": " << success; | 727 DVLOG(2) << __FUNCTION__ << ": success:" << success; |
| 707 DCHECK(!reset_credentials_cb_.is_null()); | 728 DCHECK(!reset_credentials_cb_.is_null()); |
| 708 task_runner_->PostTask( | 729 task_runner_->PostTask( |
| 709 FROM_HERE, | 730 FROM_HERE, |
| 710 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); | 731 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); |
| 711 } | 732 } |
| 712 | 733 |
| 713 // The following are private methods. | 734 // The following are private methods. |
| 714 | 735 |
| 715 MediaDrmBridge::MediaDrmBridge( | 736 MediaDrmBridge::MediaDrmBridge( |
| 716 const std::vector<uint8>& scheme_uuid, | 737 const std::vector<uint8>& scheme_uuid, |
| 738 scoped_ptr<ProvisionFetcher> provision_fetcher, | |
| 717 const SessionMessageCB& session_message_cb, | 739 const SessionMessageCB& session_message_cb, |
| 718 const SessionClosedCB& session_closed_cb, | 740 const SessionClosedCB& session_closed_cb, |
| 719 const LegacySessionErrorCB& legacy_session_error_cb, | 741 const LegacySessionErrorCB& legacy_session_error_cb, |
| 720 const SessionKeysChangeCB& session_keys_change_cb, | 742 const SessionKeysChangeCB& session_keys_change_cb, |
| 721 const SessionExpirationUpdateCB& session_expiration_update_cb) | 743 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 722 : scheme_uuid_(scheme_uuid), | 744 : scheme_uuid_(scheme_uuid), |
| 745 provision_fetcher_(provision_fetcher.Pass()), | |
| 723 session_message_cb_(session_message_cb), | 746 session_message_cb_(session_message_cb), |
| 724 session_closed_cb_(session_closed_cb), | 747 session_closed_cb_(session_closed_cb), |
| 725 legacy_session_error_cb_(legacy_session_error_cb), | 748 legacy_session_error_cb_(legacy_session_error_cb), |
| 726 session_keys_change_cb_(session_keys_change_cb), | 749 session_keys_change_cb_(session_keys_change_cb), |
| 727 session_expiration_update_cb_(session_expiration_update_cb), | 750 session_expiration_update_cb_(session_expiration_update_cb), |
| 728 cdm_promise_adapter_(new CdmPromiseAdapter()), | 751 cdm_promise_adapter_(new CdmPromiseAdapter()), |
| 729 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 752 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 730 use_media_thread_(UseMediaThreadForMediaPlayback()), | 753 use_media_thread_(UseMediaThreadForMediaPlayback()), |
| 731 media_weak_factory_(this), | 754 media_weak_factory_(this), |
| 732 weak_factory_(this) { | 755 weak_factory_(this) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 DCHECK(!GetMediaCrypto().is_null()); | 802 DCHECK(!GetMediaCrypto().is_null()); |
| 780 | 803 |
| 781 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. | 804 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. |
| 782 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( | 805 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( |
| 783 new ScopedJavaGlobalRef<jobject>()); | 806 new ScopedJavaGlobalRef<jobject>()); |
| 784 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); | 807 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); |
| 785 | 808 |
| 786 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); | 809 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); |
| 787 } | 810 } |
| 788 | 811 |
| 812 void MediaDrmBridge::SendProvisioningRequest(const std::string& default_url, | |
| 813 const std::string& request_data) { | |
| 814 DVLOG(1) << __FUNCTION__; | |
| 815 | |
| 816 provision_fetcher_->Retrieve( | |
| 817 default_url, request_data, | |
| 818 base::Bind(&MediaDrmBridge::ProcessProvisionResponse, WeakPtr())); | |
| 819 } | |
| 820 | |
| 821 void MediaDrmBridge::ProcessProvisionResponse(bool success, | |
| 822 const std::string& response) { | |
| 823 DVLOG(1) << __FUNCTION__; | |
| 824 | |
| 825 if (!success) { | |
| 826 VLOG(1) << "Device provision failure: can't get server response"; | |
| 827 return; | |
| 828 } | |
| 829 | |
| 830 JNIEnv* env = AttachCurrentThread(); | |
| 831 | |
| 832 ScopedJavaLocalRef<jbyteArray> j_response = base::android::ToJavaByteArray( | |
| 833 env, (uint8_t*)response.data(), response.size()); | |
|
xhwang
2015/11/06 23:08:19
static_cast instead of C-style cast.
Tima Vaisburd
2015/11/11 03:03:34
reinterpret_cast, signed and unsigned char seems t
| |
| 834 | |
| 835 Java_MediaDrmBridge_processProvisionResponse(env, j_media_drm_.obj(), | |
| 836 j_response.obj()); | |
| 837 } | |
| 838 | |
| 789 } // namespace media | 839 } // namespace media |
| OLD | NEW |