diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-09 00:19:12 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-09 00:19:12 +0000 |
commit | f6824cadc9cd083edd146120622e8e6184d105ef (patch) | |
tree | e76c052d9b45f21a056088eab79aa3f7c46ef9c7 /media/base | |
parent | 694ffab8fbe7a05c10d694a109fc430cfc3ba472 (diff) | |
download | chromium_src-f6824cadc9cd083edd146120622e8e6184d105ef.zip chromium_src-f6824cadc9cd083edd146120622e8e6184d105ef.tar.gz chromium_src-f6824cadc9cd083edd146120622e8e6184d105ef.tar.bz2 |
Encrypted Media: Check container mime type in MediaDrmBridge.
Android MediaDrm API supports container mime type check in
isCryptoSchemeSupported (UUID uuid, String mimeType):
http://developer.android.com/reference/android/media/MediaDrm.html#isCryptoSchemeSupported(java.util.UUID, java.lang.String)
This CL hook this API up in MediaDrmBridge.
Also, Chromium will always query the codec/container type it
is interested in (e.g. MP4 and WebM).
BUG=350481
Review URL: https://codereview.chromium.org/229203002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rw-r--r-- | media/base/android/java/src/org/chromium/media/MediaDrmBridge.java | 8 | ||||
-rw-r--r-- | media/base/android/media_drm_bridge.cc | 74 | ||||
-rw-r--r-- | media/base/android/media_drm_bridge.h | 8 | ||||
-rw-r--r-- | media/base/android/media_drm_bridge_unittest.cc | 36 |
4 files changed, 88 insertions, 38 deletions
diff --git a/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java b/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java index 2099dde..31e5055 100644 --- a/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java +++ b/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java @@ -254,7 +254,6 @@ class MediaDrmBridge { * Check whether the crypto scheme is supported for the given container. * If |containerMimeType| is an empty string, we just return whether * the crypto scheme is supported. - * TODO(xhwang): Implement container check. See: http://crbug.com/350481 * * @return true if the container and the crypto scheme is supported, or * false otherwise. @@ -262,7 +261,12 @@ class MediaDrmBridge { @CalledByNative private static boolean isCryptoSchemeSupported(byte[] schemeUUID, String containerMimeType) { UUID cryptoScheme = getUUIDFromBytes(schemeUUID); - return MediaDrm.isCryptoSchemeSupported(cryptoScheme); + + if (containerMimeType.isEmpty()) { + return MediaDrm.isCryptoSchemeSupported(cryptoScheme); + } + + return MediaDrm.isCryptoSchemeSupported(cryptoScheme, containerMimeType); } /** diff --git a/media/base/android/media_drm_bridge.cc b/media/base/android/media_drm_bridge.cc index 38584fb..dbcd187 100644 --- a/media/base/android/media_drm_bridge.cc +++ b/media/base/android/media_drm_bridge.cc @@ -4,6 +4,8 @@ #include "media/base/android/media_drm_bridge.h" +#include <algorithm> + #include "base/android/build_info.h" #include "base/android/jni_array.h" #include "base/android/jni_string.h" @@ -180,6 +182,30 @@ static std::string GetSecurityLevelString( return ""; } +// Checks whether |key_system| is supported with |container_mime_type|. Only +// checks |key_system| support if |container_mime_type| is empty. +// TODO(xhwang): The |container_mime_type| is not the same as contentType in +// the EME spec. Revisit this once the spec issue with initData type is +// resolved. +static bool IsKeySystemSupportedWithTypeImpl( + const std::string& key_system, + const std::string& container_mime_type) { + if (!MediaDrmBridge::IsAvailable()) + return false; + + std::vector<uint8> scheme_uuid = GetUUID(key_system); + if (scheme_uuid.empty()) + return false; + + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = + base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); + ScopedJavaLocalRef<jstring> j_container_mime_type = + ConvertUTF8ToJavaString(env, container_mime_type); + return Java_MediaDrmBridge_isCryptoSchemeSupported( + env, j_scheme_uuid.obj(), j_container_mime_type.obj()); +} + // static bool MediaDrmBridge::IsAvailable() { return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; @@ -208,23 +234,17 @@ bool MediaDrmBridge::IsSecurityLevelSupported(const std::string& key_system, } // static +bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { + DCHECK(!key_system.empty()); + return IsKeySystemSupportedWithTypeImpl(key_system, ""); +} + +// static bool MediaDrmBridge::IsKeySystemSupportedWithType( const std::string& key_system, const std::string& container_mime_type) { - if (!IsAvailable()) - return false; - - std::vector<uint8> scheme_uuid = GetUUID(key_system); - if (scheme_uuid.empty()) - return false; - - JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = - base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); - ScopedJavaLocalRef<jstring> j_container_mime_type = - ConvertUTF8ToJavaString(env, container_mime_type); - return Java_MediaDrmBridge_isCryptoSchemeSupported( - env, j_scheme_uuid.obj(), j_container_mime_type.obj()); + DCHECK(!key_system.empty() && !container_mime_type.empty()); + return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); } bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { @@ -292,17 +312,29 @@ bool MediaDrmBridge::CreateSession(uint32 session_id, const std::string& content_type, const uint8* init_data, int init_data_length) { - std::vector<uint8> pssh_data; - if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) - return false; - JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jbyteArray> j_pssh_data = - base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); + ScopedJavaLocalRef<jbyteArray> j_init_data; + // Caller should always use "video/*" content types. + DCHECK_EQ(0u, content_type.find("video/")); + + // Widevine MediaDrm plugin only accepts the "data" part of the PSSH box as + // the init data when using MP4 container. + if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && + content_type == "video/mp4") { + std::vector<uint8> pssh_data; + if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) + return false; + j_init_data = + base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); + } else { + j_init_data = + base::android::ToJavaByteArray(env, init_data, init_data_length); + } + ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, content_type); Java_MediaDrmBridge_createSession( - env, j_media_drm_.obj(), session_id, j_pssh_data.obj(), j_mime.obj()); + env, j_media_drm_.obj(), session_id, j_init_data.obj(), j_mime.obj()); return true; } diff --git a/media/base/android/media_drm_bridge.h b/media/base/android/media_drm_bridge.h index 07e6b61..f34bbc4 100644 --- a/media/base/android/media_drm_bridge.h +++ b/media/base/android/media_drm_bridge.h @@ -44,9 +44,11 @@ class MEDIA_EXPORT MediaDrmBridge : public MediaKeys { static bool IsSecurityLevelSupported(const std::string& key_system, SecurityLevel security_level); - // TODO(xhwang): The |container_mime_type| is not the same as contentType in - // the EME spec. Revisit this once the spec issue with initData type is - // resolved. + // Checks whether |key_system| is supported. + static bool IsKeySystemSupported(const std::string& key_system); + + // Checks whether |key_system| is supported with |container_mime_type|. + // |container_mime_type| must not be empty. static bool IsKeySystemSupportedWithType( const std::string& key_system, const std::string& container_mime_type); diff --git a/media/base/android/media_drm_bridge_unittest.cc b/media/base/android/media_drm_bridge_unittest.cc index fdf5350..a838203 100644 --- a/media/base/android/media_drm_bridge_unittest.cc +++ b/media/base/android/media_drm_bridge_unittest.cc @@ -31,6 +31,12 @@ const MediaDrmBridge::SecurityLevel kLNone = const MediaDrmBridge::SecurityLevel kL1 = MediaDrmBridge::SECURITY_LEVEL_1; const MediaDrmBridge::SecurityLevel kL3 = MediaDrmBridge::SECURITY_LEVEL_3; +// Helper functions to avoid typing "MediaDrmBridge::" in tests. + +static bool IsKeySystemSupported(const std::string& key_system) { + return MediaDrmBridge::IsKeySystemSupported(key_system); +} + static bool IsKeySystemSupportedWithType( const std::string& key_system, const std::string& container_mime_type) { @@ -59,26 +65,32 @@ TEST(MediaDrmBridgeTest, IsSecurityLevelSupported_InvalidKeySystem) { EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL3)); } -TEST(MediaDrmBridgeTest, IsTypeSupported_Widevine) { - EXPECT_TRUE_IF_AVAILABLE( - IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4)); +TEST(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) { + EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem)); + + // TODO(xhwang): Enable when b/13564917 is fixed. + // EXPECT_TRUE_IF_AVAILABLE( + // IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4)); EXPECT_TRUE_IF_AVAILABLE( IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoMp4)); - // TODO(xhwang): MediaDrmBridge.IsKeySystemSupportedWithType() doesn't check - // the container type. Fix IsKeySystemSupportedWithType() and update this test - // as necessary. See: http://crbug.com/350481 - EXPECT_TRUE_IF_AVAILABLE( - IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); - EXPECT_TRUE_IF_AVAILABLE( - IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); + EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); + EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); + EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "unknown")); + EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "video/avi")); + EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "audio/mp3")); } // Invalid keysytem is NOT supported regardless whether MediaDrm is available. -TEST(MediaDrmBridgeTest, IsTypeSupported_InvalidKeySystem) { - EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "")); +TEST(MediaDrmBridgeTest, IsKeySystemSupported_InvalidKeySystem) { + EXPECT_FALSE(IsKeySystemSupported(kInvalidKeySystem)); + EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioMp4)); EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4)); + EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM)); EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM)); + EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown")); + EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi")); + EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3")); } } // namespace media |