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/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/command_line.h" | |
| 13 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 14 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 15 #include "base/location.h" | 17 #include "base/location.h" |
| 16 #include "base/logging.h" | 18 #include "base/logging.h" |
| 17 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 18 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 21 #include "base/sys_byteorder.h" | 23 #include "base/sys_byteorder.h" |
| 22 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
| 23 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
| 24 #include "jni/MediaDrmBridge_jni.h" | 26 #include "jni/MediaDrmBridge_jni.h" |
| 25 #include "media/base/android/media_client_android.h" | 27 #include "media/base/android/media_client_android.h" |
| 28 #include "media/base/android/media_codec_player.h" // for GetMediaTaskRunner() | |
| 26 #include "media/base/android/media_drm_bridge_delegate.h" | 29 #include "media/base/android/media_drm_bridge_delegate.h" |
| 27 #include "media/base/cdm_key_information.h" | 30 #include "media/base/cdm_key_information.h" |
| 31 #include "media/base/media_switches.h" | |
| 28 | 32 |
| 29 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 33 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 30 | 34 |
| 35 #define RUN_CB_ON_MEDIA_THREAD(cb, ...) \ | |
| 36 do { \ | |
| 37 if (use_media_thread_ && \ | |
| 38 !GetMediaTaskRunner()->BelongsToCurrentThread()) { \ | |
| 39 GetMediaTaskRunner()->PostTask(FROM_HERE, \ | |
| 40 base::Bind(cb, ##__VA_ARGS__)); \ | |
| 41 } else { \ | |
| 42 cb.Run(__VA_ARGS__); \ | |
| 43 } \ | |
| 44 } while (0) | |
| 45 | |
| 31 using base::android::AttachCurrentThread; | 46 using base::android::AttachCurrentThread; |
| 32 using base::android::ConvertUTF8ToJavaString; | 47 using base::android::ConvertUTF8ToJavaString; |
| 33 using base::android::ConvertJavaStringToUTF8; | 48 using base::android::ConvertJavaStringToUTF8; |
| 34 using base::android::JavaByteArrayToByteVector; | 49 using base::android::JavaByteArrayToByteVector; |
| 35 using base::android::ScopedJavaLocalRef; | 50 using base::android::ScopedJavaLocalRef; |
| 51 using base::android::ScopedJavaGlobalRef; | |
|
xhwang
2015/09/29 17:28:23
nit: order
Tima Vaisburd
2015/09/29 19:55:44
Done.
| |
| 36 | 52 |
| 37 namespace media { | 53 namespace media { |
| 38 | 54 |
| 39 namespace { | 55 namespace { |
| 40 | 56 |
| 41 // These must be in sync with Android MediaDrm REQUEST_TYPE_XXX constants! | 57 // These must be in sync with Android MediaDrm REQUEST_TYPE_XXX constants! |
| 42 // https://developer.android.com/reference/android/media/MediaDrm.KeyRequest.htm l | 58 // https://developer.android.com/reference/android/media/MediaDrm.KeyRequest.htm l |
| 43 enum class RequestType { | 59 enum class RequestType { |
| 44 REQUEST_TYPE_INITIAL = 0, | 60 REQUEST_TYPE_INITIAL = 0, |
| 45 REQUEST_TYPE_RENEWAL = 1, | 61 REQUEST_TYPE_RENEWAL = 1, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 } | 263 } |
| 248 | 264 |
| 249 // static | 265 // static |
| 250 bool MediaDrmBridge::IsKeySystemSupportedWithType( | 266 bool MediaDrmBridge::IsKeySystemSupportedWithType( |
| 251 const std::string& key_system, | 267 const std::string& key_system, |
| 252 const std::string& container_mime_type) { | 268 const std::string& container_mime_type) { |
| 253 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 269 DCHECK(!key_system.empty() && !container_mime_type.empty()); |
| 254 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); | 270 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); |
| 255 } | 271 } |
| 256 | 272 |
| 273 // static | |
| 257 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { | 274 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { |
| 258 return RegisterNativesImpl(env); | 275 return RegisterNativesImpl(env); |
| 259 } | 276 } |
| 260 | 277 |
| 261 MediaDrmBridge::MediaDrmBridge( | 278 MediaDrmBridge::MediaDrmBridge( |
| 262 const std::vector<uint8>& scheme_uuid, | 279 const std::vector<uint8>& scheme_uuid, |
| 263 const SessionMessageCB& session_message_cb, | 280 const SessionMessageCB& session_message_cb, |
| 264 const SessionClosedCB& session_closed_cb, | 281 const SessionClosedCB& session_closed_cb, |
| 265 const LegacySessionErrorCB& legacy_session_error_cb, | 282 const LegacySessionErrorCB& legacy_session_error_cb, |
| 266 const SessionKeysChangeCB& session_keys_change_cb, | 283 const SessionKeysChangeCB& session_keys_change_cb, |
| 267 const SessionExpirationUpdateCB& session_expiration_update_cb) | 284 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 268 : scheme_uuid_(scheme_uuid), | 285 : scheme_uuid_(scheme_uuid), |
| 269 session_message_cb_(session_message_cb), | 286 session_message_cb_(session_message_cb), |
| 270 session_closed_cb_(session_closed_cb), | 287 session_closed_cb_(session_closed_cb), |
| 271 legacy_session_error_cb_(legacy_session_error_cb), | 288 legacy_session_error_cb_(legacy_session_error_cb), |
| 272 session_keys_change_cb_(session_keys_change_cb), | 289 session_keys_change_cb_(session_keys_change_cb), |
| 273 session_expiration_update_cb_(session_expiration_update_cb) { | 290 session_expiration_update_cb_(session_expiration_update_cb), |
| 291 ui_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
| 292 use_media_thread_(false), | |
| 293 weak_factory_(this) { | |
| 294 DVLOG(1) << "MediaDrmBridge::MediaDrmBridge"; | |
| 295 | |
| 296 use_media_thread_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 297 switches::kEnableMediaThreadForMediaPlayback); | |
| 298 | |
| 299 base::WeakPtr<MediaDrmBridge> weak_this = weak_factory_.GetWeakPtr(); | |
| 300 | |
| 301 internal_keys_added_cb_ = | |
| 302 base::Bind(&MediaDrmBridge::InternalKeysAdded, weak_this); | |
| 303 | |
| 274 JNIEnv* env = AttachCurrentThread(); | 304 JNIEnv* env = AttachCurrentThread(); |
| 275 CHECK(env); | 305 CHECK(env); |
| 276 | 306 |
| 277 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 307 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 278 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 308 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 279 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 309 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 280 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 310 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
| 281 } | 311 } |
| 282 | 312 |
| 283 MediaDrmBridge::~MediaDrmBridge() { | 313 void MediaDrmBridge::DeleteOnCorrectThread() { |
| 314 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; | |
| 315 | |
| 284 JNIEnv* env = AttachCurrentThread(); | 316 JNIEnv* env = AttachCurrentThread(); |
| 285 player_tracker_.NotifyCdmUnset(); | |
| 286 if (!j_media_drm_.is_null()) | 317 if (!j_media_drm_.is_null()) |
| 287 Java_MediaDrmBridge_destroy(env, j_media_drm_.obj()); | 318 Java_MediaDrmBridge_destroy(env, j_media_drm_.obj()); |
| 319 | |
| 320 // Post deletion onto Media thread if we use it. | |
| 321 if (use_media_thread_) | |
| 322 GetMediaTaskRunner()->DeleteSoon(FROM_HERE, this); | |
| 323 else | |
| 324 delete this; | |
| 325 } | |
| 326 | |
| 327 MediaDrmBridge::~MediaDrmBridge() { | |
| 328 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; | |
|
xhwang
2015/09/29 17:28:23
nit: in media code (and the rest of this file) we
Tima Vaisburd
2015/09/29 19:55:43
Class name removed.
| |
| 329 | |
| 330 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); | |
| 331 | |
| 332 player_tracker_.NotifyCdmUnset(); | |
| 288 } | 333 } |
| 289 | 334 |
| 290 // static | 335 // static |
| 291 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( | 336 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> MediaDrmBridge::Create( |
| 292 const std::string& key_system, | 337 const std::string& key_system, |
| 293 const SessionMessageCB& session_message_cb, | 338 const SessionMessageCB& session_message_cb, |
| 294 const SessionClosedCB& session_closed_cb, | 339 const SessionClosedCB& session_closed_cb, |
| 295 const LegacySessionErrorCB& legacy_session_error_cb, | 340 const LegacySessionErrorCB& legacy_session_error_cb, |
| 296 const SessionKeysChangeCB& session_keys_change_cb, | 341 const SessionKeysChangeCB& session_keys_change_cb, |
| 297 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 342 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 298 scoped_ptr<MediaDrmBridge> media_drm_bridge; | 343 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge; |
| 299 if (!IsAvailable()) | 344 if (!IsAvailable()) |
| 300 return media_drm_bridge.Pass(); | 345 return media_drm_bridge.Pass(); |
| 301 | 346 |
| 302 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 347 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); |
| 303 if (scheme_uuid.empty()) | 348 if (scheme_uuid.empty()) |
| 304 return media_drm_bridge.Pass(); | 349 return media_drm_bridge.Pass(); |
| 305 | 350 |
| 306 media_drm_bridge.reset( | 351 media_drm_bridge.reset( |
| 307 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, | 352 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, |
| 308 legacy_session_error_cb, session_keys_change_cb, | 353 legacy_session_error_cb, session_keys_change_cb, |
| 309 session_expiration_update_cb)); | 354 session_expiration_update_cb)); |
| 310 | 355 |
| 311 if (media_drm_bridge->j_media_drm_.is_null()) | 356 if (media_drm_bridge->j_media_drm_.is_null()) |
| 312 media_drm_bridge.reset(); | 357 media_drm_bridge.reset(); |
| 313 | 358 |
| 314 return media_drm_bridge.Pass(); | 359 return media_drm_bridge.Pass(); |
| 315 } | 360 } |
| 316 | 361 |
| 317 // static | 362 // static |
| 318 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 363 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> |
| 319 const std::string& key_system) { | 364 MediaDrmBridge::CreateWithoutSessionSupport(const std::string& key_system) { |
| 320 return MediaDrmBridge::Create( | 365 return MediaDrmBridge::Create( |
| 321 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), | 366 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), |
| 322 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 367 SessionKeysChangeCB(), SessionExpirationUpdateCB()); |
| 323 } | 368 } |
| 324 | 369 |
| 325 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { | 370 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { |
| 326 if (security_level != SECURITY_LEVEL_NONE && | 371 if (security_level != SECURITY_LEVEL_NONE && |
| 327 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { | 372 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { |
| 328 NOTREACHED() << "Widevine security level " << security_level | 373 NOTREACHED() << "Widevine security level " << security_level |
| 329 << "used with another key system"; | 374 << "used with another key system"; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 promise->reject(NOT_SUPPORTED_ERROR, 0, "RemoveSession() is not supported."); | 502 promise->reject(NOT_SUPPORTED_ERROR, 0, "RemoveSession() is not supported."); |
| 458 } | 503 } |
| 459 | 504 |
| 460 CdmContext* MediaDrmBridge::GetCdmContext() { | 505 CdmContext* MediaDrmBridge::GetCdmContext() { |
| 461 NOTREACHED(); | 506 NOTREACHED(); |
| 462 return nullptr; | 507 return nullptr; |
| 463 } | 508 } |
| 464 | 509 |
| 465 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, | 510 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, |
| 466 const base::Closure& cdm_unset_cb) { | 511 const base::Closure& cdm_unset_cb) { |
| 512 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); | |
| 467 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); | 513 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); |
| 468 } | 514 } |
| 469 | 515 |
| 470 void MediaDrmBridge::UnregisterPlayer(int registration_id) { | 516 void MediaDrmBridge::UnregisterPlayer(int registration_id) { |
| 517 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); | |
| 471 player_tracker_.UnregisterPlayer(registration_id); | 518 player_tracker_.UnregisterPlayer(registration_id); |
| 472 } | 519 } |
| 473 | 520 |
| 474 void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure& closure) { | 521 void MediaDrmBridge::SetMediaCryptoReadyCB(const MediaCryptoReadyCB& closure) { |
| 475 if (closure.is_null()) { | 522 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); |
| 476 media_crypto_ready_cb_.Reset(); | 523 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 524 | |
| 525 { | |
| 526 base::AutoLock lock(media_crypto_ready_lock_); | |
| 527 | |
| 528 if (closure.is_null()) { | |
| 529 media_crypto_ready_cb_.Reset(); | |
| 530 return; | |
| 531 } | |
| 532 | |
| 533 DCHECK(media_crypto_ready_cb_.is_null()); | |
| 534 | |
| 535 media_crypto_ready_cb_ = closure; | |
| 536 } | |
| 537 | |
| 538 ui_task_runner_->PostTask( | |
| 539 FROM_HERE, base::Bind(&MediaDrmBridge::CheckMediaCryptoAndInvokeCB, | |
| 540 base::Unretained(this))); | |
| 541 } | |
| 542 | |
| 543 void MediaDrmBridge::CheckMediaCryptoAndInvokeCB() { | |
| 544 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 545 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; | |
| 546 | |
| 547 ScopedJavaLocalRef<jobject> media_crypto = GetMediaCrypto(); | |
| 548 if (media_crypto.is_null()) { | |
| 549 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__ << ": no MediaCrypto"; | |
| 477 return; | 550 return; |
| 478 } | 551 } |
| 479 | 552 |
| 480 DCHECK(media_crypto_ready_cb_.is_null()); | 553 MediaCryptoReadyCB media_crypto_ready_cb; |
| 554 { | |
| 555 base::AutoLock lock(media_crypto_ready_lock_); | |
| 481 | 556 |
| 482 if (!GetMediaCrypto().is_null()) { | 557 if (media_crypto_ready_cb_.is_null()) { |
| 483 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 558 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__ << ": no callback"; |
| 484 return; | 559 return; |
| 560 } | |
| 561 | |
| 562 media_crypto_ready_cb = base::ResetAndReturn(&media_crypto_ready_cb_); | |
| 485 } | 563 } |
| 486 | 564 |
| 487 media_crypto_ready_cb_ = closure; | 565 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( |
| 566 new ScopedJavaGlobalRef<jobject>()); | |
| 567 j_object_ptr->Reset(AttachCurrentThread(), media_crypto.obj()); | |
| 568 | |
| 569 if (use_media_thread_) { | |
| 570 GetMediaTaskRunner()->PostTask( | |
| 571 FROM_HERE, | |
| 572 base::Bind(media_crypto_ready_cb, base::Passed(&j_object_ptr))); | |
| 573 } else { | |
| 574 media_crypto_ready_cb.Run(j_object_ptr.Pass()); | |
| 575 } | |
| 488 } | 576 } |
| 489 | 577 |
| 490 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { | 578 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm) { |
| 579 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 580 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; | |
| 581 | |
| 491 DCHECK(!GetMediaCrypto().is_null()); | 582 DCHECK(!GetMediaCrypto().is_null()); |
| 492 if (!media_crypto_ready_cb_.is_null()) | 583 |
| 493 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); | 584 CheckMediaCryptoAndInvokeCB(); |
| 494 } | 585 } |
| 495 | 586 |
| 496 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 587 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
| 497 jobject j_media_drm, | 588 jobject j_media_drm, |
| 498 jint j_promise_id) { | 589 jint j_promise_id) { |
| 499 cdm_promise_adapter_.ResolvePromise(j_promise_id); | 590 cdm_promise_adapter_.ResolvePromise(j_promise_id); |
| 500 } | 591 } |
| 501 | 592 |
| 502 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 593 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
| 503 jobject j_media_drm, | 594 jobject j_media_drm, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 jobject j_media_drm, | 628 jobject j_media_drm, |
| 538 jbyteArray j_session_id) { | 629 jbyteArray j_session_id) { |
| 539 session_closed_cb_.Run(GetSessionId(env, j_session_id)); | 630 session_closed_cb_.Run(GetSessionId(env, j_session_id)); |
| 540 } | 631 } |
| 541 | 632 |
| 542 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 633 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
| 543 jobject j_media_drm, | 634 jobject j_media_drm, |
| 544 jbyteArray j_session_id, | 635 jbyteArray j_session_id, |
| 545 jobjectArray j_keys_info, | 636 jobjectArray j_keys_info, |
| 546 bool has_additional_usable_key) { | 637 bool has_additional_usable_key) { |
| 547 if (has_additional_usable_key) | 638 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 548 player_tracker_.NotifyNewKey(); | |
| 549 | 639 |
| 550 CdmKeysInfo cdm_keys_info; | 640 CdmKeysInfo cdm_keys_info; |
| 551 | 641 |
| 552 size_t size = env->GetArrayLength(j_keys_info); | 642 size_t size = env->GetArrayLength(j_keys_info); |
| 553 DCHECK_GT(size, 0u); | 643 DCHECK_GT(size, 0u); |
| 554 | 644 |
| 555 for (size_t i = 0; i < size; ++i) { | 645 for (size_t i = 0; i < size; ++i) { |
| 556 ScopedJavaLocalRef<jobject> j_key_status( | 646 ScopedJavaLocalRef<jobject> j_key_status( |
| 557 env, env->GetObjectArrayElement(j_keys_info, i)); | 647 env, env->GetObjectArrayElement(j_keys_info, i)); |
| 558 | 648 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 572 << key_status; | 662 << key_status; |
| 573 | 663 |
| 574 // TODO(xhwang): Update CdmKeyInformation to take key_id and status in the | 664 // TODO(xhwang): Update CdmKeyInformation to take key_id and status in the |
| 575 // constructor. | 665 // constructor. |
| 576 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | 666 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); |
| 577 cdm_key_information->key_id = key_id; | 667 cdm_key_information->key_id = key_id; |
| 578 cdm_key_information->status = key_status; | 668 cdm_key_information->status = key_status; |
| 579 cdm_keys_info.push_back(cdm_key_information.release()); | 669 cdm_keys_info.push_back(cdm_key_information.release()); |
| 580 } | 670 } |
| 581 | 671 |
| 582 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), | 672 RUN_CB_ON_MEDIA_THREAD(internal_keys_added_cb_, has_additional_usable_key); |
| 583 has_additional_usable_key, cdm_keys_info.Pass()); | 673 |
| 674 std::string session_id = GetSessionId(env, j_session_id); | |
| 675 | |
| 676 session_keys_change_cb_.Run(session_id, has_additional_usable_key, | |
| 677 cdm_keys_info.Pass()); | |
| 678 } | |
| 679 | |
| 680 void MediaDrmBridge::InternalKeysAdded(bool has_additional_usable_key) { | |
| 681 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); | |
| 682 if (has_additional_usable_key) | |
| 683 player_tracker_.NotifyNewKey(); | |
| 584 } | 684 } |
| 585 | 685 |
| 586 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 686 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys |
| 587 // will never expire. This will be translated into a NULL base::Time() [2], | 687 // will never expire. This will be translated into a NULL base::Time() [2], |
| 588 // which will then be mapped to a zero Java time [3]. The zero Java time is | 688 // which will then be mapped to a zero Java time [3]. The zero Java time is |
| 589 // passed to Blink which will then be translated to NaN [4], which is what the | 689 // passed to Blink which will then be translated to NaN [4], which is what the |
| 590 // spec uses to indicate that the license will never expire [5]. | 690 // spec uses to indicate that the license will never expire [5]. |
| 591 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio nUpdateListener.html | 691 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio nUpdateListener.html |
| 592 // [2] See base::Time::FromDoubleT() | 692 // [2] See base::Time::FromDoubleT() |
| 593 // [3] See base::Time::ToJavaTime() | 693 // [3] See base::Time::ToJavaTime() |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 606 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 706 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
| 607 jobject j_media_drm, | 707 jobject j_media_drm, |
| 608 jbyteArray j_session_id, | 708 jbyteArray j_session_id, |
| 609 jstring j_error_message) { | 709 jstring j_error_message) { |
| 610 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 710 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
| 611 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), | 711 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), |
| 612 MediaKeys::UNKNOWN_ERROR, 0, error_message); | 712 MediaKeys::UNKNOWN_ERROR, 0, error_message); |
| 613 } | 713 } |
| 614 | 714 |
| 615 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { | 715 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { |
| 716 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 717 | |
| 616 JNIEnv* env = AttachCurrentThread(); | 718 JNIEnv* env = AttachCurrentThread(); |
| 617 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); | 719 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); |
| 618 } | 720 } |
| 619 | 721 |
| 620 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 722 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
| 621 JNIEnv* env = AttachCurrentThread(); | 723 JNIEnv* env = AttachCurrentThread(); |
| 622 ScopedJavaLocalRef<jstring> j_security_level = | 724 ScopedJavaLocalRef<jstring> j_security_level = |
| 623 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); | 725 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); |
| 624 std::string security_level_str = | 726 std::string security_level_str = |
| 625 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 727 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 642 JNIEnv* env = AttachCurrentThread(); | 744 JNIEnv* env = AttachCurrentThread(); |
| 643 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 745 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 644 } | 746 } |
| 645 | 747 |
| 646 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 748 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
| 647 JNIEnv* env, jobject, bool success) { | 749 JNIEnv* env, jobject, bool success) { |
| 648 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 750 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 649 } | 751 } |
| 650 | 752 |
| 651 } // namespace media | 753 } // namespace media |
| OLD | NEW |