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" |
13 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/sys_byteorder.h" | 22 #include "base/sys_byteorder.h" |
22 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
23 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
24 #include "jni/MediaDrmBridge_jni.h" | 25 #include "jni/MediaDrmBridge_jni.h" |
25 #include "media/base/android/media_client_android.h" | 26 #include "media/base/android/media_client_android.h" |
26 #include "media/base/android/media_drm_bridge_delegate.h" | 27 #include "media/base/android/media_drm_bridge_delegate.h" |
| 28 #include "media/base/android/media_task_runner.h" |
27 #include "media/base/cdm_key_information.h" | 29 #include "media/base/cdm_key_information.h" |
28 | 30 |
29 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 31 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
30 | 32 |
31 using base::android::AttachCurrentThread; | 33 using base::android::AttachCurrentThread; |
32 using base::android::ConvertUTF8ToJavaString; | 34 using base::android::ConvertUTF8ToJavaString; |
33 using base::android::ConvertJavaStringToUTF8; | 35 using base::android::ConvertJavaStringToUTF8; |
34 using base::android::JavaByteArrayToByteVector; | 36 using base::android::JavaByteArrayToByteVector; |
| 37 using base::android::ScopedJavaGlobalRef; |
35 using base::android::ScopedJavaLocalRef; | 38 using base::android::ScopedJavaLocalRef; |
36 | 39 |
37 namespace media { | 40 namespace media { |
38 | 41 |
39 namespace { | 42 namespace { |
40 | 43 |
41 // These must be in sync with Android MediaDrm REQUEST_TYPE_XXX constants! | 44 // These must be in sync with Android MediaDrm REQUEST_TYPE_XXX constants! |
42 // https://developer.android.com/reference/android/media/MediaDrm.KeyRequest.htm
l | 45 // https://developer.android.com/reference/android/media/MediaDrm.KeyRequest.htm
l |
43 enum class RequestType { | 46 enum class RequestType { |
44 REQUEST_TYPE_INITIAL = 0, | 47 REQUEST_TYPE_INITIAL = 0, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 250 } |
248 | 251 |
249 // static | 252 // static |
250 bool MediaDrmBridge::IsKeySystemSupportedWithType( | 253 bool MediaDrmBridge::IsKeySystemSupportedWithType( |
251 const std::string& key_system, | 254 const std::string& key_system, |
252 const std::string& container_mime_type) { | 255 const std::string& container_mime_type) { |
253 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 256 DCHECK(!key_system.empty() && !container_mime_type.empty()); |
254 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); | 257 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); |
255 } | 258 } |
256 | 259 |
| 260 // static |
257 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { | 261 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { |
258 return RegisterNativesImpl(env); | 262 return RegisterNativesImpl(env); |
259 } | 263 } |
260 | 264 |
261 MediaDrmBridge::MediaDrmBridge( | 265 MediaDrmBridge::MediaDrmBridge( |
262 const std::vector<uint8>& scheme_uuid, | 266 const std::vector<uint8>& scheme_uuid, |
263 const SessionMessageCB& session_message_cb, | 267 const SessionMessageCB& session_message_cb, |
264 const SessionClosedCB& session_closed_cb, | 268 const SessionClosedCB& session_closed_cb, |
265 const LegacySessionErrorCB& legacy_session_error_cb, | 269 const LegacySessionErrorCB& legacy_session_error_cb, |
266 const SessionKeysChangeCB& session_keys_change_cb, | 270 const SessionKeysChangeCB& session_keys_change_cb, |
267 const SessionExpirationUpdateCB& session_expiration_update_cb) | 271 const SessionExpirationUpdateCB& session_expiration_update_cb) |
268 : scheme_uuid_(scheme_uuid), | 272 : scheme_uuid_(scheme_uuid), |
269 session_message_cb_(session_message_cb), | 273 session_message_cb_(session_message_cb), |
270 session_closed_cb_(session_closed_cb), | 274 session_closed_cb_(session_closed_cb), |
271 legacy_session_error_cb_(legacy_session_error_cb), | 275 legacy_session_error_cb_(legacy_session_error_cb), |
272 session_keys_change_cb_(session_keys_change_cb), | 276 session_keys_change_cb_(session_keys_change_cb), |
273 session_expiration_update_cb_(session_expiration_update_cb) { | 277 session_expiration_update_cb_(session_expiration_update_cb), |
| 278 ui_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 279 use_media_thread_(UseMediaThreadForMediaPlayback()), |
| 280 media_weak_factory_(this), |
| 281 ui_weak_factory_(this) { |
| 282 DVLOG(1) << __FUNCTION__; |
| 283 |
274 JNIEnv* env = AttachCurrentThread(); | 284 JNIEnv* env = AttachCurrentThread(); |
275 CHECK(env); | 285 CHECK(env); |
276 | 286 |
277 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 287 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
278 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 288 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
279 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 289 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
280 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 290 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
281 } | 291 } |
282 | 292 |
283 MediaDrmBridge::~MediaDrmBridge() { | 293 void MediaDrmBridge::DeleteOnCorrectThread() { |
| 294 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 295 DVLOG(1) << __FUNCTION__; |
| 296 |
284 JNIEnv* env = AttachCurrentThread(); | 297 JNIEnv* env = AttachCurrentThread(); |
285 player_tracker_.NotifyCdmUnset(); | |
286 if (!j_media_drm_.is_null()) | 298 if (!j_media_drm_.is_null()) |
287 Java_MediaDrmBridge_destroy(env, j_media_drm_.obj()); | 299 Java_MediaDrmBridge_destroy(env, j_media_drm_.obj()); |
| 300 |
| 301 // After the call to Java_MediaDrmBridge_destroy() Java won't call native |
| 302 // methods anymore, this is ensured by MediaDrmBridge.java. |
| 303 |
| 304 // Post deletion onto Media thread if we use it. |
| 305 if (use_media_thread_) { |
| 306 ui_weak_factory_.InvalidateWeakPtrs(); |
| 307 GetMediaTaskRunner()->DeleteSoon(FROM_HERE, this); |
| 308 } else { |
| 309 delete this; |
| 310 } |
| 311 } |
| 312 |
| 313 MediaDrmBridge::~MediaDrmBridge() { |
| 314 DVLOG(1) << __FUNCTION__; |
| 315 |
| 316 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); |
| 317 |
| 318 player_tracker_.NotifyCdmUnset(); |
288 } | 319 } |
289 | 320 |
290 // static | 321 // static |
291 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( | 322 ScopedMediaDrmBridgePtr MediaDrmBridge::Create( |
292 const std::string& key_system, | 323 const std::string& key_system, |
293 const SessionMessageCB& session_message_cb, | 324 const SessionMessageCB& session_message_cb, |
294 const SessionClosedCB& session_closed_cb, | 325 const SessionClosedCB& session_closed_cb, |
295 const LegacySessionErrorCB& legacy_session_error_cb, | 326 const LegacySessionErrorCB& legacy_session_error_cb, |
296 const SessionKeysChangeCB& session_keys_change_cb, | 327 const SessionKeysChangeCB& session_keys_change_cb, |
297 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 328 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
298 scoped_ptr<MediaDrmBridge> media_drm_bridge; | 329 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge; |
299 if (!IsAvailable()) | 330 if (!IsAvailable()) |
300 return media_drm_bridge.Pass(); | 331 return media_drm_bridge.Pass(); |
301 | 332 |
302 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 333 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); |
303 if (scheme_uuid.empty()) | 334 if (scheme_uuid.empty()) |
304 return media_drm_bridge.Pass(); | 335 return media_drm_bridge.Pass(); |
305 | 336 |
306 media_drm_bridge.reset( | 337 media_drm_bridge.reset( |
307 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, | 338 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, |
308 legacy_session_error_cb, session_keys_change_cb, | 339 legacy_session_error_cb, session_keys_change_cb, |
309 session_expiration_update_cb)); | 340 session_expiration_update_cb)); |
310 | 341 |
311 if (media_drm_bridge->j_media_drm_.is_null()) | 342 if (media_drm_bridge->j_media_drm_.is_null()) |
312 media_drm_bridge.reset(); | 343 media_drm_bridge.reset(); |
313 | 344 |
314 return media_drm_bridge.Pass(); | 345 return media_drm_bridge.Pass(); |
315 } | 346 } |
316 | 347 |
317 // static | 348 // static |
318 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 349 ScopedMediaDrmBridgePtr |
319 const std::string& key_system) { | 350 MediaDrmBridge::CreateWithoutSessionSupport(const std::string& key_system) { |
320 return MediaDrmBridge::Create( | 351 return MediaDrmBridge::Create( |
321 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), | 352 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), |
322 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 353 SessionKeysChangeCB(), SessionExpirationUpdateCB()); |
323 } | 354 } |
324 | 355 |
325 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { | 356 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { |
326 if (security_level != SECURITY_LEVEL_NONE && | 357 if (security_level != SECURITY_LEVEL_NONE && |
327 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { | 358 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { |
328 NOTREACHED() << "Widevine security level " << security_level | 359 NOTREACHED() << "Widevine security level " << security_level |
329 << "used with another key system"; | 360 << "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."); | 488 promise->reject(NOT_SUPPORTED_ERROR, 0, "RemoveSession() is not supported."); |
458 } | 489 } |
459 | 490 |
460 CdmContext* MediaDrmBridge::GetCdmContext() { | 491 CdmContext* MediaDrmBridge::GetCdmContext() { |
461 NOTREACHED(); | 492 NOTREACHED(); |
462 return nullptr; | 493 return nullptr; |
463 } | 494 } |
464 | 495 |
465 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, | 496 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, |
466 const base::Closure& cdm_unset_cb) { | 497 const base::Closure& cdm_unset_cb) { |
| 498 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); |
467 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); | 499 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); |
468 } | 500 } |
469 | 501 |
470 void MediaDrmBridge::UnregisterPlayer(int registration_id) { | 502 void MediaDrmBridge::UnregisterPlayer(int registration_id) { |
| 503 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); |
471 player_tracker_.UnregisterPlayer(registration_id); | 504 player_tracker_.UnregisterPlayer(registration_id); |
472 } | 505 } |
473 | 506 |
474 void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure& closure) { | 507 void MediaDrmBridge::SetMediaCryptoReadyCB( |
475 if (closure.is_null()) { | 508 const MediaCryptoReadyCB& media_crypto_ready_cb) { |
| 509 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 510 DVLOG(1) << __FUNCTION__; |
| 511 |
| 512 if (media_crypto_ready_cb.is_null()) { |
476 media_crypto_ready_cb_.Reset(); | 513 media_crypto_ready_cb_.Reset(); |
477 return; | 514 return; |
478 } | 515 } |
479 | 516 |
480 DCHECK(media_crypto_ready_cb_.is_null()); | 517 DCHECK(media_crypto_ready_cb_.is_null()); |
481 | 518 |
| 519 // |media_crypto_ready_cb| is already bound to the correct thread |
| 520 // (either UI or Media). |
482 if (!GetMediaCrypto().is_null()) { | 521 if (!GetMediaCrypto().is_null()) { |
483 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 522 NotifyMediaCryptoReady(media_crypto_ready_cb); |
484 return; | 523 return; |
485 } | 524 } |
486 | 525 |
487 media_crypto_ready_cb_ = closure; | 526 media_crypto_ready_cb_ = media_crypto_ready_cb; |
488 } | 527 } |
489 | 528 |
490 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { | 529 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm) { |
| 530 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 531 DVLOG(1) << __FUNCTION__; |
| 532 |
491 DCHECK(!GetMediaCrypto().is_null()); | 533 DCHECK(!GetMediaCrypto().is_null()); |
492 if (!media_crypto_ready_cb_.is_null()) | 534 |
493 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); | 535 if (media_crypto_ready_cb_.is_null()) |
| 536 return; |
| 537 |
| 538 NotifyMediaCryptoReady(base::ResetAndReturn(&media_crypto_ready_cb_)); |
| 539 } |
| 540 |
| 541 void MediaDrmBridge::NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb) { |
| 542 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 543 |
| 544 DCHECK(!cb.is_null()); |
| 545 DCHECK(!GetMediaCrypto().is_null()); |
| 546 |
| 547 // We can use scoped_ptr to pass ScopedJavaGlobalRef with a callback. |
| 548 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_object_ptr( |
| 549 new ScopedJavaGlobalRef<jobject>()); |
| 550 j_object_ptr->Reset(AttachCurrentThread(), GetMediaCrypto().obj()); |
| 551 |
| 552 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); |
494 } | 553 } |
495 | 554 |
496 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 555 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
497 jobject j_media_drm, | 556 jobject j_media_drm, |
498 jint j_promise_id) { | 557 jint j_promise_id) { |
499 cdm_promise_adapter_.ResolvePromise(j_promise_id); | 558 cdm_promise_adapter_.ResolvePromise(j_promise_id); |
500 } | 559 } |
501 | 560 |
502 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 561 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
503 jobject j_media_drm, | 562 jobject j_media_drm, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 jbyteArray j_session_id) { | 597 jbyteArray j_session_id) { |
539 session_closed_cb_.Run(GetSessionId(env, j_session_id)); | 598 session_closed_cb_.Run(GetSessionId(env, j_session_id)); |
540 } | 599 } |
541 | 600 |
542 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 601 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
543 jobject j_media_drm, | 602 jobject j_media_drm, |
544 jbyteArray j_session_id, | 603 jbyteArray j_session_id, |
545 jobjectArray j_keys_info, | 604 jobjectArray j_keys_info, |
546 bool has_additional_usable_key) { | 605 bool has_additional_usable_key) { |
547 if (has_additional_usable_key) | 606 if (has_additional_usable_key) |
548 player_tracker_.NotifyNewKey(); | 607 NotifyNewKeyOnCorrectThread(); |
549 | 608 |
550 CdmKeysInfo cdm_keys_info; | 609 CdmKeysInfo cdm_keys_info; |
551 | 610 |
552 size_t size = env->GetArrayLength(j_keys_info); | 611 size_t size = env->GetArrayLength(j_keys_info); |
553 DCHECK_GT(size, 0u); | 612 DCHECK_GT(size, 0u); |
554 | 613 |
555 for (size_t i = 0; i < size; ++i) { | 614 for (size_t i = 0; i < size; ++i) { |
556 ScopedJavaLocalRef<jobject> j_key_status( | 615 ScopedJavaLocalRef<jobject> j_key_status( |
557 env, env->GetObjectArrayElement(j_keys_info, i)); | 616 env, env->GetObjectArrayElement(j_keys_info, i)); |
558 | 617 |
(...skipping 17 matching lines...) Expand all Loading... |
576 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | 635 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); |
577 cdm_key_information->key_id = key_id; | 636 cdm_key_information->key_id = key_id; |
578 cdm_key_information->status = key_status; | 637 cdm_key_information->status = key_status; |
579 cdm_keys_info.push_back(cdm_key_information.release()); | 638 cdm_keys_info.push_back(cdm_key_information.release()); |
580 } | 639 } |
581 | 640 |
582 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), | 641 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), |
583 has_additional_usable_key, cdm_keys_info.Pass()); | 642 has_additional_usable_key, cdm_keys_info.Pass()); |
584 } | 643 } |
585 | 644 |
| 645 void MediaDrmBridge::NotifyNewKeyOnCorrectThread() { |
| 646 // Repost this method onto the Media thread if |use_media_thread_| is true. |
| 647 if (use_media_thread_ && !GetMediaTaskRunner()->BelongsToCurrentThread()) { |
| 648 GetMediaTaskRunner()->PostTask( |
| 649 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyNewKeyOnCorrectThread, |
| 650 media_weak_factory_.GetWeakPtr())); |
| 651 return; |
| 652 } |
| 653 |
| 654 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); |
| 655 DVLOG(1) << __FUNCTION__; |
| 656 |
| 657 player_tracker_.NotifyNewKey(); |
| 658 } |
| 659 |
586 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 660 // 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], | 661 // 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 | 662 // 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 | 663 // 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]. | 664 // spec uses to indicate that the license will never expire [5]. |
591 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio
nUpdateListener.html | 665 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio
nUpdateListener.html |
592 // [2] See base::Time::FromDoubleT() | 666 // [2] See base::Time::FromDoubleT() |
593 // [3] See base::Time::ToJavaTime() | 667 // [3] See base::Time::ToJavaTime() |
594 // [4] See MediaKeySession::expirationChanged() | 668 // [4] See MediaKeySession::expirationChanged() |
595 // [5] https://github.com/w3c/encrypted-media/issues/58 | 669 // [5] https://github.com/w3c/encrypted-media/issues/58 |
(...skipping 10 matching lines...) Expand all Loading... |
606 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 680 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
607 jobject j_media_drm, | 681 jobject j_media_drm, |
608 jbyteArray j_session_id, | 682 jbyteArray j_session_id, |
609 jstring j_error_message) { | 683 jstring j_error_message) { |
610 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 684 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
611 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), | 685 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), |
612 MediaKeys::UNKNOWN_ERROR, 0, error_message); | 686 MediaKeys::UNKNOWN_ERROR, 0, error_message); |
613 } | 687 } |
614 | 688 |
615 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { | 689 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { |
| 690 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 691 |
616 JNIEnv* env = AttachCurrentThread(); | 692 JNIEnv* env = AttachCurrentThread(); |
617 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); | 693 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); |
618 } | 694 } |
619 | 695 |
620 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 696 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
621 JNIEnv* env = AttachCurrentThread(); | 697 JNIEnv* env = AttachCurrentThread(); |
622 ScopedJavaLocalRef<jstring> j_security_level = | 698 ScopedJavaLocalRef<jstring> j_security_level = |
623 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); | 699 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); |
624 std::string security_level_str = | 700 std::string security_level_str = |
625 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 701 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
626 return GetSecurityLevelFromString(security_level_str); | 702 return GetSecurityLevelFromString(security_level_str); |
627 } | 703 } |
628 | 704 |
629 bool MediaDrmBridge::IsProtectedSurfaceRequired() { | 705 bool MediaDrmBridge::IsProtectedSurfaceRequired() { |
630 // For Widevine, this depends on the security level. | 706 // For Widevine, this depends on the security level. |
631 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) | 707 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) |
632 return IsSecureDecoderRequired(GetSecurityLevel()); | 708 return IsSecureDecoderRequired(GetSecurityLevel()); |
633 | 709 |
634 // For other key systems, assume true. | 710 // For other key systems, assume true. |
635 return true; | 711 return true; |
636 } | 712 } |
637 | 713 |
| 714 base::WeakPtr<MediaDrmBridge> MediaDrmBridge::WeakPtrForUIThread() { |
| 715 return ui_weak_factory_.GetWeakPtr(); |
| 716 } |
| 717 |
638 void MediaDrmBridge::ResetDeviceCredentials( | 718 void MediaDrmBridge::ResetDeviceCredentials( |
639 const ResetCredentialsCB& callback) { | 719 const ResetCredentialsCB& callback) { |
640 DCHECK(reset_credentials_cb_.is_null()); | 720 DCHECK(reset_credentials_cb_.is_null()); |
641 reset_credentials_cb_ = callback; | 721 reset_credentials_cb_ = callback; |
642 JNIEnv* env = AttachCurrentThread(); | 722 JNIEnv* env = AttachCurrentThread(); |
643 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 723 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
644 } | 724 } |
645 | 725 |
646 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 726 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
647 JNIEnv* env, jobject, bool success) { | 727 JNIEnv* env, jobject, bool success) { |
648 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 728 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
649 } | 729 } |
650 | 730 |
651 } // namespace media | 731 } // namespace media |
OLD | NEW |