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/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/message_loop/message_loop_proxy.h" | 17 #include "base/message_loop/message_loop_proxy.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/sys_byteorder.h" | 19 #include "base/sys_byteorder.h" |
| 20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 21 #include "jni/MediaDrmBridge_jni.h" | 21 #include "jni/MediaDrmBridge_jni.h" |
| 22 #include "media/base/cdm_key_information.h" | |
| 22 | 23 |
| 23 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 24 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 24 | 25 |
| 25 using base::android::AttachCurrentThread; | 26 using base::android::AttachCurrentThread; |
| 26 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
| 27 using base::android::ConvertJavaStringToUTF8; | 28 using base::android::ConvertJavaStringToUTF8; |
| 28 using base::android::JavaByteArrayToByteVector; | 29 using base::android::JavaByteArrayToByteVector; |
| 29 using base::android::ScopedJavaLocalRef; | 30 using base::android::ScopedJavaLocalRef; |
| 30 | 31 |
| 31 namespace media { | 32 namespace media { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 61 const int kBoxLargeSizeSize = 8; | 62 const int kBoxLargeSizeSize = 8; |
| 62 const int kPsshVersionFlagSize = 4; | 63 const int kPsshVersionFlagSize = 4; |
| 63 const int kPsshSystemIdSize = 16; | 64 const int kPsshSystemIdSize = 16; |
| 64 const int kPsshDataSizeSize = 4; | 65 const int kPsshDataSizeSize = 4; |
| 65 const uint32 kTencType = 0x74656e63; | 66 const uint32 kTencType = 0x74656e63; |
| 66 const uint32 kPsshType = 0x70737368; | 67 const uint32 kPsshType = 0x70737368; |
| 67 const uint8 kWidevineUuid[16] = { | 68 const uint8 kWidevineUuid[16] = { |
| 68 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 69 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
| 69 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 70 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
| 70 | 71 |
| 72 // DrmBridge supports session expiration event but doesn't provide detailed | |
| 73 // status for each key ID, which is required by the EME spec. Use a dummy key ID | |
| 74 // here to report session expiration info. | |
| 75 const char kDummyKeyId[] = "Dummy Key Id"; | |
|
dcheng
2015/01/17 00:08:16
These constants should probably all be in an unnam
xhwang
2015/01/17 01:20:40
consts are by default static, which is equivalent
| |
| 76 | |
| 71 typedef std::vector<uint8> UUID; | 77 typedef std::vector<uint8> UUID; |
| 72 | 78 |
| 73 class KeySystemUuidManager { | 79 class KeySystemUuidManager { |
| 74 public: | 80 public: |
| 75 KeySystemUuidManager(); | 81 KeySystemUuidManager(); |
| 76 UUID GetUUID(const std::string& key_system); | 82 UUID GetUUID(const std::string& key_system); |
| 77 void AddMapping(const std::string& key_system, const UUID& uuid); | 83 void AddMapping(const std::string& key_system, const UUID& uuid); |
| 78 std::vector<std::string> GetPlatformKeySystemNames(); | 84 std::vector<std::string> GetPlatformKeySystemNames(); |
| 79 | 85 |
| 80 private: | 86 private: |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 252 |
| 247 JNIEnv* env = AttachCurrentThread(); | 253 JNIEnv* env = AttachCurrentThread(); |
| 248 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 254 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 249 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 255 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 250 ScopedJavaLocalRef<jstring> j_container_mime_type = | 256 ScopedJavaLocalRef<jstring> j_container_mime_type = |
| 251 ConvertUTF8ToJavaString(env, container_mime_type); | 257 ConvertUTF8ToJavaString(env, container_mime_type); |
| 252 return Java_MediaDrmBridge_isCryptoSchemeSupported( | 258 return Java_MediaDrmBridge_isCryptoSchemeSupported( |
| 253 env, j_scheme_uuid.obj(), j_container_mime_type.obj()); | 259 env, j_scheme_uuid.obj(), j_container_mime_type.obj()); |
| 254 } | 260 } |
| 255 | 261 |
| 262 // Returns string session ID from jbyteArray (byte[] in Java). | |
| 263 static std::string GetSessionId(JNIEnv* env, jbyteArray j_session_id) { | |
| 264 std::vector<uint8> session_id_vector; | |
| 265 JavaByteArrayToByteVector(env, j_session_id, &session_id_vector); | |
| 266 return std::string(session_id_vector.begin(), session_id_vector.end()); | |
| 267 } | |
| 268 | |
| 256 // static | 269 // static |
| 257 bool MediaDrmBridge::IsAvailable() { | 270 bool MediaDrmBridge::IsAvailable() { |
| 258 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19) | 271 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19) |
| 259 return false; | 272 return false; |
| 260 | 273 |
| 261 int32 os_major_version = 0; | 274 int32 os_major_version = 0; |
| 262 int32 os_minor_version = 0; | 275 int32 os_minor_version = 0; |
| 263 int32 os_bugfix_version = 0; | 276 int32 os_bugfix_version = 0; |
| 264 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 277 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 265 &os_minor_version, | 278 &os_minor_version, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 276 return SECURITY_LEVEL_1 == security_level; | 289 return SECURITY_LEVEL_1 == security_level; |
| 277 } | 290 } |
| 278 | 291 |
| 279 // static | 292 // static |
| 280 bool MediaDrmBridge::IsSecurityLevelSupported(const std::string& key_system, | 293 bool MediaDrmBridge::IsSecurityLevelSupported(const std::string& key_system, |
| 281 SecurityLevel security_level) { | 294 SecurityLevel security_level) { |
| 282 if (!IsAvailable()) | 295 if (!IsAvailable()) |
| 283 return false; | 296 return false; |
| 284 | 297 |
| 285 scoped_ptr<MediaDrmBridge> media_drm_bridge = | 298 scoped_ptr<MediaDrmBridge> media_drm_bridge = |
| 286 MediaDrmBridge::CreateSessionless(key_system); | 299 MediaDrmBridge::CreateWithoutSessionSupport(key_system); |
| 287 if (!media_drm_bridge) | 300 if (!media_drm_bridge) |
| 288 return false; | 301 return false; |
| 289 | 302 |
| 290 return media_drm_bridge->SetSecurityLevel(security_level); | 303 return media_drm_bridge->SetSecurityLevel(security_level); |
| 291 } | 304 } |
| 292 | 305 |
| 293 static void AddKeySystemUuidMapping(JNIEnv* env, jclass clazz, | 306 static void AddKeySystemUuidMapping(JNIEnv* env, jclass clazz, |
| 294 jstring j_key_system, | 307 jstring j_key_system, |
| 295 jobject j_buffer) { | 308 jobject j_buffer) { |
| 296 std::string key_system = ConvertJavaStringToUTF8(env, j_key_system); | 309 std::string key_system = ConvertJavaStringToUTF8(env, j_key_system); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 315 const std::string& key_system, | 328 const std::string& key_system, |
| 316 const std::string& container_mime_type) { | 329 const std::string& container_mime_type) { |
| 317 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 330 DCHECK(!key_system.empty() && !container_mime_type.empty()); |
| 318 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); | 331 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); |
| 319 } | 332 } |
| 320 | 333 |
| 321 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { | 334 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { |
| 322 return RegisterNativesImpl(env); | 335 return RegisterNativesImpl(env); |
| 323 } | 336 } |
| 324 | 337 |
| 325 MediaDrmBridge::MediaDrmBridge(const std::vector<uint8>& scheme_uuid, | 338 MediaDrmBridge::MediaDrmBridge( |
| 326 const SessionCreatedCB& session_created_cb, | 339 const std::vector<uint8>& scheme_uuid, |
| 327 const SessionMessageCB& session_message_cb, | 340 const SessionMessageCB& session_message_cb, |
| 328 const SessionReadyCB& session_ready_cb, | 341 const SessionClosedCB& session_closed_cb, |
| 329 const SessionClosedCB& session_closed_cb, | 342 const SessionErrorCB& session_error_cb, |
| 330 const SessionErrorCB& session_error_cb) | 343 const SessionKeysChangeCB& session_keys_change_cb) |
| 331 : scheme_uuid_(scheme_uuid), | 344 : scheme_uuid_(scheme_uuid), |
| 332 session_created_cb_(session_created_cb), | |
| 333 session_message_cb_(session_message_cb), | 345 session_message_cb_(session_message_cb), |
| 334 session_ready_cb_(session_ready_cb), | |
| 335 session_closed_cb_(session_closed_cb), | 346 session_closed_cb_(session_closed_cb), |
| 336 session_error_cb_(session_error_cb) { | 347 session_error_cb_(session_error_cb), |
| 348 session_keys_change_cb_(session_keys_change_cb) { | |
| 337 JNIEnv* env = AttachCurrentThread(); | 349 JNIEnv* env = AttachCurrentThread(); |
| 338 CHECK(env); | 350 CHECK(env); |
| 339 | 351 |
| 340 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 352 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 341 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 353 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 342 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 354 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
| 343 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); | 355 env, j_scheme_uuid.obj(), reinterpret_cast<intptr_t>(this))); |
| 344 } | 356 } |
| 345 | 357 |
| 346 MediaDrmBridge::~MediaDrmBridge() { | 358 MediaDrmBridge::~MediaDrmBridge() { |
| 347 JNIEnv* env = AttachCurrentThread(); | 359 JNIEnv* env = AttachCurrentThread(); |
| 348 player_tracker_.NotifyCdmUnset(); | 360 player_tracker_.NotifyCdmUnset(); |
| 349 if (!j_media_drm_.is_null()) | 361 if (!j_media_drm_.is_null()) |
| 350 Java_MediaDrmBridge_release(env, j_media_drm_.obj()); | 362 Java_MediaDrmBridge_release(env, j_media_drm_.obj()); |
| 351 } | 363 } |
| 352 | 364 |
| 353 // static | 365 // static |
| 366 // TODO(xhwang): Enable SessionExpirationUpdateCB when it is supported. | |
| 354 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( | 367 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( |
| 355 const std::string& key_system, | 368 const std::string& key_system, |
| 356 const SessionCreatedCB& session_created_cb, | |
| 357 const SessionMessageCB& session_message_cb, | 369 const SessionMessageCB& session_message_cb, |
| 358 const SessionReadyCB& session_ready_cb, | |
| 359 const SessionClosedCB& session_closed_cb, | 370 const SessionClosedCB& session_closed_cb, |
| 360 const SessionErrorCB& session_error_cb) { | 371 const SessionErrorCB& session_error_cb, |
| 372 const SessionKeysChangeCB& session_keys_change_cb, | |
| 373 const SessionExpirationUpdateCB& /* session_expiration_update_cb */) { | |
| 361 scoped_ptr<MediaDrmBridge> media_drm_bridge; | 374 scoped_ptr<MediaDrmBridge> media_drm_bridge; |
| 362 if (!IsAvailable()) | 375 if (!IsAvailable()) |
| 363 return media_drm_bridge.Pass(); | 376 return media_drm_bridge.Pass(); |
| 364 | 377 |
| 365 UUID scheme_uuid = g_key_system_uuid_manager.Get().GetUUID(key_system); | 378 UUID scheme_uuid = g_key_system_uuid_manager.Get().GetUUID(key_system); |
| 366 if (scheme_uuid.empty()) | 379 if (scheme_uuid.empty()) |
| 367 return media_drm_bridge.Pass(); | 380 return media_drm_bridge.Pass(); |
| 368 | 381 |
| 369 media_drm_bridge.reset(new MediaDrmBridge(scheme_uuid, | 382 media_drm_bridge.reset(new MediaDrmBridge(scheme_uuid, session_message_cb, |
| 370 session_created_cb, | 383 session_closed_cb, session_error_cb, |
| 371 session_message_cb, | 384 session_keys_change_cb)); |
| 372 session_ready_cb, | |
| 373 session_closed_cb, | |
| 374 session_error_cb)); | |
| 375 | 385 |
| 376 if (media_drm_bridge->j_media_drm_.is_null()) | 386 if (media_drm_bridge->j_media_drm_.is_null()) |
| 377 media_drm_bridge.reset(); | 387 media_drm_bridge.reset(); |
| 378 | 388 |
| 379 return media_drm_bridge.Pass(); | 389 return media_drm_bridge.Pass(); |
| 380 } | 390 } |
| 381 | 391 |
| 382 // static | 392 // static |
| 383 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateSessionless( | 393 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( |
| 384 const std::string& key_system) { | 394 const std::string& key_system) { |
| 385 return MediaDrmBridge::Create(key_system, | 395 return MediaDrmBridge::Create( |
| 386 SessionCreatedCB(), | 396 key_system, SessionMessageCB(), SessionClosedCB(), SessionErrorCB(), |
| 387 SessionMessageCB(), | 397 SessionKeysChangeCB(), SessionExpirationUpdateCB()); |
| 388 SessionReadyCB(), | |
| 389 SessionClosedCB(), | |
| 390 SessionErrorCB()); | |
| 391 } | 398 } |
| 392 | 399 |
| 393 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { | 400 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { |
| 394 JNIEnv* env = AttachCurrentThread(); | 401 JNIEnv* env = AttachCurrentThread(); |
| 395 | 402 |
| 396 std::string security_level_str = GetSecurityLevelString(security_level); | 403 std::string security_level_str = GetSecurityLevelString(security_level); |
| 397 if (security_level_str.empty()) | 404 if (security_level_str.empty()) |
| 398 return false; | 405 return false; |
| 399 | 406 |
| 400 ScopedJavaLocalRef<jstring> j_security_level = | 407 ScopedJavaLocalRef<jstring> j_security_level = |
| 401 ConvertUTF8ToJavaString(env, security_level_str); | 408 ConvertUTF8ToJavaString(env, security_level_str); |
| 402 return Java_MediaDrmBridge_setSecurityLevel( | 409 return Java_MediaDrmBridge_setSecurityLevel( |
| 403 env, j_media_drm_.obj(), j_security_level.obj()); | 410 env, j_media_drm_.obj(), j_security_level.obj()); |
| 404 } | 411 } |
| 405 | 412 |
| 406 bool MediaDrmBridge::CreateSession(uint32 session_id, | 413 void MediaDrmBridge::SetServerCertificate( |
| 407 const std::string& content_type, | 414 const uint8* certificate_data, |
| 408 const uint8* init_data, | 415 int certificate_data_length, |
| 409 int init_data_length) { | 416 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 417 promise->reject(NOT_SUPPORTED_ERROR, 0, | |
| 418 "SetServerCertificate() is not supported."); | |
| 419 } | |
| 420 | |
| 421 void MediaDrmBridge::CreateSessionAndGenerateRequest( | |
| 422 SessionType session_type, | |
| 423 const std::string& init_data_type, | |
| 424 const uint8* init_data, | |
| 425 int init_data_length, | |
| 426 scoped_ptr<media::NewSessionCdmPromise> promise) { | |
| 410 DVLOG(1) << __FUNCTION__; | 427 DVLOG(1) << __FUNCTION__; |
| 411 | 428 |
| 412 DCHECK(!session_created_cb_.is_null()) | 429 if (session_type != media::MediaKeys::TEMPORARY_SESSION) { |
| 413 << "CreateSession called on a sessionless MediaDrmBridge object."; | 430 promise->reject(NOT_SUPPORTED_ERROR, 0, |
| 431 "Only the temporary session type is supported."); | |
| 432 return; | |
| 433 } | |
| 414 | 434 |
| 415 JNIEnv* env = AttachCurrentThread(); | 435 JNIEnv* env = AttachCurrentThread(); |
| 416 ScopedJavaLocalRef<jbyteArray> j_init_data; | 436 ScopedJavaLocalRef<jbyteArray> j_init_data; |
| 417 // Caller should always use "video/*" content types. | 437 // Caller should always use "video/*" content types. |
| 418 DCHECK_EQ(0u, content_type.find("video/")); | 438 DCHECK_EQ(0u, init_data_type.find("video/")); |
| 419 | 439 |
| 420 // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as | 440 // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as |
| 421 // the init data when using MP4 container. | 441 // the init data when using MP4 container. |
| 422 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && | 442 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && |
| 423 content_type == "video/mp4") { | 443 init_data_type == "video/mp4") { |
| 424 std::vector<uint8> pssh_data; | 444 std::vector<uint8> pssh_data; |
| 425 if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) | 445 if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) { |
| 426 return false; | 446 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid PSSH data."); |
| 447 return; | |
| 448 } | |
| 427 j_init_data = | 449 j_init_data = |
| 428 base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); | 450 base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); |
| 429 } else { | 451 } else { |
| 430 j_init_data = | 452 j_init_data = |
| 431 base::android::ToJavaByteArray(env, init_data, init_data_length); | 453 base::android::ToJavaByteArray(env, init_data, init_data_length); |
| 432 } | 454 } |
| 433 | 455 |
| 434 ScopedJavaLocalRef<jstring> j_mime = | 456 ScopedJavaLocalRef<jstring> j_mime = |
| 435 ConvertUTF8ToJavaString(env, content_type); | 457 ConvertUTF8ToJavaString(env, init_data_type); |
| 436 Java_MediaDrmBridge_createSession( | 458 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); |
| 437 env, j_media_drm_.obj(), session_id, j_init_data.obj(), j_mime.obj()); | 459 Java_MediaDrmBridge_createSession(env, j_media_drm_.obj(), j_init_data.obj(), |
| 438 return true; | 460 j_mime.obj(), promise_id); |
| 439 } | 461 } |
| 440 | 462 |
| 441 void MediaDrmBridge::LoadSession(uint32 session_id, | 463 void MediaDrmBridge::LoadSession( |
| 442 const std::string& web_session_id) { | 464 SessionType session_type, |
| 443 // MediaDrmBridge doesn't support loading sessions. | 465 const std::string& session_id, |
| 444 NOTREACHED(); | 466 scoped_ptr<media::NewSessionCdmPromise> promise) { |
| 467 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); | |
| 445 } | 468 } |
| 446 | 469 |
| 447 void MediaDrmBridge::UpdateSession(uint32 session_id, | 470 void MediaDrmBridge::UpdateSession( |
| 448 const uint8* response, | 471 const std::string& session_id, |
| 449 int response_length) { | 472 const uint8* response, |
| 473 int response_length, | |
| 474 scoped_ptr<media::SimpleCdmPromise> promise) { | |
| 450 DVLOG(1) << __FUNCTION__; | 475 DVLOG(1) << __FUNCTION__; |
| 451 | 476 |
| 452 DCHECK(!session_ready_cb_.is_null()) | |
| 453 << __FUNCTION__ << " called on a sessionless MediaDrmBridge object."; | |
| 454 | |
| 455 JNIEnv* env = AttachCurrentThread(); | 477 JNIEnv* env = AttachCurrentThread(); |
| 456 ScopedJavaLocalRef<jbyteArray> j_response = | 478 ScopedJavaLocalRef<jbyteArray> j_response = |
| 457 base::android::ToJavaByteArray(env, response, response_length); | 479 base::android::ToJavaByteArray(env, response, response_length); |
| 458 Java_MediaDrmBridge_updateSession( | 480 ScopedJavaLocalRef<jbyteArray> j_session_id = base::android::ToJavaByteArray( |
| 459 env, j_media_drm_.obj(), session_id, j_response.obj()); | 481 env, reinterpret_cast<const uint8_t*>(session_id.data()), |
| 482 session_id.size()); | |
| 483 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | |
| 484 Java_MediaDrmBridge_updateSession(env, j_media_drm_.obj(), j_session_id.obj(), | |
| 485 j_response.obj(), promise_id); | |
| 460 } | 486 } |
| 461 | 487 |
| 462 void MediaDrmBridge::ReleaseSession(uint32 session_id) { | 488 void MediaDrmBridge::CloseSession(const std::string& session_id, |
| 489 scoped_ptr<media::SimpleCdmPromise> promise) { | |
| 463 DVLOG(1) << __FUNCTION__; | 490 DVLOG(1) << __FUNCTION__; |
| 491 JNIEnv* env = AttachCurrentThread(); | |
| 492 ScopedJavaLocalRef<jbyteArray> j_session_id = base::android::ToJavaByteArray( | |
| 493 env, reinterpret_cast<const uint8_t*>(session_id.data()), | |
| 494 session_id.size()); | |
| 495 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | |
| 496 Java_MediaDrmBridge_closeSession(env, j_media_drm_.obj(), j_session_id.obj(), | |
| 497 promise_id); | |
| 498 } | |
| 464 | 499 |
| 465 DCHECK(!session_closed_cb_.is_null()) | 500 void MediaDrmBridge::RemoveSession( |
| 466 << __FUNCTION__ << " called on a sessionless MediaDrmBridge object."; | 501 const std::string& session_id, |
| 502 scoped_ptr<media::SimpleCdmPromise> promise) { | |
| 503 promise->reject(NOT_SUPPORTED_ERROR, 0, "RemoveSession() is not supported."); | |
| 504 } | |
| 467 | 505 |
| 468 JNIEnv* env = AttachCurrentThread(); | 506 CdmContext* MediaDrmBridge::GetCdmContext() { |
| 469 Java_MediaDrmBridge_releaseSession(env, j_media_drm_.obj(), session_id); | 507 NOTREACHED(); |
| 508 return nullptr; | |
| 470 } | 509 } |
| 471 | 510 |
| 472 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, | 511 int MediaDrmBridge::RegisterPlayer(const base::Closure& new_key_cb, |
| 473 const base::Closure& cdm_unset_cb) { | 512 const base::Closure& cdm_unset_cb) { |
| 474 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); | 513 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); |
| 475 } | 514 } |
| 476 | 515 |
| 477 void MediaDrmBridge::UnregisterPlayer(int registration_id) { | 516 void MediaDrmBridge::UnregisterPlayer(int registration_id) { |
| 478 player_tracker_.UnregisterPlayer(registration_id); | 517 player_tracker_.UnregisterPlayer(registration_id); |
| 479 } | 518 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 493 | 532 |
| 494 media_crypto_ready_cb_ = closure; | 533 media_crypto_ready_cb_ = closure; |
| 495 } | 534 } |
| 496 | 535 |
| 497 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { | 536 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) { |
| 498 DCHECK(!GetMediaCrypto().is_null()); | 537 DCHECK(!GetMediaCrypto().is_null()); |
| 499 if (!media_crypto_ready_cb_.is_null()) | 538 if (!media_crypto_ready_cb_.is_null()) |
| 500 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); | 539 base::ResetAndReturn(&media_crypto_ready_cb_).Run(); |
| 501 } | 540 } |
| 502 | 541 |
| 503 void MediaDrmBridge::OnSessionCreated(JNIEnv* env, | 542 void MediaDrmBridge::OnPromiseResolved(JNIEnv* env, |
| 504 jobject j_media_drm, | 543 jobject j_media_drm, |
| 505 jint j_session_id, | 544 jint j_promise_id) { |
| 506 jstring j_web_session_id) { | 545 cdm_promise_adapter_.ResolvePromise(j_promise_id); |
| 507 uint32 session_id = j_session_id; | 546 } |
| 508 std::string web_session_id = ConvertJavaStringToUTF8(env, j_web_session_id); | 547 |
| 509 session_created_cb_.Run(session_id, web_session_id); | 548 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env, |
| 549 jobject j_media_drm, | |
| 550 jint j_promise_id, | |
| 551 jbyteArray j_session_id) { | |
| 552 cdm_promise_adapter_.ResolvePromise(j_promise_id, | |
| 553 GetSessionId(env, j_session_id)); | |
| 554 } | |
| 555 | |
| 556 void MediaDrmBridge::OnPromiseRejected(JNIEnv* env, | |
| 557 jobject j_media_drm, | |
| 558 jint j_promise_id, | |
| 559 jstring j_error_message) { | |
| 560 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | |
| 561 cdm_promise_adapter_.RejectPromise(j_promise_id, MediaKeys::UNKNOWN_ERROR, 0, | |
| 562 error_message); | |
| 510 } | 563 } |
| 511 | 564 |
| 512 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, | 565 void MediaDrmBridge::OnSessionMessage(JNIEnv* env, |
| 513 jobject j_media_drm, | 566 jobject j_media_drm, |
| 514 jint j_session_id, | 567 jbyteArray j_session_id, |
| 515 jbyteArray j_message, | 568 jbyteArray j_message, |
| 516 jstring j_destination_url) { | 569 jstring j_legacy_destination_url) { |
| 517 uint32 session_id = j_session_id; | |
| 518 std::vector<uint8> message; | 570 std::vector<uint8> message; |
| 519 JavaByteArrayToByteVector(env, j_message, &message); | 571 JavaByteArrayToByteVector(env, j_message, &message); |
| 520 GURL destination_gurl = GURL(ConvertJavaStringToUTF8(env, j_destination_url)); | 572 GURL legacy_destination_url = |
| 521 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) { | 573 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); |
| 522 DLOG(WARNING) << "SessionMessage destination_url is invalid : " | 574 // Note: Message type is not supported in MediaDrm. Do our best guess here. |
| 523 << destination_gurl.possibly_invalid_spec(); | 575 media::MediaKeys::MessageType message_type = |
| 524 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 576 legacy_destination_url.is_empty() ? media::MediaKeys::LICENSE_REQUEST |
| 525 } | 577 : media::MediaKeys::LICENSE_RENEWAL; |
| 526 session_message_cb_.Run(session_id, message, destination_gurl); | |
| 527 } | |
| 528 | 578 |
| 529 void MediaDrmBridge::OnSessionReady(JNIEnv* env, | 579 session_message_cb_.Run(GetSessionId(env, j_session_id), message_type, |
| 530 jobject j_media_drm, | 580 message, legacy_destination_url); |
| 531 jint j_session_id) { | |
| 532 uint32 session_id = j_session_id; | |
| 533 session_ready_cb_.Run(session_id); | |
| 534 // TODO(xhwang/jrummell): Move this when usableKeyIds/keyschange are | |
| 535 // implemented. | |
| 536 player_tracker_.NotifyNewKey(); | |
| 537 } | 581 } |
| 538 | 582 |
| 539 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, | 583 void MediaDrmBridge::OnSessionClosed(JNIEnv* env, |
| 540 jobject j_media_drm, | 584 jobject j_media_drm, |
| 541 jint j_session_id) { | 585 jbyteArray j_session_id) { |
| 542 uint32 session_id = j_session_id; | 586 session_closed_cb_.Run(GetSessionId(env, j_session_id)); |
| 543 session_closed_cb_.Run(session_id); | |
| 544 } | 587 } |
| 545 | 588 |
| 546 void MediaDrmBridge::OnSessionError(JNIEnv* env, | 589 void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env, |
| 547 jobject j_media_drm, | 590 jobject j_media_drm, |
| 548 jint j_session_id) { | 591 jbyteArray j_session_id, |
| 549 uint32 session_id = j_session_id; | 592 bool has_additional_usable_key, |
| 550 session_error_cb_.Run(session_id, MediaKeys::kUnknownError, 0); | 593 jint j_key_status) { |
| 594 if (has_additional_usable_key) | |
| 595 player_tracker_.NotifyNewKey(); | |
| 596 | |
| 597 scoped_ptr<CdmKeyInformation> cdm_key_information(new CdmKeyInformation()); | |
| 598 cdm_key_information->key_id.assign(kDummyKeyId, | |
| 599 kDummyKeyId + sizeof(kDummyKeyId)); | |
| 600 cdm_key_information->status = | |
| 601 static_cast<CdmKeyInformation::KeyStatus>(j_key_status); | |
| 602 CdmKeysInfo cdm_keys_info; | |
| 603 cdm_keys_info.push_back(cdm_key_information.release()); | |
| 604 | |
| 605 session_keys_change_cb_.Run(GetSessionId(env, j_session_id), | |
| 606 has_additional_usable_key, cdm_keys_info.Pass()); | |
| 607 } | |
| 608 | |
| 609 void MediaDrmBridge::OnLegacySessionError(JNIEnv* env, | |
| 610 jobject j_media_drm, | |
| 611 jbyteArray j_session_id, | |
| 612 jstring j_error_message) { | |
| 613 std::string error_message = ConvertJavaStringToUTF8(env, j_error_message); | |
| 614 session_error_cb_.Run(GetSessionId(env, j_session_id), | |
| 615 MediaKeys::UNKNOWN_ERROR, 0, error_message); | |
| 551 } | 616 } |
| 552 | 617 |
| 553 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { | 618 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { |
| 554 JNIEnv* env = AttachCurrentThread(); | 619 JNIEnv* env = AttachCurrentThread(); |
| 555 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); | 620 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); |
| 556 } | 621 } |
| 557 | 622 |
| 558 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 623 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
| 559 JNIEnv* env = AttachCurrentThread(); | 624 JNIEnv* env = AttachCurrentThread(); |
| 560 ScopedJavaLocalRef<jstring> j_security_level = | 625 ScopedJavaLocalRef<jstring> j_security_level = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 575 JNIEnv* env = AttachCurrentThread(); | 640 JNIEnv* env = AttachCurrentThread(); |
| 576 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 641 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 577 } | 642 } |
| 578 | 643 |
| 579 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 644 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
| 580 JNIEnv* env, jobject, bool success) { | 645 JNIEnv* env, jobject, bool success) { |
| 581 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 646 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 582 } | 647 } |
| 583 | 648 |
| 584 } // namespace media | 649 } // namespace media |
| OLD | NEW |