| Index: media/base/android/media_drm_bridge.cc
|
| diff --git a/media/base/android/media_drm_bridge.cc b/media/base/android/media_drm_bridge.cc
|
| index 14bdbda03f0ac81e2f32ea958d02103f3b91e3d1..288cc26ee0b4bed1d1d0f7eeb49f0e2be48a3b93 100644
|
| --- a/media/base/android/media_drm_bridge.cc
|
| +++ b/media/base/android/media_drm_bridge.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/android/build_info.h"
|
| #include "base/android/jni_array.h"
|
| #include "base/android/jni_string.h"
|
| +#include "base/bind.h"
|
| #include "base/callback_helpers.h"
|
| #include "base/containers/hash_tables.h"
|
| #include "base/lazy_instance.h"
|
| @@ -23,11 +24,23 @@
|
| #include "base/thread_task_runner_handle.h"
|
| #include "jni/MediaDrmBridge_jni.h"
|
| #include "media/base/android/media_client_android.h"
|
| +#include "media/base/android/media_codec_player.h" // for GetMediaTaskRunner()
|
| #include "media/base/android/media_drm_bridge_delegate.h"
|
| #include "media/base/cdm_key_information.h"
|
|
|
| #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
|
|
|
| +#define RUN_CB_ON_MEDIA_THREAD(CB, ...) \
|
| + do { \
|
| + if (run_on_media_thread_ && \
|
| + !GetMediaTaskRunner()->BelongsToCurrentThread()) { \
|
| + GetMediaTaskRunner()->PostTask(FROM_HERE, \
|
| + base::Bind(CB, ##__VA_ARGS__)); \
|
| + } else { \
|
| + CB.Run(__VA_ARGS__); \
|
| + } \
|
| + } while (0)
|
| +
|
| using base::android::AttachCurrentThread;
|
| using base::android::ConvertUTF8ToJavaString;
|
| using base::android::ConvertJavaStringToUTF8;
|
| @@ -228,6 +241,31 @@ bool MediaDrmBridge::IsAvailable() {
|
| return true;
|
| }
|
|
|
| +// static
|
| +bool MediaDrmBridge::CanCreate(const std::string& key_system,
|
| + SecurityLevel widevine_security_level) {
|
| + if (!IsAvailable()) {
|
| + DVLOG(1) << __FUNCTION__ << ": DRM is not available";
|
| + return false;
|
| + }
|
| +
|
| + UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system);
|
| + if (scheme_uuid.empty()) {
|
| + DVLOG(1) << __FUNCTION__ << ": key system " << key_system
|
| + << " not supported";
|
| + return false;
|
| + }
|
| +
|
| + if (key_system == kWidevineKeySystem &&
|
| + widevine_security_level != SECURITY_LEVEL_NONE &&
|
| + !std::equal(scheme_uuid.begin(), scheme_uuid.end(), kWidevineUuid)) {
|
| + NOTREACHED() << "Widevine security level " << widevine_security_level
|
| + << "used with another key system";
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| // TODO(ddorwin): This is specific to Widevine. http://crbug.com/459400
|
| // static
|
| bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) {
|
| @@ -254,6 +292,7 @@ bool MediaDrmBridge::IsKeySystemSupportedWithType(
|
| return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type);
|
| }
|
|
|
| +// static
|
| bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) {
|
| return RegisterNativesImpl(env);
|
| }
|
| @@ -270,7 +309,19 @@ MediaDrmBridge::MediaDrmBridge(
|
| session_closed_cb_(session_closed_cb),
|
| legacy_session_error_cb_(legacy_session_error_cb),
|
| session_keys_change_cb_(session_keys_change_cb),
|
| - session_expiration_update_cb_(session_expiration_update_cb) {
|
| + session_expiration_update_cb_(session_expiration_update_cb),
|
| + run_on_media_thread_(false) {
|
| + DVLOG(1) << "MediaDrmBridge::MediaDrmBridge";
|
| +
|
| + // When this flag is set we need to repost the notifications about
|
| + // crypto became ready and a key had been added to the Media thread.
|
| + run_on_media_thread_ = GetMediaTaskRunner()->BelongsToCurrentThread();
|
| +
|
| + // Create internal callbacks to repost Java notifications to the media thread.
|
| + // TODO(timav): weak pointers instead of unretained?
|
| + internal_keys_added_cb_ =
|
| + base::Bind(&MediaDrmBridge::InternalKeysAdded, base::Unretained(this));
|
| +
|
| JNIEnv* env = AttachCurrentThread();
|
| CHECK(env);
|
|
|
| @@ -288,14 +339,15 @@ MediaDrmBridge::~MediaDrmBridge() {
|
| }
|
|
|
| // static
|
| -scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create(
|
| +scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> MediaDrmBridge::Create(
|
| const std::string& key_system,
|
| + SecurityLevel widevine_security_level,
|
| const SessionMessageCB& session_message_cb,
|
| const SessionClosedCB& session_closed_cb,
|
| const LegacySessionErrorCB& legacy_session_error_cb,
|
| const SessionKeysChangeCB& session_keys_change_cb,
|
| const SessionExpirationUpdateCB& session_expiration_update_cb) {
|
| - scoped_ptr<MediaDrmBridge> media_drm_bridge;
|
| + scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge;
|
| if (!IsAvailable())
|
| return media_drm_bridge.Pass();
|
|
|
| @@ -311,15 +363,24 @@ scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create(
|
| if (media_drm_bridge->j_media_drm_.is_null())
|
| media_drm_bridge.reset();
|
|
|
| + if (key_system == kWidevineKeySystem &&
|
| + widevine_security_level != SECURITY_LEVEL_NONE &&
|
| + !media_drm_bridge->SetSecurityLevel(widevine_security_level)) {
|
| + DVLOG(1) << __FUNCTION__ << ": failed to set security level "
|
| + << widevine_security_level;
|
| + media_drm_bridge.reset();
|
| + }
|
| +
|
| return media_drm_bridge.Pass();
|
| }
|
|
|
| // static
|
| -scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport(
|
| - const std::string& key_system) {
|
| - return MediaDrmBridge::Create(
|
| - key_system, SessionMessageCB(), SessionClosedCB(), LegacySessionErrorCB(),
|
| - SessionKeysChangeCB(), SessionExpirationUpdateCB());
|
| +scoped_ptr<MediaDrmBridge, BrowserCdmDeleter>
|
| +MediaDrmBridge::CreateWithoutSessionSupport(const std::string& key_system) {
|
| + return MediaDrmBridge::Create(key_system, SECURITY_LEVEL_NONE,
|
| + SessionMessageCB(), SessionClosedCB(),
|
| + LegacySessionErrorCB(), SessionKeysChangeCB(),
|
| + SessionExpirationUpdateCB());
|
| }
|
|
|
| bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) {
|
| @@ -472,6 +533,8 @@ void MediaDrmBridge::UnregisterPlayer(int registration_id) {
|
| }
|
|
|
| void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure& closure) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| +
|
| if (closure.is_null()) {
|
| media_crypto_ready_cb_.Reset();
|
| return;
|
| @@ -487,15 +550,21 @@ void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure& closure) {
|
| media_crypto_ready_cb_ = closure;
|
| }
|
|
|
| -void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject) {
|
| +void MediaDrmBridge::OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| +
|
| DCHECK(!GetMediaCrypto().is_null());
|
| - if (!media_crypto_ready_cb_.is_null())
|
| - base::ResetAndReturn(&media_crypto_ready_cb_).Run();
|
| +
|
| + if (media_crypto_ready_cb_.is_null())
|
| + return;
|
| +
|
| + RUN_CB_ON_MEDIA_THREAD(base::ResetAndReturn(&media_crypto_ready_cb_));
|
| }
|
|
|
| void MediaDrmBridge::OnPromiseResolved(JNIEnv* env,
|
| jobject j_media_drm,
|
| jint j_promise_id) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| cdm_promise_adapter_.ResolvePromise(j_promise_id);
|
| }
|
|
|
| @@ -503,6 +572,7 @@ void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv* env,
|
| jobject j_media_drm,
|
| jint j_promise_id,
|
| jbyteArray j_session_id) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| cdm_promise_adapter_.ResolvePromise(j_promise_id,
|
| GetSessionId(env, j_session_id));
|
| }
|
| @@ -511,6 +581,7 @@ void MediaDrmBridge::OnPromiseRejected(JNIEnv* env,
|
| jobject j_media_drm,
|
| jint j_promise_id,
|
| jstring j_error_message) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| std::string error_message = ConvertJavaStringToUTF8(env, j_error_message);
|
| cdm_promise_adapter_.RejectPromise(j_promise_id, MediaKeys::UNKNOWN_ERROR, 0,
|
| error_message);
|
| @@ -522,6 +593,8 @@ void MediaDrmBridge::OnSessionMessage(JNIEnv* env,
|
| jint j_message_type,
|
| jbyteArray j_message,
|
| jstring j_legacy_destination_url) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| +
|
| std::vector<uint8> message;
|
| JavaByteArrayToByteVector(env, j_message, &message);
|
| GURL legacy_destination_url =
|
| @@ -536,6 +609,7 @@ void MediaDrmBridge::OnSessionMessage(JNIEnv* env,
|
| void MediaDrmBridge::OnSessionClosed(JNIEnv* env,
|
| jobject j_media_drm,
|
| jbyteArray j_session_id) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| session_closed_cb_.Run(GetSessionId(env, j_session_id));
|
| }
|
|
|
| @@ -544,8 +618,7 @@ void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env,
|
| jbyteArray j_session_id,
|
| jobjectArray j_keys_info,
|
| bool has_additional_usable_key) {
|
| - if (has_additional_usable_key)
|
| - player_tracker_.NotifyNewKey();
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
|
|
| CdmKeysInfo cdm_keys_info;
|
|
|
| @@ -579,10 +652,17 @@ void MediaDrmBridge::OnSessionKeysChange(JNIEnv* env,
|
| cdm_keys_info.push_back(cdm_key_information.release());
|
| }
|
|
|
| + RUN_CB_ON_MEDIA_THREAD(internal_keys_added_cb_, has_additional_usable_key);
|
| +
|
| session_keys_change_cb_.Run(GetSessionId(env, j_session_id),
|
| has_additional_usable_key, cdm_keys_info.Pass());
|
| }
|
|
|
| +void MediaDrmBridge::InternalKeysAdded(bool has_additional_usable_key) {
|
| + if (has_additional_usable_key)
|
| + player_tracker_.NotifyNewKey();
|
| +}
|
| +
|
| // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys
|
| // will never expire. This will be translated into a NULL base::Time() [2],
|
| // which will then be mapped to a zero Java time [3]. The zero Java time is
|
| @@ -607,6 +687,7 @@ void MediaDrmBridge::OnLegacySessionError(JNIEnv* env,
|
| jobject j_media_drm,
|
| jbyteArray j_session_id,
|
| jstring j_error_message) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| std::string error_message = ConvertJavaStringToUTF8(env, j_error_message);
|
| legacy_session_error_cb_.Run(GetSessionId(env, j_session_id),
|
| MediaKeys::UNKNOWN_ERROR, 0, error_message);
|
| @@ -645,6 +726,8 @@ void MediaDrmBridge::ResetDeviceCredentials(
|
|
|
| void MediaDrmBridge::OnResetDeviceCredentialsCompleted(
|
| JNIEnv* env, jobject, bool success) {
|
| + DVLOG(1) << "MediaDrmBridge::" << __FUNCTION__;
|
| +
|
| base::ResetAndReturn(&reset_credentials_cb_).Run(success);
|
| }
|
|
|
|
|