| 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" |
| 27 #include "media/base/android/media_codec_player.h" // for GetMediaTaskRunner() |
| 26 #include "media/base/android/media_drm_bridge_delegate.h" | 28 #include "media/base/android/media_drm_bridge_delegate.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 |
| 33 #define RUN_CB_ON_MEDIA_THREAD(CB, ...) \ |
| 34 do { \ |
| 35 if (run_on_media_thread_ && \ |
| 36 !GetMediaTaskRunner()->BelongsToCurrentThread()) { \ |
| 37 GetMediaTaskRunner()->PostTask(FROM_HERE, \ |
| 38 base::Bind(CB, ##__VA_ARGS__)); \ |
| 39 } else { \ |
| 40 CB.Run(__VA_ARGS__); \ |
| 41 } \ |
| 42 } while (0) |
| 43 |
| 31 using base::android::AttachCurrentThread; | 44 using base::android::AttachCurrentThread; |
| 32 using base::android::ConvertUTF8ToJavaString; | 45 using base::android::ConvertUTF8ToJavaString; |
| 33 using base::android::ConvertJavaStringToUTF8; | 46 using base::android::ConvertJavaStringToUTF8; |
| 34 using base::android::JavaByteArrayToByteVector; | 47 using base::android::JavaByteArrayToByteVector; |
| 35 using base::android::ScopedJavaLocalRef; | 48 using base::android::ScopedJavaLocalRef; |
| 36 | 49 |
| 37 namespace media { | 50 namespace media { |
| 38 | 51 |
| 39 namespace { | 52 namespace { |
| 40 | 53 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 int32 os_bugfix_version = 0; | 234 int32 os_bugfix_version = 0; |
| 222 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 235 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 223 &os_minor_version, | 236 &os_minor_version, |
| 224 &os_bugfix_version); | 237 &os_bugfix_version); |
| 225 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) | 238 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) |
| 226 return false; | 239 return false; |
| 227 | 240 |
| 228 return true; | 241 return true; |
| 229 } | 242 } |
| 230 | 243 |
| 244 // static |
| 245 bool MediaDrmBridge::CanCreate(const std::string& key_system, |
| 246 SecurityLevel widevine_security_level) { |
| 247 if (!IsAvailable()) { |
| 248 DVLOG(1) << __FUNCTION__ << ": DRM is not available"; |
| 249 return false; |
| 250 } |
| 251 |
| 252 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); |
| 253 if (scheme_uuid.empty()) { |
| 254 DVLOG(1) << __FUNCTION__ << ": key system " << key_system |
| 255 << " not supported"; |
| 256 return false; |
| 257 } |
| 258 |
| 259 if (key_system == kWidevineKeySystem && |
| 260 widevine_security_level != SECURITY_LEVEL_NONE && |
| 261 !std::equal(scheme_uuid.begin(), scheme_uuid.end(), kWidevineUuid)) { |
| 262 NOTREACHED() << "Widevine security level " << widevine_security_level |
| 263 << "used with another key system"; |
| 264 return false; |
| 265 } |
| 266 return true; |
| 267 } |
| 268 |
| 231 // TODO(ddorwin): This is specific to Widevine. http://crbug.com/459400 | 269 // TODO(ddorwin): This is specific to Widevine. http://crbug.com/459400 |
| 232 // static | 270 // static |
| 233 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { | 271 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { |
| 234 DCHECK(IsAvailable()); | 272 DCHECK(IsAvailable()); |
| 235 return SECURITY_LEVEL_1 == security_level; | 273 return SECURITY_LEVEL_1 == security_level; |
| 236 } | 274 } |
| 237 | 275 |
| 238 // static | 276 // static |
| 239 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | 277 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 240 return g_key_system_manager.Get().GetPlatformKeySystemNames(); | 278 return g_key_system_manager.Get().GetPlatformKeySystemNames(); |
| 241 } | 279 } |
| 242 | 280 |
| 243 // static | 281 // static |
| 244 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { | 282 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { |
| 245 DCHECK(!key_system.empty()); | 283 DCHECK(!key_system.empty()); |
| 246 return IsKeySystemSupportedWithTypeImpl(key_system, ""); | 284 return IsKeySystemSupportedWithTypeImpl(key_system, ""); |
| 247 } | 285 } |
| 248 | 286 |
| 249 // static | 287 // static |
| 250 bool MediaDrmBridge::IsKeySystemSupportedWithType( | 288 bool MediaDrmBridge::IsKeySystemSupportedWithType( |
| 251 const std::string& key_system, | 289 const std::string& key_system, |
| 252 const std::string& container_mime_type) { | 290 const std::string& container_mime_type) { |
| 253 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 291 DCHECK(!key_system.empty() && !container_mime_type.empty()); |
| 254 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); | 292 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); |
| 255 } | 293 } |
| 256 | 294 |
| 295 // static |
| 257 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { | 296 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { |
| 258 return RegisterNativesImpl(env); | 297 return RegisterNativesImpl(env); |
| 259 } | 298 } |
| 260 | 299 |
| 261 MediaDrmBridge::MediaDrmBridge( | 300 MediaDrmBridge::MediaDrmBridge( |
| 262 const std::vector<uint8>& scheme_uuid, | 301 const std::vector<uint8>& scheme_uuid, |
| 263 const SessionMessageCB& session_message_cb, | 302 const SessionMessageCB& session_message_cb, |
| 264 const SessionClosedCB& session_closed_cb, | 303 const SessionClosedCB& session_closed_cb, |
| 265 const LegacySessionErrorCB& legacy_session_error_cb, | 304 const LegacySessionErrorCB& legacy_session_error_cb, |
| 266 const SessionKeysChangeCB& session_keys_change_cb, | 305 const SessionKeysChangeCB& session_keys_change_cb, |
| 267 const SessionExpirationUpdateCB& session_expiration_update_cb) | 306 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 268 : scheme_uuid_(scheme_uuid), | 307 : scheme_uuid_(scheme_uuid), |
| 269 session_message_cb_(session_message_cb), | 308 session_message_cb_(session_message_cb), |
| 270 session_closed_cb_(session_closed_cb), | 309 session_closed_cb_(session_closed_cb), |
| 271 legacy_session_error_cb_(legacy_session_error_cb), | 310 legacy_session_error_cb_(legacy_session_error_cb), |
| 272 session_keys_change_cb_(session_keys_change_cb), | 311 session_keys_change_cb_(session_keys_change_cb), |
| 273 session_expiration_update_cb_(session_expiration_update_cb) { | 312 session_expiration_update_cb_(session_expiration_update_cb), |
| 313 run_on_media_thread_(false) { |
| 314 DVLOG(1) << "MediaDrmBridge::MediaDrmBridge"; |
| 315 |
| 316 // When this flag is set we need to repost the notifications about |
| 317 // crypto became ready and a key had been added to the Media thread. |
| 318 run_on_media_thread_ = GetMediaTaskRunner()->BelongsToCurrentThread(); |
| 319 |
| 320 // Create internal callbacks to repost Java notifications to the media thread. |
| 321 // TODO(timav): weak pointers instead of unretained? |
| 322 internal_keys_added_cb_ = |
| 323 base::Bind(&MediaDrmBridge::InternalKeysAdded, base::Unretained(this)); |
| 324 |
| 274 JNIEnv* env = AttachCurrentThread(); | 325 JNIEnv* env = AttachCurrentThread(); |
| 275 CHECK(env); | 326 CHECK(env); |
| 276 | 327 |
| 277 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 328 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 278 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 329 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 279 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 330 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 280 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 331 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
| 281 } | 332 } |
| 282 | 333 |
| 283 MediaDrmBridge::~MediaDrmBridge() { | 334 MediaDrmBridge::~MediaDrmBridge() { |
| 284 JNIEnv* env = AttachCurrentThread(); | 335 JNIEnv* env = AttachCurrentThread(); |
| 285 player_tracker_.NotifyCdmUnset(); | 336 player_tracker_.NotifyCdmUnset(); |
| 286 if (!j_media_drm_.is_null()) | 337 if (!j_media_drm_.is_null()) |
| 287 Java_MediaDrmBridge_destroy(env, j_media_drm_.obj()); | 338 Java_MediaDrmBridge_destroy(env, j_media_drm_.obj()); |
| 288 } | 339 } |
| 289 | 340 |
| 290 // static | 341 // static |
| 291 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( | 342 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> MediaDrmBridge::Create( |
| 292 const std::string& key_system, | 343 const std::string& key_system, |
| 344 SecurityLevel widevine_security_level, |
| 293 const SessionMessageCB& session_message_cb, | 345 const SessionMessageCB& session_message_cb, |
| 294 const SessionClosedCB& session_closed_cb, | 346 const SessionClosedCB& session_closed_cb, |
| 295 const LegacySessionErrorCB& legacy_session_error_cb, | 347 const LegacySessionErrorCB& legacy_session_error_cb, |
| 296 const SessionKeysChangeCB& session_keys_change_cb, | 348 const SessionKeysChangeCB& session_keys_change_cb, |
| 297 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 349 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 298 scoped_ptr<MediaDrmBridge> media_drm_bridge; | 350 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge; |
| 299 if (!IsAvailable()) | 351 if (!IsAvailable()) |
| 300 return media_drm_bridge.Pass(); | 352 return media_drm_bridge.Pass(); |
| 301 | 353 |
| 302 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 354 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); |
| 303 if (scheme_uuid.empty()) | 355 if (scheme_uuid.empty()) |
| 304 return media_drm_bridge.Pass(); | 356 return media_drm_bridge.Pass(); |
| 305 | 357 |
| 306 media_drm_bridge.reset( | 358 media_drm_bridge.reset( |
| 307 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, | 359 new MediaDrmBridge(scheme_uuid, session_message_cb, session_closed_cb, |
| 308 legacy_session_error_cb, session_keys_change_cb, | 360 legacy_session_error_cb, session_keys_change_cb, |
| 309 session_expiration_update_cb)); | 361 session_expiration_update_cb)); |
| 310 | 362 |
| 311 if (media_drm_bridge->j_media_drm_.is_null()) | 363 if (media_drm_bridge->j_media_drm_.is_null()) |
| 312 media_drm_bridge.reset(); | 364 media_drm_bridge.reset(); |
| 313 | 365 |
| 366 if (key_system == kWidevineKeySystem && |
| 367 widevine_security_level != SECURITY_LEVEL_NONE && |
| 368 !media_drm_bridge->SetSecurityLevel(widevine_security_level)) { |
| 369 DVLOG(1) << __FUNCTION__ << ": failed to set security level " |
| 370 << widevine_security_level; |
| 371 media_drm_bridge.reset(); |
| 372 } |
| 373 |
| 314 return media_drm_bridge.Pass(); | 374 return media_drm_bridge.Pass(); |
| 315 } | 375 } |
| 316 | 376 |
| 317 // static | 377 // static |
| 318 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 378 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> |
| 319 const std::string& key_system) { | 379 MediaDrmBridge::CreateWithoutSessionSupport(const std::string& key_system) { |
| 320 return MediaDrmBridge::Create( | 380 return MediaDrmBridge::Create(key_system, SECURITY_LEVEL_NONE, |
| 321 key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(), | 381 SessionMessageCB(), SessionClosedCB(), |
| 322 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 382 LegacySessionErrorCB(), SessionKeysChangeCB(), |
| 383 SessionExpirationUpdateCB()); |
| 323 } | 384 } |
| 324 | 385 |
| 325 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { | 386 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { |
| 326 if (security_level != SECURITY_LEVEL_NONE && | 387 if (security_level != SECURITY_LEVEL_NONE && |
| 327 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { | 388 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { |
| 328 NOTREACHED() << "Widevine security level " << security_level | 389 NOTREACHED() << "Widevine security level " << security_level |
| 329 << "used with another key system"; | 390 << "used with another key system"; |
| 330 return false; | 391 return false; |
| 331 } | 392 } |
| 332 | 393 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, | 526 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, |
| 466 const base::Closure& cdm_unset_cb) { | 527 const base::Closure& cdm_unset_cb) { |
| 467 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); | 528 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); |
| 468 } | 529 } |
| 469 | 530 |
| 470 void MediaDrmBridge::UnregisterPlayer(int registration_id) { | 531 void MediaDrmBridge::UnregisterPlayer(int registration_id) { |
| 471 player_tracker_.UnregisterPlayer(registration_id); | 532 player_tracker_.UnregisterPlayer(registration_id); |
| 472 } | 533 } |
| 473 | 534 |
| 474 void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure& closure) { | 535 void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure& closure) { |
| 536 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 537 |
| 475 if (closure.is_null()) { | 538 if (closure.is_null()) { |
| 476 media_crypto_ready_cb_.Reset(); | 539 media_crypto_ready_cb_.Reset(); |
| 477 return; | 540 return; |
| 478 } | 541 } |
| 479 | 542 |
| 480 DCHECK(media_crypto_ready_cb_.is_null()); | 543 DCHECK(media_crypto_ready_cb_.is_null()); |
| 481 | 544 |
| 482 if (!GetMediaCrypto().is_null()) { | 545 if (!GetMediaCrypto().is_null()) { |
| 483 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 546 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
| 484 return; | 547 return; |
| 485 } | 548 } |
| 486 | 549 |
| 487 media_crypto_ready_cb_ = closure; | 550 media_crypto_ready_cb_ = closure; |
| 488 } | 551 } |
| 489 | 552 |
| 490 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { | 553 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm) { |
| 554 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 555 |
| 491 DCHECK(!GetMediaCrypto().is_null()); | 556 DCHECK(!GetMediaCrypto().is_null()); |
| 492 if (!media_crypto_ready_cb_.is_null()) | 557 |
| 493 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); | 558 if (media_crypto_ready_cb_.is_null()) |
| 559 return; |
| 560 |
| 561 RUN_CB_ON_MEDIA_THREAD(base::ResetAndReturn(&media_crypto_ready_cb_)); |
| 494 } | 562 } |
| 495 | 563 |
| 496 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, | 564 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
| 497 jobject j_media_drm, | 565 jobject j_media_drm, |
| 498 jint j_promise_id) { | 566 jint j_promise_id) { |
| 567 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 499 cdm_promise_adapter_.ResolvePromise(j_promise_id); | 568 cdm_promise_adapter_.ResolvePromise(j_promise_id); |
| 500 } | 569 } |
| 501 | 570 |
| 502 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, | 571 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
| 503 jobject j_media_drm, | 572 jobject j_media_drm, |
| 504 jint j_promise_id, | 573 jint j_promise_id, |
| 505 jbyteArray j_session_id) { | 574 jbyteArray j_session_id) { |
| 575 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 506 cdm_promise_adapter_.ResolvePromise(j_promise_id, | 576 cdm_promise_adapter_.ResolvePromise(j_promise_id, |
| 507 GetSessionId(env, j_session_id)); | 577 GetSessionId(env, j_session_id)); |
| 508 } | 578 } |
| 509 | 579 |
| 510 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, | 580 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, |
| 511 jobject j_media_drm, | 581 jobject j_media_drm, |
| 512 jint j_promise_id, | 582 jint j_promise_id, |
| 513 jstring j_error_message) { | 583 jstring j_error_message) { |
| 584 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 514 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 585 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
| 515 cdm_promise_adapter_.RejectPromise(j_promise_id, MediaKeys::UNKNOWN_ERROR, 0, | 586 cdm_promise_adapter_.RejectPromise(j_promise_id, MediaKeys::UNKNOWN_ERROR, 0, |
| 516 error_message); | 587 error_message); |
| 517 } | 588 } |
| 518 | 589 |
| 519 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, | 590 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, |
| 520 jobject j_media_drm, | 591 jobject j_media_drm, |
| 521 jbyteArray j_session_id, | 592 jbyteArray j_session_id, |
| 522 jint j_message_type, | 593 jint j_message_type, |
| 523 jbyteArray j_message, | 594 jbyteArray j_message, |
| 524 jstring j_legacy_destination_url) { | 595 jstring j_legacy_destination_url) { |
| 596 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 597 |
| 525 std::vector<uint8> message; | 598 std::vector<uint8> message; |
| 526 JavaByteArrayToByteVector(env, j_message, &message); | 599 JavaByteArrayToByteVector(env, j_message, &message); |
| 527 GURL legacy_destination_url = | 600 GURL legacy_destination_url = |
| 528 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); | 601 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); |
| 529 MediaKeys::MessageType message_type = | 602 MediaKeys::MessageType message_type = |
| 530 GetMessageType(static_cast<RequestType>(j_message_type)); | 603 GetMessageType(static_cast<RequestType>(j_message_type)); |
| 531 | 604 |
| 532 session_message_cb_.Run(GetSessionId(env, j_session_id), message_type, | 605 session_message_cb_.Run(GetSessionId(env, j_session_id), message_type, |
| 533 message, legacy_destination_url); | 606 message, legacy_destination_url); |
| 534 } | 607 } |
| 535 | 608 |
| 536 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, | 609 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, |
| 537 jobject j_media_drm, | 610 jobject j_media_drm, |
| 538 jbyteArray j_session_id) { | 611 jbyteArray j_session_id) { |
| 612 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 539 session_closed_cb_.Run(GetSessionId(env, j_session_id)); | 613 session_closed_cb_.Run(GetSessionId(env, j_session_id)); |
| 540 } | 614 } |
| 541 | 615 |
| 542 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, | 616 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
| 543 jobject j_media_drm, | 617 jobject j_media_drm, |
| 544 jbyteArray j_session_id, | 618 jbyteArray j_session_id, |
| 545 jobjectArray j_keys_info, | 619 jobjectArray j_keys_info, |
| 546 bool has_additional_usable_key) { | 620 bool has_additional_usable_key) { |
| 547 if (has_additional_usable_key) | 621 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 548 player_tracker_.NotifyNewKey(); | |
| 549 | 622 |
| 550 CdmKeysInfo cdm_keys_info; | 623 CdmKeysInfo cdm_keys_info; |
| 551 | 624 |
| 552 size_t size = env->GetArrayLength(j_keys_info); | 625 size_t size = env->GetArrayLength(j_keys_info); |
| 553 DCHECK_GT(size, 0u); | 626 DCHECK_GT(size, 0u); |
| 554 | 627 |
| 555 for (size_t i = 0; i < size; ++i) { | 628 for (size_t i = 0; i < size; ++i) { |
| 556 ScopedJavaLocalRef<jobject> j_key_status( | 629 ScopedJavaLocalRef<jobject> j_key_status( |
| 557 env, env->GetObjectArrayElement(j_keys_info, i)); | 630 env, env->GetObjectArrayElement(j_keys_info, i)); |
| 558 | 631 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 572 << key_status; | 645 << key_status; |
| 573 | 646 |
| 574 // TODO(xhwang): Update CdmKeyInformation to take key_id and status in the | 647 // TODO(xhwang): Update CdmKeyInformation to take key_id and status in the |
| 575 // constructor. | 648 // constructor. |
| 576 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | 649 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); |
| 577 cdm_key_information->key_id = key_id; | 650 cdm_key_information->key_id = key_id; |
| 578 cdm_key_information->status = key_status; | 651 cdm_key_information->status = key_status; |
| 579 cdm_keys_info.push_back(cdm_key_information.release()); | 652 cdm_keys_info.push_back(cdm_key_information.release()); |
| 580 } | 653 } |
| 581 | 654 |
| 655 RUN_CB_ON_MEDIA_THREAD(internal_keys_added_cb_, has_additional_usable_key); |
| 656 |
| 582 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), | 657 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), |
| 583 has_additional_usable_key, cdm_keys_info.Pass()); | 658 has_additional_usable_key, cdm_keys_info.Pass()); |
| 584 } | 659 } |
| 585 | 660 |
| 661 void MediaDrmBridge::InternalKeysAdded(bool has_additional_usable_key) { |
| 662 if (has_additional_usable_key) |
| 663 player_tracker_.NotifyNewKey(); |
| 664 } |
| 665 |
| 586 // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys | 666 // 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], | 667 // 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 | 668 // 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 | 669 // 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]. | 670 // spec uses to indicate that the license will never expire [5]. |
| 591 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio
nUpdateListener.html | 671 // [1] http://developer.android.com/reference/android/media/MediaDrm.OnExpiratio
nUpdateListener.html |
| 592 // [2] See base::Time::FromDoubleT() | 672 // [2] See base::Time::FromDoubleT() |
| 593 // [3] See base::Time::ToJavaTime() | 673 // [3] See base::Time::ToJavaTime() |
| 594 // [4] See MediaKeySession::expirationChanged() | 674 // [4] See MediaKeySession::expirationChanged() |
| 595 // [5] https://github.com/w3c/encrypted-media/issues/58 | 675 // [5] https://github.com/w3c/encrypted-media/issues/58 |
| 596 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, | 676 void MediaDrmBridge::OnSessionExpirationUpdate(JNIEnv* env, |
| 597 jobject j_media_drm, | 677 jobject j_media_drm, |
| 598 jbyteArray j_session_id, | 678 jbyteArray j_session_id, |
| 599 jlong expiry_time_ms) { | 679 jlong expiry_time_ms) { |
| 600 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; | 680 DVLOG(2) << __FUNCTION__ << ": " << expiry_time_ms << " ms"; |
| 601 session_expiration_update_cb_.Run( | 681 session_expiration_update_cb_.Run( |
| 602 GetSessionId(env, j_session_id), | 682 GetSessionId(env, j_session_id), |
| 603 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); | 683 base::Time::FromDoubleT(expiry_time_ms / 1000.0)); |
| 604 } | 684 } |
| 605 | 685 |
| 606 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | 686 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, |
| 607 jobject j_media_drm, | 687 jobject j_media_drm, |
| 608 jbyteArray j_session_id, | 688 jbyteArray j_session_id, |
| 609 jstring j_error_message) { | 689 jstring j_error_message) { |
| 690 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 610 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | 691 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); |
| 611 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), | 692 legacy_session_error_cb_.Run(GetSessionId(env, j_session_id), |
| 612 MediaKeys::UNKNOWN_ERROR, 0, error_message); | 693 MediaKeys::UNKNOWN_ERROR, 0, error_message); |
| 613 } | 694 } |
| 614 | 695 |
| 615 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { | 696 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { |
| 616 JNIEnv* env = AttachCurrentThread(); | 697 JNIEnv* env = AttachCurrentThread(); |
| 617 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); | 698 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); |
| 618 } | 699 } |
| 619 | 700 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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) { |
| 729 DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__; |
| 730 |
| 648 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 731 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 649 } | 732 } |
| 650 | 733 |
| 651 } // namespace media | 734 } // namespace media |
| OLD | NEW |