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
3 // found in the LICENSE file.
5 #include "media/base/android/media_drm_bridge.h"
9 #include "base/android/build_info.h"
10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h"
12 #include "base/callback_helpers.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/lazy_instance.h"
15 #include "base/location.h"
16 #include "base/logging.h"
17 #include "base/message_loop/message_loop_proxy.h"
18 #include "base/strings/string_util.h"
19 #include "base/sys_byteorder.h"
20 #include "base/sys_info.h"
21 #include "jni/MediaDrmBridge_jni.h"
22 #include "media/base/cdm_key_information.h"
24 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
26 using base::android::AttachCurrentThread
;
27 using base::android::ConvertUTF8ToJavaString
;
28 using base::android::ConvertJavaStringToUTF8
;
29 using base::android::JavaByteArrayToByteVector
;
30 using base::android::ScopedJavaLocalRef
;
36 // DrmBridge supports session expiration event but doesn't provide detailed
37 // status for each key ID, which is required by the EME spec. Use a dummy key ID
38 // here to report session expiration info.
39 const char kDummyKeyId
[] = "Dummy Key Id";
41 uint32
ReadUint32(const uint8_t* data
) {
43 for (int i
= 0; i
< 4; ++i
)
44 value
= (value
<< 8) | data
[i
];
48 uint64
ReadUint64(const uint8_t* data
) {
50 for (int i
= 0; i
< 8; ++i
)
51 value
= (value
<< 8) | data
[i
];
55 // Returns string session ID from jbyteArray (byte[] in Java).
56 std::string
GetSessionId(JNIEnv
* env
, jbyteArray j_session_id
) {
57 std::vector
<uint8
> session_id_vector
;
58 JavaByteArrayToByteVector(env
, j_session_id
, &session_id_vector
);
59 return std::string(session_id_vector
.begin(), session_id_vector
.end());
62 // The structure of an ISO CENC Protection System Specific Header (PSSH) box is
63 // as follows. (See ISO/IEC FDIS 23001-7:2011(E).)
64 // Note: ISO boxes use big-endian values.
69 // uint64 LargeSize # Field is only present if value(Size) == 1.
70 // uint32 VersionAndFlags
73 // uint8[DataSize] Data
75 const int kBoxHeaderSize
= 8; // Box's header contains Size and Type.
76 const int kBoxLargeSizeSize
= 8;
77 const int kPsshVersionFlagSize
= 4;
78 const int kPsshSystemIdSize
= 16;
79 const int kPsshDataSizeSize
= 4;
80 const uint32 kTencType
= 0x74656e63;
81 const uint32 kPsshType
= 0x70737368;
82 const uint8 kWidevineUuid
[16] = {
83 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
84 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
86 typedef std::vector
<uint8
> UUID
;
88 // Tries to find a PSSH box whose "SystemId" is |uuid| in |data|, parses the
89 // "Data" of the box and put it in |pssh_data|. Returns true if such a box is
90 // found and successfully parsed. Returns false otherwise.
92 // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box
93 // will be set in |pssh_data|.
94 // 2, Only PSSH and TENC boxes are allowed in |data|. TENC boxes are skipped.
95 bool GetPsshData(const uint8
* data
,
98 std::vector
<uint8
>* pssh_data
) {
99 const uint8
* cur
= data
;
100 const uint8
* data_end
= data
+ data_size
;
101 int bytes_left
= data_size
;
103 while (bytes_left
> 0) {
104 const uint8
* box_head
= cur
;
106 if (bytes_left
< kBoxHeaderSize
)
109 uint64_t box_size
= ReadUint32(cur
);
110 uint32 type
= ReadUint32(cur
+ 4);
111 cur
+= kBoxHeaderSize
;
112 bytes_left
-= kBoxHeaderSize
;
114 if (box_size
== 1) { // LargeSize is present.
115 if (bytes_left
< kBoxLargeSizeSize
)
118 box_size
= ReadUint64(cur
);
119 cur
+= kBoxLargeSizeSize
;
120 bytes_left
-= kBoxLargeSizeSize
;
121 } else if (box_size
== 0) {
122 box_size
= bytes_left
+ kBoxHeaderSize
;
125 const uint8
* box_end
= box_head
+ box_size
;
126 if (data_end
< box_end
)
129 if (type
== kTencType
) {
132 bytes_left
= data_end
- cur
;
134 } else if (type
!= kPsshType
) {
138 const int kPsshBoxMinimumSize
=
139 kPsshVersionFlagSize
+ kPsshSystemIdSize
+ kPsshDataSizeSize
;
140 if (box_end
< cur
+ kPsshBoxMinimumSize
)
143 uint32 version_and_flags
= ReadUint32(cur
);
144 cur
+= kPsshVersionFlagSize
;
145 bytes_left
-= kPsshVersionFlagSize
;
146 if (version_and_flags
!= 0)
149 DCHECK_GE(bytes_left
, kPsshSystemIdSize
);
150 if (!std::equal(uuid
.begin(), uuid
.end(), cur
)) {
152 bytes_left
= data_end
- cur
;
156 cur
+= kPsshSystemIdSize
;
157 bytes_left
-= kPsshSystemIdSize
;
159 uint32 data_size
= ReadUint32(cur
);
160 cur
+= kPsshDataSizeSize
;
161 bytes_left
-= kPsshDataSizeSize
;
163 if (box_end
< cur
+ data_size
)
166 pssh_data
->assign(cur
, cur
+ data_size
);
173 class KeySystemUuidManager
{
175 KeySystemUuidManager();
176 UUID
GetUUID(const std::string
& key_system
);
177 void AddMapping(const std::string
& key_system
, const UUID
& uuid
);
178 std::vector
<std::string
> GetPlatformKeySystemNames();
181 typedef base::hash_map
<std::string
, UUID
> KeySystemUuidMap
;
183 KeySystemUuidMap key_system_uuid_map_
;
185 DISALLOW_COPY_AND_ASSIGN(KeySystemUuidManager
);
188 KeySystemUuidManager::KeySystemUuidManager() {
189 // Widevine is always supported in Android.
190 key_system_uuid_map_
[kWidevineKeySystem
] =
191 UUID(kWidevineUuid
, kWidevineUuid
+ arraysize(kWidevineUuid
));
194 UUID
KeySystemUuidManager::GetUUID(const std::string
& key_system
) {
195 KeySystemUuidMap::iterator it
= key_system_uuid_map_
.find(key_system
);
196 if (it
== key_system_uuid_map_
.end())
201 void KeySystemUuidManager::AddMapping(const std::string
& key_system
,
203 KeySystemUuidMap::iterator it
= key_system_uuid_map_
.find(key_system
);
204 DCHECK(it
== key_system_uuid_map_
.end())
205 << "Shouldn't overwrite an existing key system.";
206 if (it
!= key_system_uuid_map_
.end())
208 key_system_uuid_map_
[key_system
] = uuid
;
211 std::vector
<std::string
> KeySystemUuidManager::GetPlatformKeySystemNames() {
212 std::vector
<std::string
> key_systems
;
213 for (KeySystemUuidMap::iterator it
= key_system_uuid_map_
.begin();
214 it
!= key_system_uuid_map_
.end(); ++it
) {
215 // Rule out the key system handled by Chrome explicitly.
216 if (it
->first
!= kWidevineKeySystem
)
217 key_systems
.push_back(it
->first
);
222 base::LazyInstance
<KeySystemUuidManager
>::Leaky g_key_system_uuid_manager
=
223 LAZY_INSTANCE_INITIALIZER
;
225 // Checks whether |key_system| is supported with |container_mime_type|. Only
226 // checks |key_system| support if |container_mime_type| is empty.
227 // TODO(xhwang): The |container_mime_type| is not the same as contentType in
228 // the EME spec. Revisit this once the spec issue with initData type is
230 bool IsKeySystemSupportedWithTypeImpl(const std::string
& key_system
,
231 const std::string
& container_mime_type
) {
232 if (!MediaDrmBridge::IsAvailable())
235 UUID scheme_uuid
= g_key_system_uuid_manager
.Get().GetUUID(key_system
);
236 if (scheme_uuid
.empty())
239 JNIEnv
* env
= AttachCurrentThread();
240 ScopedJavaLocalRef
<jbyteArray
> j_scheme_uuid
=
241 base::android::ToJavaByteArray(env
, &scheme_uuid
[0], scheme_uuid
.size());
242 ScopedJavaLocalRef
<jstring
> j_container_mime_type
=
243 ConvertUTF8ToJavaString(env
, container_mime_type
);
244 return Java_MediaDrmBridge_isCryptoSchemeSupported(
245 env
, j_scheme_uuid
.obj(), j_container_mime_type
.obj());
248 MediaDrmBridge::SecurityLevel
GetSecurityLevelFromString(
249 const std::string
& security_level_str
) {
250 if (0 == security_level_str
.compare("L1"))
251 return MediaDrmBridge::SECURITY_LEVEL_1
;
252 if (0 == security_level_str
.compare("L3"))
253 return MediaDrmBridge::SECURITY_LEVEL_3
;
254 DCHECK(security_level_str
.empty());
255 return MediaDrmBridge::SECURITY_LEVEL_NONE
;
258 std::string
GetSecurityLevelString(
259 MediaDrmBridge::SecurityLevel security_level
) {
260 switch (security_level
) {
261 case MediaDrmBridge::SECURITY_LEVEL_NONE
:
263 case MediaDrmBridge::SECURITY_LEVEL_1
:
265 case MediaDrmBridge::SECURITY_LEVEL_3
:
274 static void AddKeySystemUuidMapping(JNIEnv
* env
,
276 jstring j_key_system
,
278 std::string key_system
= ConvertJavaStringToUTF8(env
, j_key_system
);
279 uint8
* buffer
= static_cast<uint8
*>(env
->GetDirectBufferAddress(j_buffer
));
280 UUID
uuid(buffer
, buffer
+ 16);
281 g_key_system_uuid_manager
.Get().AddMapping(key_system
, uuid
);
285 bool MediaDrmBridge::IsAvailable() {
286 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19)
289 int32 os_major_version
= 0;
290 int32 os_minor_version
= 0;
291 int32 os_bugfix_version
= 0;
292 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version
,
295 if (os_major_version
== 4 && os_minor_version
== 4 && os_bugfix_version
== 0)
302 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level
) {
303 DCHECK(IsAvailable());
304 return SECURITY_LEVEL_1
== security_level
;
308 bool MediaDrmBridge::IsSecurityLevelSupported(const std::string
& key_system
,
309 SecurityLevel security_level
) {
313 scoped_ptr
<MediaDrmBridge
> media_drm_bridge
=
314 MediaDrmBridge::CreateWithoutSessionSupport(key_system
);
315 if (!media_drm_bridge
)
318 return media_drm_bridge
->SetSecurityLevel(security_level
);
322 std::vector
<std::string
> MediaDrmBridge::GetPlatformKeySystemNames() {
323 return g_key_system_uuid_manager
.Get().GetPlatformKeySystemNames();
327 bool MediaDrmBridge::IsKeySystemSupported(const std::string
& key_system
) {
328 DCHECK(!key_system
.empty());
329 return IsKeySystemSupportedWithTypeImpl(key_system
, "");
333 bool MediaDrmBridge::IsKeySystemSupportedWithType(
334 const std::string
& key_system
,
335 const std::string
& container_mime_type
) {
336 DCHECK(!key_system
.empty() && !container_mime_type
.empty());
337 return IsKeySystemSupportedWithTypeImpl(key_system
, container_mime_type
);
340 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv
* env
) {
341 return RegisterNativesImpl(env
);
344 MediaDrmBridge::MediaDrmBridge(
345 const std::vector
<uint8
>& scheme_uuid
,
346 const SessionMessageCB
& session_message_cb
,
347 const SessionClosedCB
& session_closed_cb
,
348 const SessionErrorCB
& session_error_cb
,
349 const SessionKeysChangeCB
& session_keys_change_cb
)
350 : scheme_uuid_(scheme_uuid
),
351 session_message_cb_(session_message_cb
),
352 session_closed_cb_(session_closed_cb
),
353 session_error_cb_(session_error_cb
),
354 session_keys_change_cb_(session_keys_change_cb
) {
355 JNIEnv
* env
= AttachCurrentThread();
358 ScopedJavaLocalRef
<jbyteArray
> j_scheme_uuid
=
359 base::android::ToJavaByteArray(env
, &scheme_uuid
[0], scheme_uuid
.size());
360 j_media_drm_
.Reset(Java_MediaDrmBridge_create(
361 env
, j_scheme_uuid
.obj(), reinterpret_cast<intptr_t>(this)));
364 MediaDrmBridge::~MediaDrmBridge() {
365 JNIEnv
* env
= AttachCurrentThread();
366 player_tracker_
.NotifyCdmUnset();
367 if (!j_media_drm_
.is_null())
368 Java_MediaDrmBridge_release(env
, j_media_drm_
.obj());
372 // TODO(xhwang): Enable SessionExpirationUpdateCB when it is supported.
373 scoped_ptr
<MediaDrmBridge
> MediaDrmBridge::Create(
374 const std::string
& key_system
,
375 const SessionMessageCB
& session_message_cb
,
376 const SessionClosedCB
& session_closed_cb
,
377 const SessionErrorCB
& session_error_cb
,
378 const SessionKeysChangeCB
& session_keys_change_cb
,
379 const SessionExpirationUpdateCB
& /* session_expiration_update_cb */) {
380 scoped_ptr
<MediaDrmBridge
> media_drm_bridge
;
382 return media_drm_bridge
.Pass();
384 UUID scheme_uuid
= g_key_system_uuid_manager
.Get().GetUUID(key_system
);
385 if (scheme_uuid
.empty())
386 return media_drm_bridge
.Pass();
388 media_drm_bridge
.reset(new MediaDrmBridge(scheme_uuid
, session_message_cb
,
389 session_closed_cb
, session_error_cb
,
390 session_keys_change_cb
));
392 if (media_drm_bridge
->j_media_drm_
.is_null())
393 media_drm_bridge
.reset();
395 return media_drm_bridge
.Pass();
399 scoped_ptr
<MediaDrmBridge
> MediaDrmBridge::CreateWithoutSessionSupport(
400 const std::string
& key_system
) {
401 return MediaDrmBridge::Create(
402 key_system
, SessionMessageCB(), SessionClosedCB(), SessionErrorCB(),
403 SessionKeysChangeCB(), SessionExpirationUpdateCB());
406 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level
) {
407 JNIEnv
* env
= AttachCurrentThread();
409 std::string security_level_str
= GetSecurityLevelString(security_level
);
410 if (security_level_str
.empty())
413 ScopedJavaLocalRef
<jstring
> j_security_level
=
414 ConvertUTF8ToJavaString(env
, security_level_str
);
415 return Java_MediaDrmBridge_setSecurityLevel(
416 env
, j_media_drm_
.obj(), j_security_level
.obj());
419 void MediaDrmBridge::SetServerCertificate(
420 const uint8
* certificate_data
,
421 int certificate_data_length
,
422 scoped_ptr
<media::SimpleCdmPromise
> promise
) {
423 promise
->reject(NOT_SUPPORTED_ERROR
, 0,
424 "SetServerCertificate() is not supported.");
427 void MediaDrmBridge::CreateSessionAndGenerateRequest(
428 SessionType session_type
,
429 const std::string
& init_data_type
,
430 const uint8
* init_data
,
431 int init_data_length
,
432 scoped_ptr
<media::NewSessionCdmPromise
> promise
) {
433 DVLOG(1) << __FUNCTION__
;
435 if (session_type
!= media::MediaKeys::TEMPORARY_SESSION
) {
436 promise
->reject(NOT_SUPPORTED_ERROR
, 0,
437 "Only the temporary session type is supported.");
441 JNIEnv
* env
= AttachCurrentThread();
442 ScopedJavaLocalRef
<jbyteArray
> j_init_data
;
443 // Caller should always use "video/*" content types.
444 DCHECK_EQ(0u, init_data_type
.find("video/"));
446 // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as
447 // the init data when using MP4 container.
448 if (std::equal(scheme_uuid_
.begin(), scheme_uuid_
.end(), kWidevineUuid
) &&
449 init_data_type
== "video/mp4") {
450 std::vector
<uint8
> pssh_data
;
451 if (!GetPsshData(init_data
, init_data_length
, scheme_uuid_
, &pssh_data
)) {
452 promise
->reject(INVALID_ACCESS_ERROR
, 0, "Invalid PSSH data.");
456 base::android::ToJavaByteArray(env
, &pssh_data
[0], pssh_data
.size());
459 base::android::ToJavaByteArray(env
, init_data
, init_data_length
);
462 ScopedJavaLocalRef
<jstring
> j_mime
=
463 ConvertUTF8ToJavaString(env
, init_data_type
);
464 uint32_t promise_id
= cdm_promise_adapter_
.SavePromise(promise
.Pass());
465 Java_MediaDrmBridge_createSession(env
, j_media_drm_
.obj(), j_init_data
.obj(),
466 j_mime
.obj(), promise_id
);
469 void MediaDrmBridge::LoadSession(
470 SessionType session_type
,
471 const std::string
& session_id
,
472 scoped_ptr
<media::NewSessionCdmPromise
> promise
) {
473 promise
->reject(NOT_SUPPORTED_ERROR
, 0, "LoadSession() is not supported.");
476 void MediaDrmBridge::UpdateSession(
477 const std::string
& session_id
,
478 const uint8
* response
,
480 scoped_ptr
<media::SimpleCdmPromise
> promise
) {
481 DVLOG(1) << __FUNCTION__
;
483 JNIEnv
* env
= AttachCurrentThread();
484 ScopedJavaLocalRef
<jbyteArray
> j_response
=
485 base::android::ToJavaByteArray(env
, response
, response_length
);
486 ScopedJavaLocalRef
<jbyteArray
> j_session_id
= base::android::ToJavaByteArray(
487 env
, reinterpret_cast<const uint8_t*>(session_id
.data()),
489 uint32_t promise_id
= cdm_promise_adapter_
.SavePromise(promise
.Pass());
490 Java_MediaDrmBridge_updateSession(env
, j_media_drm_
.obj(), j_session_id
.obj(),
491 j_response
.obj(), promise_id
);
494 void MediaDrmBridge::CloseSession(const std::string
& session_id
,
495 scoped_ptr
<media::SimpleCdmPromise
> promise
) {
496 DVLOG(1) << __FUNCTION__
;
497 JNIEnv
* env
= AttachCurrentThread();
498 ScopedJavaLocalRef
<jbyteArray
> j_session_id
= base::android::ToJavaByteArray(
499 env
, reinterpret_cast<const uint8_t*>(session_id
.data()),
501 uint32_t promise_id
= cdm_promise_adapter_
.SavePromise(promise
.Pass());
502 Java_MediaDrmBridge_closeSession(env
, j_media_drm_
.obj(), j_session_id
.obj(),
506 void MediaDrmBridge::RemoveSession(
507 const std::string
& session_id
,
508 scoped_ptr
<media::SimpleCdmPromise
> promise
) {
509 promise
->reject(NOT_SUPPORTED_ERROR
, 0, "RemoveSession() is not supported.");
512 CdmContext
* MediaDrmBridge::GetCdmContext() {
517 int MediaDrmBridge::RegisterPlayer(const base::Closure
& new_key_cb
,
518 const base::Closure
& cdm_unset_cb
) {
519 return player_tracker_
.RegisterPlayer(new_key_cb
, cdm_unset_cb
);
522 void MediaDrmBridge::UnregisterPlayer(int registration_id
) {
523 player_tracker_
.UnregisterPlayer(registration_id
);
526 void MediaDrmBridge::SetMediaCryptoReadyCB(const base::Closure
& closure
) {
527 if (closure
.is_null()) {
528 media_crypto_ready_cb_
.Reset();
532 DCHECK(media_crypto_ready_cb_
.is_null());
534 if (!GetMediaCrypto().is_null()) {
535 base::MessageLoopProxy::current()->PostTask(FROM_HERE
, closure
);
539 media_crypto_ready_cb_
= closure
;
542 void MediaDrmBridge::OnMediaCryptoReady(JNIEnv
* env
, jobject
) {
543 DCHECK(!GetMediaCrypto().is_null());
544 if (!media_crypto_ready_cb_
.is_null())
545 base::ResetAndReturn(&media_crypto_ready_cb_
).Run();
548 void MediaDrmBridge::OnPromiseResolved(JNIEnv
* env
,
551 cdm_promise_adapter_
.ResolvePromise(j_promise_id
);
554 void MediaDrmBridge::OnPromiseResolvedWithSession(JNIEnv
* env
,
557 jbyteArray j_session_id
) {
558 cdm_promise_adapter_
.ResolvePromise(j_promise_id
,
559 GetSessionId(env
, j_session_id
));
562 void MediaDrmBridge::OnPromiseRejected(JNIEnv
* env
,
565 jstring j_error_message
) {
566 std::string error_message
= ConvertJavaStringToUTF8(env
, j_error_message
);
567 cdm_promise_adapter_
.RejectPromise(j_promise_id
, MediaKeys::UNKNOWN_ERROR
, 0,
571 void MediaDrmBridge::OnSessionMessage(JNIEnv
* env
,
573 jbyteArray j_session_id
,
574 jbyteArray j_message
,
575 jstring j_legacy_destination_url
) {
576 std::vector
<uint8
> message
;
577 JavaByteArrayToByteVector(env
, j_message
, &message
);
578 GURL legacy_destination_url
=
579 GURL(ConvertJavaStringToUTF8(env
, j_legacy_destination_url
));
580 // Note: Message type is not supported in MediaDrm. Do our best guess here.
581 media::MediaKeys::MessageType message_type
=
582 legacy_destination_url
.is_empty() ? media::MediaKeys::LICENSE_REQUEST
583 : media::MediaKeys::LICENSE_RENEWAL
;
585 session_message_cb_
.Run(GetSessionId(env
, j_session_id
), message_type
,
586 message
, legacy_destination_url
);
589 void MediaDrmBridge::OnSessionClosed(JNIEnv
* env
,
591 jbyteArray j_session_id
) {
592 session_closed_cb_
.Run(GetSessionId(env
, j_session_id
));
595 void MediaDrmBridge::OnSessionKeysChange(JNIEnv
* env
,
597 jbyteArray j_session_id
,
598 bool has_additional_usable_key
,
600 if (has_additional_usable_key
)
601 player_tracker_
.NotifyNewKey();
603 scoped_ptr
<CdmKeyInformation
> cdm_key_information(new CdmKeyInformation());
604 cdm_key_information
->key_id
.assign(kDummyKeyId
,
605 kDummyKeyId
+ sizeof(kDummyKeyId
));
606 cdm_key_information
->status
=
607 static_cast<CdmKeyInformation::KeyStatus
>(j_key_status
);
608 CdmKeysInfo cdm_keys_info
;
609 cdm_keys_info
.push_back(cdm_key_information
.release());
611 session_keys_change_cb_
.Run(GetSessionId(env
, j_session_id
),
612 has_additional_usable_key
, cdm_keys_info
.Pass());
615 void MediaDrmBridge::OnLegacySessionError(JNIEnv
* env
,
617 jbyteArray j_session_id
,
618 jstring j_error_message
) {
619 std::string error_message
= ConvertJavaStringToUTF8(env
, j_error_message
);
620 session_error_cb_
.Run(GetSessionId(env
, j_session_id
),
621 MediaKeys::UNKNOWN_ERROR
, 0, error_message
);
624 ScopedJavaLocalRef
<jobject
> MediaDrmBridge::GetMediaCrypto() {
625 JNIEnv
* env
= AttachCurrentThread();
626 return Java_MediaDrmBridge_getMediaCrypto(env
, j_media_drm_
.obj());
629 MediaDrmBridge::SecurityLevel
MediaDrmBridge::GetSecurityLevel() {
630 JNIEnv
* env
= AttachCurrentThread();
631 ScopedJavaLocalRef
<jstring
> j_security_level
=
632 Java_MediaDrmBridge_getSecurityLevel(env
, j_media_drm_
.obj());
633 std::string security_level_str
=
634 ConvertJavaStringToUTF8(env
, j_security_level
.obj());
635 return GetSecurityLevelFromString(security_level_str
);
638 bool MediaDrmBridge::IsProtectedSurfaceRequired() {
639 return IsSecureDecoderRequired(GetSecurityLevel());
642 void MediaDrmBridge::ResetDeviceCredentials(
643 const ResetCredentialsCB
& callback
) {
644 DCHECK(reset_credentials_cb_
.is_null());
645 reset_credentials_cb_
= callback
;
646 JNIEnv
* env
= AttachCurrentThread();
647 Java_MediaDrmBridge_resetDeviceCredentials(env
, j_media_drm_
.obj());
650 void MediaDrmBridge::OnResetDeviceCredentialsCompleted(
651 JNIEnv
* env
, jobject
, bool success
) {
652 base::ResetAndReturn(&reset_credentials_cb_
).Run(success
);