Index: media/base/mime_util.cc |
diff --git a/media/base/mime_util.cc b/media/base/mime_util.cc |
index ff1d3369e1d6017a2274a0aeef4ef2d90f50d18f..05c821800352c9f14e779486af8f7985815ba37c 100644 |
--- a/media/base/mime_util.cc |
+++ b/media/base/mime_util.cc |
@@ -14,11 +14,13 @@ |
#include "base/strings/string_split.h" |
#include "base/strings/string_util.h" |
#include "build/build_config.h" |
+#include "media/base/media.h" |
#include "media/base/mime_util.h" |
#include "media/media_features.h" |
#if defined(OS_ANDROID) |
#include "base/android/build_info.h" |
+#include "media/base/android/media_codec_util.h" |
#endif |
namespace media { |
@@ -56,6 +58,7 @@ class MimeUtil { |
bool strip); |
SupportsType IsSupportedMediaFormat( |
+ bool is_encrypted, |
ddorwin
2016/02/16 20:34:37
nit: It seems odd that |is_encrypted| is the first
DaleCurtis
2016/02/17 03:01:05
Had to redo all of these changes after the split,
|
const std::string& mime_type, |
const std::vector<std::string>& codecs) const; |
@@ -79,14 +82,16 @@ class MimeUtil { |
// For faster lookup, keep hash sets. |
void InitializeMimeTypeMaps(); |
- // Returns IsSupported if all codec IDs in |codecs| are unambiguous |
- // and are supported by the platform. MayBeSupported is returned if |
- // at least one codec ID in |codecs| is ambiguous but all the codecs |
- // are supported by the platform. IsNotSupported is returned if at |
- // least one codec ID is not supported by the platform. |
- SupportsType AreSupportedCodecs( |
- const CodecSet& supported_codecs, |
- const std::vector<std::string>& codecs) const; |
+ // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are |
+ // supported by the platform when contained in |mime_type_lower_case|. |
ddorwin
2016/02/16 20:34:37
"platform" - This was the existing phrasing, but e
DaleCurtis
2016/02/17 03:01:05
Deleted platform from wording here.
|
+ // MayBeSupported is returned if at least one codec ID in |codecs| is |
+ // ambiguous but all the codecs are supported by the platform. IsNotSupported |
+ // is returned if at least one codec ID is not supported by the platform. |
ddorwin
2016/02/16 20:34:37
nit: two spaces
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ // |is_encrypted| means the codec will be used with encrypted samples. |
ddorwin
2016/02/16 20:34:37
nit: s/samples/blocks/?
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ SupportsType AreSupportedCodecs(bool is_encrypted, |
+ const std::string& mime_type_lower_case, |
+ const CodecSet& supported_codecs, |
+ const std::vector<std::string>& codecs) const; |
// Converts a codec ID into an Codec enum value and indicates |
// whether the conversion was ambiguous. |
@@ -100,10 +105,13 @@ class MimeUtil { |
Codec* codec, |
bool* is_ambiguous) const; |
- // Returns true if |codec| is supported by the platform. |
- // Note: This method will return false if the platform supports proprietary |
- // codecs but |allow_proprietary_codecs_| is set to false. |
- bool IsCodecSupported(Codec codec) const; |
+ // Returns true if |codec| and |mime_type_lower_case| are supported by the |
ddorwin
2016/02/16 20:34:37
Add "when contained in" as above?
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ // platform. Note: This method will return false if the platform supports |
ddorwin
2016/02/16 20:34:37
ditto for "platform"
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ // proprietary codecs but |allow_proprietary_codecs_| is set to false. |
+ // |is_encrypted| means the codec will be used with encrypted samples. |
ddorwin
2016/02/16 20:34:37
ditto for "samples"
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ bool IsCodecSupported(bool is_encrypted, |
+ const std::string& mime_type_lower_case, |
+ Codec codec) const; |
// Returns true if |codec| refers to a proprietary codec. |
bool IsCodecProprietary(Codec codec) const; |
@@ -116,7 +124,9 @@ class MimeUtil { |
// Returns true if |mime_type_lower_case| has a default codec associated with |
// it and IsCodecSupported() returns true for that particular codec. |
+ // |is_encrypted| means the codec will be used with encrypted samples. |
bool IsDefaultCodecSupportedLowerCase( |
+ bool is_encrypted, |
const std::string& mime_type_lower_case) const; |
// A map of mime_types and hash map of the supported codecs for the mime_type. |
@@ -137,7 +147,9 @@ static base::LazyInstance<MimeUtil>::Leaky g_media_mime_util = |
LAZY_INSTANCE_INITIALIZER; |
#if defined(OS_ANDROID) |
-static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { |
+static bool IsCodecSupportedOnAndroid(bool is_encrypted, |
+ const std::string& mime_type_lower_case, |
+ MimeUtil::Codec codec) { |
switch (codec) { |
case MimeUtil::INVALID_CODEC: |
return false; |
@@ -148,11 +160,26 @@ static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { |
case MimeUtil::MPEG4_AAC_SBR_v1: |
case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
case MimeUtil::VORBIS: |
+ return is_encrypted ? MediaCodecUtil::IsMediaCodecAvailable() : true; |
ddorwin
2016/02/16 20:34:37
Note: The !is_encrypted path works for MSE because
DaleCurtis
2016/02/17 03:01:05
As discussed via chat, added a comment above the s
|
+ |
case MimeUtil::H264_BASELINE: |
case MimeUtil::H264_MAIN: |
case MimeUtil::H264_HIGH: |
+ if (IsUnifiedMediaPipelineEnabled()) { |
+ return HasPlatformDecoderSupport() && |
ddorwin
2016/02/16 20:34:37
All HasPlatformDecoderSupport() means is that the
DaleCurtis
2016/02/17 03:01:05
It can mean: no gpu process, vda is blacklisted, o
ddorwin
2016/02/17 21:18:38
The MediaCodec check was added in the next patch s
|
+ MediaCodecUtil::IsMediaCodecAvailable(); |
+ } |
+ return is_encrypted ? MediaCodecUtil::IsMediaCodecAvailable() : true; |
ddorwin
2016/02/16 20:34:37
Why are encrypted videos not also subject to HasPl
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ |
case MimeUtil::VP8: |
- return true; |
+ if (!is_encrypted) |
ddorwin
2016/02/16 20:34:37
Doesn't encrypted require IsMediaCodecAvailable()
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ return true; |
+ |
+ if (MediaCodecUtil::IsVp8Blacklisted()) |
ddorwin
2016/02/16 20:34:37
Is VP8 blacklisted for Android MediaPlayer too?
I
DaleCurtis
2016/02/17 03:01:05
No it's only blacklisted for MediaCodec, I've clea
|
+ return false; |
+ |
+ return IsUnifiedMediaPipelineEnabled() ? HasPlatformDecoderSupport() |
ddorwin
2016/02/16 20:34:37
libvpx can't used for VP8?
DaleCurtis
2016/02/17 03:01:05
This was for encrypted cases, but is unclear, I've
|
+ : true; |
case MimeUtil::AC3: |
case MimeUtil::EAC3: |
@@ -162,12 +189,24 @@ static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { |
case MimeUtil::MPEG2_AAC_LC: |
case MimeUtil::MPEG2_AAC_MAIN: |
case MimeUtil::MPEG2_AAC_SSR: |
- // MPEG-2 variants of AAC are not supported on Android. |
- return false; |
+ // MPEG-2 variants of AAC are not supported on Android unless the unified |
+ // media pipeline can be used. |
ddorwin
2016/02/16 20:34:37
... and the software decoders...
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ return !is_encrypted && IsUnifiedMediaPipelineEnabled(); |
case MimeUtil::OPUS: |
- // Opus is supported only in Lollipop+ (API Level 21). |
- return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
+ if (!is_encrypted && IsUnifiedMediaPipelineEnabled()) |
+ return true; |
ddorwin
2016/02/16 20:34:37
Perhaps:
// Software decoder.
DaleCurtis
2016/02/17 03:01:05
Done.
|
+ |
+ if (!MediaCodecUtil::PlatformHasOpusSupport()) |
+ return false; |
+ |
+ // Android does not support opus in ogg containers. |
+ if (base::EndsWith(mime_type_lower_case, "ogg", |
+ base::CompareCase::SENSITIVE)) { |
+ return false; |
+ } |
+ |
+ return is_encrypted ? MediaCodecUtil::IsMediaCodecAvailable() : true; |
case MimeUtil::HEVC_MAIN: |
#if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
@@ -178,9 +217,22 @@ static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { |
return false; |
#endif |
- case MimeUtil::VP9: |
- // VP9 is supported only in KitKat+ (API Level 19). |
- return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
+ case MimeUtil::VP9: { |
+ const bool has_unified_media_pipeline = IsUnifiedMediaPipelineEnabled(); |
+ if (!is_encrypted && has_unified_media_pipeline) |
+ return true; |
+ |
+ if (!MediaCodecUtil::PlatformHasVp9Support()) |
+ return false; |
+ |
+ if (!is_encrypted) |
+ return true; |
+ |
+ if (!MediaCodecUtil::IsMediaCodecAvailable()) |
+ return false; |
+ |
+ return has_unified_media_pipeline ? HasPlatformDecoderSupport() : true; |
ddorwin
2016/02/16 20:34:37
Why is HasPlatformDecoderSupport() only required f
DaleCurtis
2016/02/17 03:01:05
Again this was confusing, though correct, simplifi
|
+ } |
case MimeUtil::THEORA: |
return false; |
@@ -254,16 +306,14 @@ static const MediaFormat kFormatCodecMappings[] = { |
{"audio/webm", COMMON, "opus,vorbis"}, |
{"audio/wav", COMMON, "1"}, |
{"audio/x-wav", COMMON, "1"}, |
-#if defined(OS_ANDROID) |
- // Android does not support Opus in Ogg container. |
- // Android does not support Theora and thus video/ogg. |
- {"audio/ogg", COMMON, "vorbis"}, |
- {"application/ogg", COMMON, "vorbis"}, |
-#else |
+#if !defined(OS_ANDROID) |
+ // Note: Android does not support Theora and thus video/ogg. |
{"video/ogg", COMMON, "opus,theora,vorbis"}, |
+#endif |
{"audio/ogg", COMMON, "opus,vorbis"}, |
+ // Note: Theora is not supported on Android and will be rejected during the |
+ // call to IsCodecSupportedOnAndroid(). |
{"application/ogg", COMMON, "opus,theora,vorbis"}, |
-#endif |
#if defined(USE_PROPRIETARY_CODECS) |
{"audio/mpeg", PROPRIETARY, "mp3"}, |
{"audio/mp3", PROPRIETARY, ""}, |
@@ -395,6 +445,8 @@ MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { |
} |
SupportsType MimeUtil::AreSupportedCodecs( |
+ bool is_encrypted, |
+ const std::string& mime_type_lower_case, |
const CodecSet& supported_codecs, |
const std::vector<std::string>& codecs) const { |
DCHECK(!supported_codecs.empty()); |
@@ -407,7 +459,7 @@ SupportsType MimeUtil::AreSupportedCodecs( |
if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) |
return IsNotSupported; |
- if (!IsCodecSupported(codec) || |
+ if (!IsCodecSupported(is_encrypted, mime_type_lower_case, codec) || |
supported_codecs.find(codec) == supported_codecs.end()) { |
return IsNotSupported; |
} |
@@ -484,6 +536,7 @@ void MimeUtil::ParseCodecString(const std::string& codecs, |
} |
SupportsType MimeUtil::IsSupportedMediaFormat( |
+ bool is_encrypted, |
const std::string& mime_type, |
const std::vector<std::string>& codecs) const { |
const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); |
@@ -494,8 +547,8 @@ SupportsType MimeUtil::IsSupportedMediaFormat( |
if (it_media_format_map->second.empty()) { |
// We get here if the mimetype does not expect a codecs parameter. |
- return (codecs.empty() && |
- IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) |
+ return (codecs.empty() && IsDefaultCodecSupportedLowerCase( |
+ is_encrypted, mime_type_lower_case)) |
? IsSupported |
: IsNotSupported; |
} |
@@ -509,7 +562,9 @@ SupportsType MimeUtil::IsSupportedMediaFormat( |
if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
return MayBeSupported; |
- return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported; |
+ return IsCodecSupported(is_encrypted, mime_type_lower_case, default_codec) |
+ ? IsSupported |
+ : IsNotSupported; |
} |
#if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
@@ -518,11 +573,13 @@ SupportsType MimeUtil::IsSupportedMediaFormat( |
for (const auto& codec_id : codecs) { |
codecs_to_check.push_back(TranslateLegacyAvc1CodecIds(codec_id)); |
} |
- return AreSupportedCodecs(it_media_format_map->second, codecs_to_check); |
+ return AreSupportedCodecs(is_encrypted, mime_type_lower_case, |
+ it_media_format_map->second, codecs_to_check); |
} |
#endif |
- return AreSupportedCodecs(it_media_format_map->second, codecs); |
+ return AreSupportedCodecs(is_encrypted, mime_type_lower_case, |
+ it_media_format_map->second, codecs); |
} |
void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
@@ -655,11 +712,13 @@ bool MimeUtil::StringToCodec(const std::string& codec_id, |
return ParseH264CodecID(codec_id, codec, is_ambiguous); |
} |
-bool MimeUtil::IsCodecSupported(Codec codec) const { |
+bool MimeUtil::IsCodecSupported(bool is_encrypted, |
+ const std::string& mime_type_lower_case, |
+ Codec codec) const { |
DCHECK_NE(codec, INVALID_CODEC); |
#if defined(OS_ANDROID) |
- if (!IsCodecSupportedOnAndroid(codec)) |
+ if (!IsCodecSupportedOnAndroid(is_encrypted, mime_type_lower_case, codec)) |
return false; |
#endif |
@@ -714,11 +773,12 @@ bool MimeUtil::GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, |
} |
bool MimeUtil::IsDefaultCodecSupportedLowerCase( |
+ bool is_encrypted, |
const std::string& mime_type_lower_case) const { |
Codec default_codec = Codec::INVALID_CODEC; |
if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
return false; |
- return IsCodecSupported(default_codec); |
+ return IsCodecSupported(is_encrypted, mime_type_lower_case, default_codec); |
} |
bool IsSupportedMediaMimeType(const std::string& mime_type) { |
@@ -727,7 +787,15 @@ bool IsSupportedMediaMimeType(const std::string& mime_type) { |
SupportsType IsSupportedMediaFormat(const std::string& mime_type, |
ddorwin
2016/02/16 20:34:37
To avoid misuse in the future, should we rename th
DaleCurtis
2016/02/17 03:01:05
Acknowledged.
|
const std::vector<std::string>& codecs) { |
- return g_media_mime_util.Get().IsSupportedMediaFormat(mime_type, codecs); |
+ return g_media_mime_util.Get().IsSupportedMediaFormat(false, mime_type, |
+ codecs); |
+} |
+ |
+SupportsType IsSupportedEncryptedMediaFormat( |
+ const std::string& mime_type, |
+ const std::vector<std::string>& codecs) { |
+ return g_media_mime_util.Get().IsSupportedMediaFormat(true, mime_type, |
+ codecs); |
} |
void ParseCodecString(const std::string& codecs, |