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