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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 | 312 |
| 313 // static | 313 // static |
| 314 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | 314 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 315 if (!MediaDrmBridge::IsAvailable()) | 315 if (!MediaDrmBridge::IsAvailable()) |
| 316 return std::vector<std::string>(); | 316 return std::vector<std::string>(); |
| 317 | 317 |
| 318 return GetKeySystemManager()->GetPlatformKeySystemNames(); | 318 return GetKeySystemManager()->GetPlatformKeySystemNames(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // static | 321 // static |
| 322 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( | 322 void MediaDrmBridge::CreateInternal( |
| 323 const std::string& key_system, | 323 const std::vector<uint8_t>& scheme_uuid, |
| 324 const GURL& security_origin, | |
| 325 SecurityLevel security_level, | 324 SecurityLevel security_level, |
| 325 std::unique_ptr<MediaDrmStorageBridge> storage, | |
| 326 const CreateFetcherCB& create_fetcher_cb, | 326 const CreateFetcherCB& create_fetcher_cb, |
| 327 const CreateStorageCB& create_storage_cb, | |
| 328 const SessionMessageCB& session_message_cb, | 327 const SessionMessageCB& session_message_cb, |
| 329 const SessionClosedCB& session_closed_cb, | 328 const SessionClosedCB& session_closed_cb, |
| 330 const SessionKeysChangeCB& session_keys_change_cb, | 329 const SessionKeysChangeCB& session_keys_change_cb, |
| 331 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 330 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 331 CreatedCB created_cb) { | |
| 332 // All paths requires the MediaDrmApis. | 332 // All paths requires the MediaDrmApis. |
| 333 DCHECK(AreMediaDrmApisAvailable()); | 333 DCHECK(AreMediaDrmApisAvailable()); |
| 334 | 334 DCHECK(!scheme_uuid.empty()); |
| 335 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); | |
| 336 if (scheme_uuid.empty()) | |
| 337 return nullptr; | |
| 338 | 335 |
| 339 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( | 336 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( |
| 340 scheme_uuid, security_origin, security_level, create_fetcher_cb, | 337 scheme_uuid, security_level, std::move(storage), create_fetcher_cb, |
| 341 create_storage_cb, session_message_cb, session_closed_cb, | 338 session_message_cb, session_closed_cb, session_keys_change_cb, |
| 342 session_keys_change_cb, session_expiration_update_cb)); | 339 session_expiration_update_cb)); |
| 343 | 340 |
| 344 if (media_drm_bridge->j_media_drm_.is_null()) | 341 if (media_drm_bridge->j_media_drm_.is_null()) |
| 345 media_drm_bridge = nullptr; | 342 media_drm_bridge = nullptr; |
| 346 | 343 |
| 347 return media_drm_bridge; | 344 std::move(created_cb).Run(std::move(media_drm_bridge)); |
|
xhwang
2017/07/21 18:18:26
Add a comment why we want to return the CDM asynch
yucliu1
2017/07/21 20:24:09
Done.
| |
| 348 } | 345 } |
| 349 | 346 |
| 350 // static | 347 // static |
| 351 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( | 348 void MediaDrmBridge::Create( |
| 352 const std::string& key_system, | 349 const std::string& key_system, |
| 353 const GURL& security_origin, | 350 const GURL& security_origin, |
| 354 SecurityLevel security_level, | 351 SecurityLevel security_level, |
| 355 const CreateFetcherCB& create_fetcher_cb, | 352 const CreateFetcherCB& create_fetcher_cb, |
| 356 const CreateStorageCB& create_storage_cb, | 353 const CreateStorageCB& create_storage_cb, |
| 357 const SessionMessageCB& session_message_cb, | 354 const SessionMessageCB& session_message_cb, |
| 358 const SessionClosedCB& session_closed_cb, | 355 const SessionClosedCB& session_closed_cb, |
| 359 const SessionKeysChangeCB& session_keys_change_cb, | 356 const SessionKeysChangeCB& session_keys_change_cb, |
| 360 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 357 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 358 CreatedCB created_cb) { | |
| 361 DVLOG(1) << __func__; | 359 DVLOG(1) << __func__; |
| 362 | 360 |
| 363 if (!IsAvailable()) | 361 if (!IsAvailable()) { |
| 364 return nullptr; | 362 std::move(created_cb).Run(nullptr); |
| 363 return; | |
| 364 } | |
| 365 | 365 |
| 366 return CreateInternal(key_system, security_origin, security_level, | 366 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); |
| 367 create_fetcher_cb, create_storage_cb, | 367 if (scheme_uuid.empty()) { |
| 368 session_message_cb, session_closed_cb, | 368 std::move(created_cb).Run(nullptr); |
| 369 session_keys_change_cb, session_expiration_update_cb); | 369 return; |
| 370 } | |
| 371 | |
| 372 // MediaDrmStorage may be lazy created in MediaDrmStorageBridge. | |
| 373 auto storage = base::MakeUnique<MediaDrmStorageBridge>(); | |
| 374 MediaDrmStorageBridge* raw_storage = storage.get(); | |
| 375 | |
| 376 base::OnceClosure create_media_drm_cb = base::BindOnce( | |
| 377 &MediaDrmBridge::CreateInternal, scheme_uuid, security_level, | |
| 378 base::Passed(&storage), create_fetcher_cb, session_message_cb, | |
| 379 session_closed_cb, session_keys_change_cb, session_expiration_update_cb, | |
| 380 base::Passed(&created_cb)); | |
| 381 | |
| 382 if (IsPersistentLicenseTypeSupported(key_system) && | |
| 383 !security_origin.is_empty() && !create_storage_cb.is_null()) { | |
| 384 raw_storage->Initialize(url::Origin(security_origin), create_storage_cb, | |
| 385 std::move(create_media_drm_cb)); | |
| 386 } else { | |
| 387 std::move(create_media_drm_cb).Run(); | |
| 388 } | |
| 370 } | 389 } |
| 371 | 390 |
| 372 // static | 391 // static |
| 373 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 392 void MediaDrmBridge::CreateWithoutSessionSupport( |
| 374 const std::string& key_system, | 393 const std::string& key_system, |
| 375 SecurityLevel security_level, | 394 SecurityLevel security_level, |
| 376 const CreateFetcherCB& create_fetcher_cb) { | 395 const CreateFetcherCB& create_fetcher_cb, |
| 396 CreatedCB created_cb) { | |
| 377 DVLOG(1) << __func__; | 397 DVLOG(1) << __func__; |
| 378 | 398 |
| 379 // Sessions won't be used so decoding capability is not required. | 399 // Sessions won't be used so decoding capability is not required. |
| 380 if (!AreMediaDrmApisAvailable()) | 400 if (!AreMediaDrmApisAvailable()) { |
| 381 return nullptr; | 401 std::move(created_cb).Run(nullptr); |
| 402 return; | |
| 403 } | |
| 382 | 404 |
| 383 return MediaDrmBridge::Create( | 405 MediaDrmBridge::Create(key_system, GURL::EmptyGURL(), security_level, |
| 384 key_system, GURL::EmptyGURL(), security_level, create_fetcher_cb, | 406 create_fetcher_cb, CreateStorageCB(), |
| 385 CreateStorageCB(), SessionMessageCB(), SessionClosedCB(), | 407 SessionMessageCB(), SessionClosedCB(), |
| 386 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 408 SessionKeysChangeCB(), SessionExpirationUpdateCB(), |
| 409 std::move(created_cb)); | |
| 387 } | 410 } |
| 388 | 411 |
| 389 void MediaDrmBridge::SetServerCertificate( | 412 void MediaDrmBridge::SetServerCertificate( |
| 390 const std::vector<uint8_t>& certificate, | 413 const std::vector<uint8_t>& certificate, |
| 391 std::unique_ptr<media::SimpleCdmPromise> promise) { | 414 std::unique_ptr<media::SimpleCdmPromise> promise) { |
| 392 DCHECK(task_runner_->BelongsToCurrentThread()); | 415 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 393 DVLOG(2) << __func__ << "(" << certificate.size() << " bytes)"; | 416 DVLOG(2) << __func__ << "(" << certificate.size() << " bytes)"; |
| 394 | 417 |
| 395 DCHECK(!certificate.empty()); | 418 DCHECK(!certificate.empty()); |
| 396 | 419 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 task_runner_->PostTask( | 817 task_runner_->PostTask( |
| 795 FROM_HERE, | 818 FROM_HERE, |
| 796 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); | 819 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); |
| 797 } | 820 } |
| 798 | 821 |
| 799 //------------------------------------------------------------------------------ | 822 //------------------------------------------------------------------------------ |
| 800 // The following are private methods. | 823 // The following are private methods. |
| 801 | 824 |
| 802 MediaDrmBridge::MediaDrmBridge( | 825 MediaDrmBridge::MediaDrmBridge( |
| 803 const std::vector<uint8_t>& scheme_uuid, | 826 const std::vector<uint8_t>& scheme_uuid, |
| 804 const GURL& security_origin, | |
| 805 SecurityLevel security_level, | 827 SecurityLevel security_level, |
| 828 std::unique_ptr<MediaDrmStorageBridge> storage, | |
| 806 const CreateFetcherCB& create_fetcher_cb, | 829 const CreateFetcherCB& create_fetcher_cb, |
| 807 const CreateStorageCB& create_storage_cb, | |
| 808 const SessionMessageCB& session_message_cb, | 830 const SessionMessageCB& session_message_cb, |
| 809 const SessionClosedCB& session_closed_cb, | 831 const SessionClosedCB& session_closed_cb, |
| 810 const SessionKeysChangeCB& session_keys_change_cb, | 832 const SessionKeysChangeCB& session_keys_change_cb, |
| 811 const SessionExpirationUpdateCB& session_expiration_update_cb) | 833 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 812 : scheme_uuid_(scheme_uuid), | 834 : scheme_uuid_(scheme_uuid), |
| 813 storage_(url::Origin(security_origin), create_storage_cb), | 835 storage_(std::move(storage)), |
| 814 create_fetcher_cb_(create_fetcher_cb), | 836 create_fetcher_cb_(create_fetcher_cb), |
| 815 session_message_cb_(session_message_cb), | 837 session_message_cb_(session_message_cb), |
| 816 session_closed_cb_(session_closed_cb), | 838 session_closed_cb_(session_closed_cb), |
| 817 session_keys_change_cb_(session_keys_change_cb), | 839 session_keys_change_cb_(session_keys_change_cb), |
| 818 session_expiration_update_cb_(session_expiration_update_cb), | 840 session_expiration_update_cb_(session_expiration_update_cb), |
| 819 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 841 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 820 media_drm_bridge_cdm_context_(this), | 842 media_drm_bridge_cdm_context_(this), |
| 821 weak_factory_(this) { | 843 weak_factory_(this) { |
| 822 DVLOG(1) << __func__; | 844 DVLOG(1) << __func__; |
| 823 | 845 |
| 824 DCHECK(!create_fetcher_cb_.is_null()); | 846 DCHECK(storage_); |
| 847 DCHECK(create_fetcher_cb_); | |
| 825 | 848 |
| 826 JNIEnv* env = AttachCurrentThread(); | 849 JNIEnv* env = AttachCurrentThread(); |
| 827 CHECK(env); | 850 CHECK(env); |
| 828 | 851 |
| 829 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 852 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 830 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 853 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 831 | 854 |
| 832 std::string security_level_str = GetSecurityLevelString(security_level); | 855 std::string security_level_str = GetSecurityLevelString(security_level); |
| 833 ScopedJavaLocalRef<jstring> j_security_level = | 856 ScopedJavaLocalRef<jstring> j_security_level = |
| 834 ConvertUTF8ToJavaString(env, security_level_str); | 857 ConvertUTF8ToJavaString(env, security_level_str); |
| 835 | 858 |
| 836 bool use_origin_isolated_storage = | 859 bool use_origin_isolated_storage = |
| 837 // TODO(yucliu): Remove the check once persistent storage is fully | 860 // TODO(yucliu): Remove the check once persistent storage is fully |
| 838 // supported and check if origin is valid. | 861 // supported and check if origin is valid. |
| 839 base::FeatureList::IsEnabled(kMediaDrmPersistentLicense) && | 862 base::FeatureList::IsEnabled(kMediaDrmPersistentLicense) && |
| 840 // MediaDrm implements origin isolated storage on M. | 863 // MediaDrm implements origin isolated storage on M. |
| 841 base::android::BuildInfo::GetInstance()->sdk_int() >= 23; | 864 base::android::BuildInfo::GetInstance()->sdk_int() >= 23 && |
| 865 !storage_->origin_id().empty(); | |
|
xhwang
2017/07/21 18:18:26
Add a comment about when the origin_id could be em
yucliu1
2017/07/21 20:24:09
Done.
| |
| 842 | 866 |
| 843 // TODO(yucliu): Per EME spec on individualization, implementation should not | 867 // TODO(yucliu): Per EME spec on individualization, implementation should not |
| 844 // expose application-specific information. Considering encode origin before | 868 // expose application-specific information. Considering encode origin before |
| 845 // passing to MediaDrm. | 869 // passing to MediaDrm. |
| 846 ScopedJavaLocalRef<jstring> j_security_origin = ConvertUTF8ToJavaString( | 870 ScopedJavaLocalRef<jstring> j_security_origin = ConvertUTF8ToJavaString( |
| 847 env, use_origin_isolated_storage ? security_origin.spec() : ""); | 871 env, use_origin_isolated_storage ? storage_->origin_id() : ""); |
| 848 | 872 |
| 849 // TODO(yucliu): Use |create_storage_cb_| to create MediaDrmStorage which can | 873 // TODO(yucliu): Use |create_storage_cb_| to create MediaDrmStorage which can |
| 850 // be used by Java side to store/retrieve persistent data. This should only | 874 // be used by Java side to store/retrieve persistent data. This should only |
| 851 // be used when |use_origin_isolated_storage| is true. | 875 // be used when |use_origin_isolated_storage| is true. |
| 852 | 876 |
| 853 // Note: OnMediaCryptoReady() could be called in this call. | 877 // Note: OnMediaCryptoReady() could be called in this call. |
| 854 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 878 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 855 env, j_scheme_uuid, j_security_origin, j_security_level, | 879 env, j_scheme_uuid, j_security_origin, j_security_level, |
| 856 reinterpret_cast<intptr_t>(this), reinterpret_cast<intptr_t>(&storage_))); | 880 reinterpret_cast<intptr_t>(this), |
| 881 reinterpret_cast<intptr_t>(storage_.get()))); | |
| 857 } | 882 } |
| 858 | 883 |
| 859 MediaDrmBridge::~MediaDrmBridge() { | 884 MediaDrmBridge::~MediaDrmBridge() { |
| 860 DCHECK(task_runner_->BelongsToCurrentThread()); | 885 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 861 DVLOG(1) << __func__; | 886 DVLOG(1) << __func__; |
| 862 | 887 |
| 863 JNIEnv* env = AttachCurrentThread(); | 888 JNIEnv* env = AttachCurrentThread(); |
| 864 | 889 |
| 865 // After the call to Java_MediaDrmBridge_destroy() Java won't call native | 890 // After the call to Java_MediaDrmBridge_destroy() Java won't call native |
| 866 // methods anymore, this is ensured by MediaDrmBridge.java. | 891 // methods anymore, this is ensured by MediaDrmBridge.java. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 } | 964 } |
| 940 | 965 |
| 941 void MediaDrmBridge::OnHasAdditionalUsableKey() { | 966 void MediaDrmBridge::OnHasAdditionalUsableKey() { |
| 942 DCHECK(task_runner_->BelongsToCurrentThread()); | 967 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 943 DVLOG(1) << __func__; | 968 DVLOG(1) << __func__; |
| 944 | 969 |
| 945 player_tracker_.NotifyNewKey(); | 970 player_tracker_.NotifyNewKey(); |
| 946 } | 971 } |
| 947 | 972 |
| 948 } // namespace media | 973 } // namespace media |
| OLD | NEW |