| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 311 |
| 312 return GetKeySystemManager()->GetPlatformKeySystemNames(); | 312 return GetKeySystemManager()->GetPlatformKeySystemNames(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 // static | 315 // static |
| 316 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( | 316 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( |
| 317 const std::string& key_system, | 317 const std::string& key_system, |
| 318 const GURL& security_origin, | 318 const GURL& security_origin, |
| 319 SecurityLevel security_level, | 319 SecurityLevel security_level, |
| 320 const CreateFetcherCB& create_fetcher_cb, | 320 const CreateFetcherCB& create_fetcher_cb, |
| 321 const CreateStorageCB& create_storage_cb, |
| 321 const SessionMessageCB& session_message_cb, | 322 const SessionMessageCB& session_message_cb, |
| 322 const SessionClosedCB& session_closed_cb, | 323 const SessionClosedCB& session_closed_cb, |
| 323 const SessionKeysChangeCB& session_keys_change_cb, | 324 const SessionKeysChangeCB& session_keys_change_cb, |
| 324 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 325 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 325 // All paths requires the MediaDrmApis. | 326 // All paths requires the MediaDrmApis. |
| 326 DCHECK(AreMediaDrmApisAvailable()); | 327 DCHECK(AreMediaDrmApisAvailable()); |
| 327 | 328 |
| 328 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); | 329 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); |
| 329 if (scheme_uuid.empty()) | 330 if (scheme_uuid.empty()) |
| 330 return nullptr; | 331 return nullptr; |
| 331 | 332 |
| 332 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( | 333 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( |
| 333 scheme_uuid, security_origin, security_level, create_fetcher_cb, | 334 scheme_uuid, security_origin, security_level, create_fetcher_cb, |
| 334 session_message_cb, session_closed_cb, session_keys_change_cb, | 335 create_storage_cb, session_message_cb, session_closed_cb, |
| 335 session_expiration_update_cb)); | 336 session_keys_change_cb, session_expiration_update_cb)); |
| 336 | 337 |
| 337 if (media_drm_bridge->j_media_drm_.is_null()) | 338 if (media_drm_bridge->j_media_drm_.is_null()) |
| 338 media_drm_bridge = nullptr; | 339 media_drm_bridge = nullptr; |
| 339 | 340 |
| 340 return media_drm_bridge; | 341 return media_drm_bridge; |
| 341 } | 342 } |
| 342 | 343 |
| 343 // static | 344 // static |
| 344 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( | 345 scoped_refptr<MediaDrmBridge> MediaDrmBridge::Create( |
| 345 const std::string& key_system, | 346 const std::string& key_system, |
| 346 const GURL& security_origin, | 347 const GURL& security_origin, |
| 347 SecurityLevel security_level, | 348 SecurityLevel security_level, |
| 348 const CreateFetcherCB& create_fetcher_cb, | 349 const CreateFetcherCB& create_fetcher_cb, |
| 350 const CreateStorageCB& create_storage_cb, |
| 349 const SessionMessageCB& session_message_cb, | 351 const SessionMessageCB& session_message_cb, |
| 350 const SessionClosedCB& session_closed_cb, | 352 const SessionClosedCB& session_closed_cb, |
| 351 const SessionKeysChangeCB& session_keys_change_cb, | 353 const SessionKeysChangeCB& session_keys_change_cb, |
| 352 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 354 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 353 DVLOG(1) << __func__; | 355 DVLOG(1) << __func__; |
| 354 | 356 |
| 355 if (!IsAvailable()) | 357 if (!IsAvailable()) |
| 356 return nullptr; | 358 return nullptr; |
| 357 | 359 |
| 358 return CreateInternal(key_system, security_origin, security_level, | 360 return CreateInternal(key_system, security_origin, security_level, |
| 359 create_fetcher_cb, session_message_cb, | 361 create_fetcher_cb, create_storage_cb, |
| 360 session_closed_cb, session_keys_change_cb, | 362 session_message_cb, session_closed_cb, |
| 361 session_expiration_update_cb); | 363 session_keys_change_cb, session_expiration_update_cb); |
| 362 } | 364 } |
| 363 | 365 |
| 364 // static | 366 // static |
| 365 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 367 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( |
| 366 const std::string& key_system, | 368 const std::string& key_system, |
| 367 SecurityLevel security_level, | 369 SecurityLevel security_level, |
| 368 const CreateFetcherCB& create_fetcher_cb) { | 370 const CreateFetcherCB& create_fetcher_cb) { |
| 369 DVLOG(1) << __func__; | 371 DVLOG(1) << __func__; |
| 370 | 372 |
| 371 // Sessions won't be used so decoding capability is not required. | 373 // Sessions won't be used so decoding capability is not required. |
| 372 if (!AreMediaDrmApisAvailable()) | 374 if (!AreMediaDrmApisAvailable()) |
| 373 return nullptr; | 375 return nullptr; |
| 374 | 376 |
| 375 return MediaDrmBridge::Create(key_system, GURL::EmptyGURL(), security_level, | 377 return MediaDrmBridge::Create( |
| 376 create_fetcher_cb, SessionMessageCB(), | 378 key_system, GURL::EmptyGURL(), security_level, create_fetcher_cb, |
| 377 SessionClosedCB(), SessionKeysChangeCB(), | 379 CreateStorageCB(), SessionMessageCB(), SessionClosedCB(), |
| 378 SessionExpirationUpdateCB()); | 380 SessionKeysChangeCB(), SessionExpirationUpdateCB()); |
| 379 } | 381 } |
| 380 | 382 |
| 381 void MediaDrmBridge::SetServerCertificate( | 383 void MediaDrmBridge::SetServerCertificate( |
| 382 const std::vector<uint8_t>& certificate, | 384 const std::vector<uint8_t>& certificate, |
| 383 std::unique_ptr<media::SimpleCdmPromise> promise) { | 385 std::unique_ptr<media::SimpleCdmPromise> promise) { |
| 384 DCHECK(task_runner_->BelongsToCurrentThread()); | 386 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 385 DVLOG(2) << __func__ << "(" << certificate.size() << " bytes)"; | 387 DVLOG(2) << __func__ << "(" << certificate.size() << " bytes)"; |
| 386 | 388 |
| 387 DCHECK(!certificate.empty()); | 389 DCHECK(!certificate.empty()); |
| 388 | 390 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 774 } |
| 773 | 775 |
| 774 //------------------------------------------------------------------------------ | 776 //------------------------------------------------------------------------------ |
| 775 // The following are private methods. | 777 // The following are private methods. |
| 776 | 778 |
| 777 MediaDrmBridge::MediaDrmBridge( | 779 MediaDrmBridge::MediaDrmBridge( |
| 778 const std::vector<uint8_t>& scheme_uuid, | 780 const std::vector<uint8_t>& scheme_uuid, |
| 779 const GURL& security_origin, | 781 const GURL& security_origin, |
| 780 SecurityLevel security_level, | 782 SecurityLevel security_level, |
| 781 const CreateFetcherCB& create_fetcher_cb, | 783 const CreateFetcherCB& create_fetcher_cb, |
| 784 const CreateStorageCB& create_storage_cb, |
| 782 const SessionMessageCB& session_message_cb, | 785 const SessionMessageCB& session_message_cb, |
| 783 const SessionClosedCB& session_closed_cb, | 786 const SessionClosedCB& session_closed_cb, |
| 784 const SessionKeysChangeCB& session_keys_change_cb, | 787 const SessionKeysChangeCB& session_keys_change_cb, |
| 785 const SessionExpirationUpdateCB& session_expiration_update_cb) | 788 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 786 : scheme_uuid_(scheme_uuid), | 789 : scheme_uuid_(scheme_uuid), |
| 787 create_fetcher_cb_(create_fetcher_cb), | 790 create_fetcher_cb_(create_fetcher_cb), |
| 791 create_storage_cb_(create_storage_cb), |
| 788 session_message_cb_(session_message_cb), | 792 session_message_cb_(session_message_cb), |
| 789 session_closed_cb_(session_closed_cb), | 793 session_closed_cb_(session_closed_cb), |
| 790 session_keys_change_cb_(session_keys_change_cb), | 794 session_keys_change_cb_(session_keys_change_cb), |
| 791 session_expiration_update_cb_(session_expiration_update_cb), | 795 session_expiration_update_cb_(session_expiration_update_cb), |
| 792 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 796 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 793 media_drm_bridge_cdm_context_(this), | 797 media_drm_bridge_cdm_context_(this), |
| 794 weak_factory_(this) { | 798 weak_factory_(this) { |
| 795 DVLOG(1) << __func__; | 799 DVLOG(1) << __func__; |
| 796 | 800 |
| 797 DCHECK(!create_fetcher_cb_.is_null()); | 801 DCHECK(!create_fetcher_cb_.is_null()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 812 base::FeatureList::IsEnabled(kMediaDrmPersistentLicense) && | 816 base::FeatureList::IsEnabled(kMediaDrmPersistentLicense) && |
| 813 // MediaDrm implements origin isolated storage on M. | 817 // MediaDrm implements origin isolated storage on M. |
| 814 base::android::BuildInfo::GetInstance()->sdk_int() >= 23; | 818 base::android::BuildInfo::GetInstance()->sdk_int() >= 23; |
| 815 | 819 |
| 816 // TODO(yucliu): Per EME spec on individualization, implementation should not | 820 // TODO(yucliu): Per EME spec on individualization, implementation should not |
| 817 // expose application-specific information. Considering encode origin before | 821 // expose application-specific information. Considering encode origin before |
| 818 // passing to MediaDrm. | 822 // passing to MediaDrm. |
| 819 ScopedJavaLocalRef<jstring> j_security_origin = ConvertUTF8ToJavaString( | 823 ScopedJavaLocalRef<jstring> j_security_origin = ConvertUTF8ToJavaString( |
| 820 env, use_origin_isolated_storage ? security_origin.spec() : ""); | 824 env, use_origin_isolated_storage ? security_origin.spec() : ""); |
| 821 | 825 |
| 826 // TODO(yucliu): Use |create_storage_cb_| to create MediaDrmStorage which can |
| 827 // be used by Java side to store/retrieve persistent data. This should only |
| 828 // be used when |use_origin_isolated_storage| is true. |
| 829 |
| 822 // Note: OnMediaCryptoReady() could be called in this call. | 830 // Note: OnMediaCryptoReady() could be called in this call. |
| 823 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 831 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 824 env, j_scheme_uuid, j_security_origin, j_security_level, | 832 env, j_scheme_uuid, j_security_origin, j_security_level, |
| 825 reinterpret_cast<intptr_t>(this), reinterpret_cast<intptr_t>(&storage_))); | 833 reinterpret_cast<intptr_t>(this), reinterpret_cast<intptr_t>(&storage_))); |
| 826 } | 834 } |
| 827 | 835 |
| 828 MediaDrmBridge::~MediaDrmBridge() { | 836 MediaDrmBridge::~MediaDrmBridge() { |
| 829 DCHECK(task_runner_->BelongsToCurrentThread()); | 837 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 830 DVLOG(1) << __func__; | 838 DVLOG(1) << __func__; |
| 831 | 839 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 } | 924 } |
| 917 | 925 |
| 918 void MediaDrmBridge::OnHasAdditionalUsableKey() { | 926 void MediaDrmBridge::OnHasAdditionalUsableKey() { |
| 919 DCHECK(task_runner_->BelongsToCurrentThread()); | 927 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 920 DVLOG(1) << __func__; | 928 DVLOG(1) << __func__; |
| 921 | 929 |
| 922 player_tracker_.NotifyNewKey(); | 930 player_tracker_.NotifyNewKey(); |
| 923 } | 931 } |
| 924 | 932 |
| 925 } // namespace media | 933 } // namespace media |
| OLD | NEW |