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 PostMediaCryptoReady(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 PostMediaCryptoReady(base::ResetAndReturn(&media_crypto_ready_cb_)); | |
Tima Vaisburd
2015/09/29 21:51:40
With this change the new code does one extra post
| |
539 } | |
540 | |
541 void MediaDrmBridge::PostMediaCryptoReady(const MediaCryptoReadyCB& cb) { | |
xhwang
2015/09/29 23:00:29
We are not "Post"ing in this function any more. So
Tima Vaisburd
2015/09/29 23:40:20
Done.
| |
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| is bound to a thread so this Run() will actually post a task. | |
xhwang
2015/09/29 23:00:30
This is really an implementation detail of the cal
Tima Vaisburd
2015/09/29 23:40:20
Acknowledged.
| |
553 cb.Run(j_object_ptr.Pass(), IsProtectedSurfaceRequired()); | |
494 } | 554 } |
495 | 555 |
496 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 556 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
497 jobject j_media_drm, | 557 jobject j_media_drm, |
498 jint j_promise_id) { | 558 jint j_promise_id) { |
499 cdm_promise_adapter_.ResolvePromise(j_promise_id); | 559 cdm_promise_adapter_.ResolvePromise(j_promise_id); |
500 } | 560 } |
501 | 561 |
502 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 562 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
503 jobject j_media_drm, | 563 jobject j_media_drm, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 jbyteArray j_session_id) { | 598 jbyteArray j_session_id) { |
539 session_closed_cb_.Run(GetSessionId(env, j_session_id)); | 599 session_closed_cb_.Run(GetSessionId(env, j_session_id)); |
540 } | 600 } |
541 | 601 |
542 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 602 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
543 jobject j_media_drm, | 603 jobject j_media_drm, |
544 jbyteArray j_session_id, | 604 jbyteArray j_session_id, |
545 jobjectArray j_keys_info, | 605 jobjectArray j_keys_info, |
546 bool has_additional_usable_key) { | 606 bool has_additional_usable_key) { |
547 if (has_additional_usable_key) | 607 if (has_additional_usable_key) |
548 player_tracker_.NotifyNewKey(); | 608 NotifyNewKeyOnCorrectThread(); |
549 | 609 |
550 CdmKeysInfo cdm_keys_info; | 610 CdmKeysInfo cdm_keys_info; |
551 | 611 |
552 size_t size = env->GetArrayLength(j_keys_info); | 612 size_t size = env->GetArrayLength(j_keys_info); |
553 DCHECK_GT(size, 0u); | 613 DCHECK_GT(size, 0u); |
554 | 614 |
555 for (size_t i = 0; i < size; ++i) { | 615 for (size_t i = 0; i < size; ++i) { |
556 ScopedJavaLocalRef<jobject> j_key_status( | 616 ScopedJavaLocalRef<jobject> j_key_status( |
557 env, env->GetObjectArrayElement(j_keys_info, i)); | 617 env, env->GetObjectArrayElement(j_keys_info, i)); |
558 | 618 |
(...skipping 17 matching lines...) Expand all Loading... | |
576 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | 636 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); |
577 cdm_key_information->key_id = key_id; | 637 cdm_key_information->key_id = key_id; |
578 cdm_key_information->status = key_status; | 638 cdm_key_information->status = key_status; |
579 cdm_keys_info.push_back(cdm_key_information.release()); | 639 cdm_keys_info.push_back(cdm_key_information.release()); |
580 } | 640 } |
581 | 641 |
582 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), | 642 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), |
583 has_additional_usable_key, cdm_keys_info.Pass()); | 643 has_additional_usable_key, cdm_keys_info.Pass()); |
584 } | 644 } |
585 | 645 |
646 void MediaDrmBridge::NotifyNewKeyOnCorrectThread() { | |
647 // Repost this method onto the Media thread if |use_media_thread_| is true. | |
648 if (use_media_thread_ && !GetMediaTaskRunner()->BelongsToCurrentThread()) { | |
649 GetMediaTaskRunner()->PostTask( | |
650 FROM_HERE, base::Bind(&MediaDrmBridge::NotifyNewKeyOnCorrectThread, | |
651 media_weak_factory_.GetWeakPtr())); | |
652 return; | |
653 } | |
654 | |
655 DCHECK(!use_media_thread_ || GetMediaTaskRunner()->BelongsToCurrentThread()); | |
656 DVLOG(1) << __FUNCTION__; | |
657 | |
658 player_tracker_.NotifyNewKey(); | |
659 } | |
660 | |
586 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 661 // 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], | 662 // 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 | 663 // 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 | 664 // 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]. | 665 // spec uses to indicate that the license will never expire [5]. |
591 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio nUpdateListener.html | 666 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio nUpdateListener.html |
592 // [2] See base::Time::FromDoubleT() | 667 // [2] See base::Time::FromDoubleT() |
593 // [3] See base::Time::ToJavaTime() | 668 // [3] See base::Time::ToJavaTime() |
594 // [4] See MediaKeySession::expirationChanged() | 669 // [4] See MediaKeySession::expirationChanged() |
595 // [5] https://github.com/w3c/encrypted-media/issues/58 | 670 // [5] https://github.com/w3c/encrypted-media/issues/58 |
(...skipping 10 matching lines...) Expand all Loading... | |
606 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 681 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
607 jobject j_media_drm, | 682 jobject j_media_drm, |
608 jbyteArray j_session_id, | 683 jbyteArray j_session_id, |
609 jstring j_error_message) { | 684 jstring j_error_message) { |
610 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 685 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
611 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), | 686 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), |
612 MediaKeys::UNKNOWN_ERROR, 0, error_message); | 687 MediaKeys::UNKNOWN_ERROR, 0, error_message); |
613 } | 688 } |
614 | 689 |
615 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { | 690 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { |
691 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
692 | |
616 JNIEnv* env = AttachCurrentThread(); | 693 JNIEnv* env = AttachCurrentThread(); |
617 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); | 694 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); |
618 } | 695 } |
619 | 696 |
620 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 697 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
621 JNIEnv* env = AttachCurrentThread(); | 698 JNIEnv* env = AttachCurrentThread(); |
622 ScopedJavaLocalRef<jstring> j_security_level = | 699 ScopedJavaLocalRef<jstring> j_security_level = |
623 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); | 700 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); |
624 std::string security_level_str = | 701 std::string security_level_str = |
625 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 702 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
626 return GetSecurityLevelFromString(security_level_str); | 703 return GetSecurityLevelFromString(security_level_str); |
627 } | 704 } |
628 | 705 |
629 bool MediaDrmBridge::IsProtectedSurfaceRequired() { | 706 bool MediaDrmBridge::IsProtectedSurfaceRequired() { |
630 // For Widevine, this depends on the security level. | 707 // For Widevine, this depends on the security level. |
631 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) | 708 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) |
632 return IsSecureDecoderRequired(GetSecurityLevel()); | 709 return IsSecureDecoderRequired(GetSecurityLevel()); |
633 | 710 |
634 // For other key systems, assume true. | 711 // For other key systems, assume true. |
635 return true; | 712 return true; |
636 } | 713 } |
637 | 714 |
715 base::WeakPtr<MediaDrmBridge> MediaDrmBridge::WeakPtrForUIThread() { | |
716 return ui_weak_factory_.GetWeakPtr(); | |
717 } | |
718 | |
638 void MediaDrmBridge::ResetDeviceCredentials( | 719 void MediaDrmBridge::ResetDeviceCredentials( |
639 const ResetCredentialsCB& callback) { | 720 const ResetCredentialsCB& callback) { |
640 DCHECK(reset_credentials_cb_.is_null()); | 721 DCHECK(reset_credentials_cb_.is_null()); |
641 reset_credentials_cb_ = callback; | 722 reset_credentials_cb_ = callback; |
642 JNIEnv* env = AttachCurrentThread(); | 723 JNIEnv* env = AttachCurrentThread(); |
643 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 724 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
644 } | 725 } |
645 | 726 |
646 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 727 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
647 JNIEnv* env, jobject, bool success) { | 728 JNIEnv* env, jobject, bool success) { |
648 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 729 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
649 } | 730 } |
650 | 731 |
651 } // namespace media | 732 } // namespace media |
OLD | NEW |