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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 return std::vector<std::string>(); | 293 return std::vector<std::string>(); |
| 294 | 294 |
| 295 return GetKeySystemManager()->GetPlatformKeySystemNames(); | 295 return GetKeySystemManager()->GetPlatformKeySystemNames(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 // static | 298 // static |
| 299 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( | 299 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( |
| 300 const std::string& key_system, | 300 const std::string& key_system, |
| 301 SecurityLevel security_level, | 301 SecurityLevel security_level, |
| 302 const CreateFetcherCB& create_fetcher_cb, | 302 const CreateFetcherCB& create_fetcher_cb, |
| 303 const CreateStorageCB& create_storage_cb, | |
| 303 const SessionMessageCB& session_message_cb, | 304 const SessionMessageCB& session_message_cb, |
| 304 const SessionClosedCB& session_closed_cb, | 305 const SessionClosedCB& session_closed_cb, |
| 305 const SessionKeysChangeCB& session_keys_change_cb, | 306 const SessionKeysChangeCB& session_keys_change_cb, |
| 306 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 307 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 307 // All paths requires the MediaDrmApis. | 308 // All paths requires the MediaDrmApis. |
| 308 DCHECK(AreMediaDrmApisAvailable()); | 309 DCHECK(AreMediaDrmApisAvailable()); |
| 309 | 310 |
| 310 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); | 311 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); |
| 311 if (scheme_uuid.empty()) | 312 if (scheme_uuid.empty()) |
| 312 return nullptr; | 313 return nullptr; |
| 313 | 314 |
| 314 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( | 315 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( |
| 315 scheme_uuid, security_level, create_fetcher_cb, session_message_cb, | 316 scheme_uuid, security_level, create_fetcher_cb, create_storage_cb, |
| 316 session_closed_cb, session_keys_change_cb, session_expiration_update_cb)); | 317 session_message_cb, session_closed_cb, session_keys_change_cb, |
| 318 session_expiration_update_cb)); | |
| 317 | 319 |
| 318 if (media_drm_bridge->j_media_drm_.is_null()) | 320 if (media_drm_bridge->j_media_drm_.is_null()) |
| 319 media_drm_bridge = nullptr; | 321 media_drm_bridge = nullptr; |
| 320 | 322 |
| 321 return media_drm_bridge; | 323 return media_drm_bridge; |
| 322 } | 324 } |
| 323 | 325 |
| 324 // static | 326 // static |
| 325 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( | 327 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( |
| 326 const std::string& key_system, | 328 const std::string& key_system, |
| 327 SecurityLevel security_level, | 329 SecurityLevel security_level, |
| 328 const CreateFetcherCB& create_fetcher_cb, | 330 const CreateFetcherCB& create_fetcher_cb, |
| 331 const CreateStorageCB& create_storage_cb, | |
| 329 const SessionMessageCB& session_message_cb, | 332 const SessionMessageCB& session_message_cb, |
| 330 const SessionClosedCB& session_closed_cb, | 333 const SessionClosedCB& session_closed_cb, |
| 331 const SessionKeysChangeCB& session_keys_change_cb, | 334 const SessionKeysChangeCB& session_keys_change_cb, |
| 332 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 335 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 333 DVLOG(1) << __func__; | 336 DVLOG(1) << __func__; |
| 334 | 337 |
| 335 if (!IsAvailable()) | 338 if (!IsAvailable()) |
| 336 return nullptr; | 339 return nullptr; |
| 337 | 340 |
| 338 return CreateInternal(key_system, security_level, create_fetcher_cb, | 341 return CreateInternal(key_system, security_level, create_fetcher_cb, |
| 339 session_message_cb, session_closed_cb, | 342 create_storage_cb, session_message_cb, |
| 340 session_keys_change_cb, session_expiration_update_cb); | 343 session_closed_cb, session_keys_change_cb, |
| 344 session_expiration_update_cb); | |
| 341 } | 345 } |
| 342 | 346 |
| 343 // static | 347 // static |
| 344 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 348 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( |
| 345 const std::string& key_system, | 349 const std::string& key_system, |
| 346 SecurityLevel security_level, | 350 SecurityLevel security_level, |
| 347 const CreateFetcherCB& create_fetcher_cb) { | 351 const CreateFetcherCB& create_fetcher_cb) { |
| 348 DVLOG(1) << __func__; | 352 DVLOG(1) << __func__; |
| 349 | 353 |
| 350 // Sessions won't be used so decoding capability is not required. | 354 // Sessions won't be used so decoding capability is not required. |
| 351 if (!AreMediaDrmApisAvailable()) | 355 if (!AreMediaDrmApisAvailable()) |
| 352 return nullptr; | 356 return nullptr; |
| 353 | 357 |
| 354 return MediaDrmBridge::Create( | 358 return MediaDrmBridge::Create(key_system, security_level, create_fetcher_cb, |
| 355 key_system, security_level, create_fetcher_cb, SessionMessageCB(), | 359 CreateStorageCB(), SessionMessageCB(), |
| 356 SessionClosedCB(), SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 360 SessionClosedCB(), SessionKeysChangeCB(), |
| 361 SessionExpirationUpdateCB()); | |
| 357 } | 362 } |
| 358 | 363 |
| 359 void MediaDrmBridge::SetServerCertificate( | 364 void MediaDrmBridge::SetServerCertificate( |
| 360 const std::vector<uint8_t>& certificate, | 365 const std::vector<uint8_t>& certificate, |
| 361 std::unique_ptr<media::SimpleCdmPromise> promise) { | 366 std::unique_ptr<media::SimpleCdmPromise> promise) { |
| 362 DCHECK(task_runner_->BelongsToCurrentThread()); | 367 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 363 DVLOG(2) << __func__ << "(" << certificate.size() << " bytes)"; | 368 DVLOG(2) << __func__ << "(" << certificate.size() << " bytes)"; |
| 364 | 369 |
| 365 DCHECK(!certificate.empty()); | 370 DCHECK(!certificate.empty()); |
| 366 | 371 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); | 758 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); |
| 754 } | 759 } |
| 755 | 760 |
| 756 //------------------------------------------------------------------------------ | 761 //------------------------------------------------------------------------------ |
| 757 // The following are private methods. | 762 // The following are private methods. |
| 758 | 763 |
| 759 MediaDrmBridge::MediaDrmBridge( | 764 MediaDrmBridge::MediaDrmBridge( |
| 760 const std::vector<uint8_t>& scheme_uuid, | 765 const std::vector<uint8_t>& scheme_uuid, |
| 761 SecurityLevel security_level, | 766 SecurityLevel security_level, |
| 762 const CreateFetcherCB& create_fetcher_cb, | 767 const CreateFetcherCB& create_fetcher_cb, |
| 768 const CreateStorageCB& create_storage_cb, | |
| 763 const SessionMessageCB& session_message_cb, | 769 const SessionMessageCB& session_message_cb, |
| 764 const SessionClosedCB& session_closed_cb, | 770 const SessionClosedCB& session_closed_cb, |
| 765 const SessionKeysChangeCB& session_keys_change_cb, | 771 const SessionKeysChangeCB& session_keys_change_cb, |
| 766 const SessionExpirationUpdateCB& session_expiration_update_cb) | 772 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 767 : scheme_uuid_(scheme_uuid), | 773 : scheme_uuid_(scheme_uuid), |
| 768 create_fetcher_cb_(create_fetcher_cb), | 774 create_fetcher_cb_(create_fetcher_cb), |
| 775 create_storage_cb_(create_storage_cb), | |
|
yucliu1
2017/03/23 01:07:16
Just curious, why do want to keep create_storage_c
xhwang
2017/03/23 05:22:06
This is for the "lazy creation" of the storage. Fo
| |
| 769 session_message_cb_(session_message_cb), | 776 session_message_cb_(session_message_cb), |
| 770 session_closed_cb_(session_closed_cb), | 777 session_closed_cb_(session_closed_cb), |
| 771 session_keys_change_cb_(session_keys_change_cb), | 778 session_keys_change_cb_(session_keys_change_cb), |
| 772 session_expiration_update_cb_(session_expiration_update_cb), | 779 session_expiration_update_cb_(session_expiration_update_cb), |
| 773 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 780 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 774 media_drm_bridge_cdm_context_(this), | 781 media_drm_bridge_cdm_context_(this), |
| 775 weak_factory_(this) { | 782 weak_factory_(this) { |
| 776 DVLOG(1) << __func__; | 783 DVLOG(1) << __func__; |
| 777 | 784 |
| 778 DCHECK(!create_fetcher_cb_.is_null()); | 785 DCHECK(!create_fetcher_cb_.is_null()); |
| 779 | 786 |
| 780 JNIEnv* env = AttachCurrentThread(); | 787 JNIEnv* env = AttachCurrentThread(); |
| 781 CHECK(env); | 788 CHECK(env); |
| 782 | 789 |
| 783 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 790 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 784 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 791 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 785 | 792 |
| 786 std::string security_level_str = GetSecurityLevelString(security_level); | 793 std::string security_level_str = GetSecurityLevelString(security_level); |
| 787 ScopedJavaLocalRef<jstring> j_security_level = | 794 ScopedJavaLocalRef<jstring> j_security_level = |
| 788 ConvertUTF8ToJavaString(env, security_level_str); | 795 ConvertUTF8ToJavaString(env, security_level_str); |
| 789 | 796 |
| 797 media_drm_storage_ = create_storage_cb_.Run(); | |
| 798 | |
| 799 // Test code!!! | |
| 800 media_drm_storage_->Initialize( | |
| 801 url::Origin(GURL("https://www.foobar.com:80"))); | |
| 802 media_drm_storage_->OnProvisioned( | |
| 803 base::Bind(&MediaDrmBridge::OnStorageResult, weak_factory_.GetWeakPtr())); | |
| 804 media_drm_storage_->SavePersistentSession( | |
| 805 "fake session id", {1, 2}, "fake mime type", | |
| 806 base::Bind(&MediaDrmBridge::OnStorageResult, weak_factory_.GetWeakPtr())); | |
| 807 | |
| 790 // Note: OnMediaCryptoReady() could be called in this call. | 808 // Note: OnMediaCryptoReady() could be called in this call. |
| 791 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 809 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 792 env, j_scheme_uuid, j_security_level, reinterpret_cast<intptr_t>(this))); | 810 env, j_scheme_uuid, j_security_level, reinterpret_cast<intptr_t>(this))); |
| 793 } | 811 } |
| 794 | 812 |
| 813 void MediaDrmBridge::OnStorageResult(bool success) { | |
| 814 LOG(ERROR) << __func__ << ": " << success; | |
| 815 } | |
| 816 | |
| 795 MediaDrmBridge::~MediaDrmBridge() { | 817 MediaDrmBridge::~MediaDrmBridge() { |
| 796 DCHECK(task_runner_->BelongsToCurrentThread()); | 818 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 797 DVLOG(1) << __func__; | 819 DVLOG(1) << __func__; |
| 798 | 820 |
| 799 JNIEnv* env = AttachCurrentThread(); | 821 JNIEnv* env = AttachCurrentThread(); |
| 800 | 822 |
| 801 // After the call to Java_MediaDrmBridge_destroy() Java won't call native | 823 // After the call to Java_MediaDrmBridge_destroy() Java won't call native |
| 802 // methods anymore, this is ensured by MediaDrmBridge.java. | 824 // methods anymore, this is ensured by MediaDrmBridge.java. |
| 803 if (!j_media_drm_.is_null()) | 825 if (!j_media_drm_.is_null()) |
| 804 Java_MediaDrmBridge_destroy(env, j_media_drm_); | 826 Java_MediaDrmBridge_destroy(env, j_media_drm_); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 } | 912 } |
| 891 | 913 |
| 892 void MediaDrmBridge::OnHasAdditionalUsableKey() { | 914 void MediaDrmBridge::OnHasAdditionalUsableKey() { |
| 893 DCHECK(task_runner_->BelongsToCurrentThread()); | 915 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 894 DVLOG(1) << __func__; | 916 DVLOG(1) << __func__; |
| 895 | 917 |
| 896 player_tracker_.NotifyNewKey(); | 918 player_tracker_.NotifyNewKey(); |
| 897 } | 919 } |
| 898 | 920 |
| 899 } // namespace media | 921 } // namespace media |
| OLD | NEW |