Index: media/base/mime_util.cc |
diff --git a/media/base/mime_util.cc b/media/base/mime_util.cc |
index ff1d3369e1d6017a2274a0aeef4ef2d90f50d18f..8d45ded5e323fc7c3b08d1bac3ffd4f59822f533 100644 |
--- a/media/base/mime_util.cc |
+++ b/media/base/mime_util.cc |
@@ -15,6 +15,7 @@ |
#include "base/strings/string_util.h" |
#include "build/build_config.h" |
#include "media/base/mime_util.h" |
+#include "media/base/video_codecs.h" |
#include "media/media_features.h" |
#if defined(OS_ANDROID) |
@@ -40,9 +41,7 @@ class MimeUtil { |
MPEG4_AAC_SBR_PS_v2, |
VORBIS, |
OPUS, |
- H264_BASELINE, |
- H264_MAIN, |
- H264_HIGH, |
+ H264, |
HEVC_MAIN, |
ddorwin
2016/02/17 19:31:20
Should we remove _MAIN here too?
servolk
2016/02/17 19:49:54
Yes, I'm planning to do that in a separate CL whic
|
VP8, |
VP9, |
@@ -148,9 +147,7 @@ static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { |
case MimeUtil::MPEG4_AAC_SBR_v1: |
case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
case MimeUtil::VORBIS: |
- case MimeUtil::H264_BASELINE: |
- case MimeUtil::H264_MAIN: |
- case MimeUtil::H264_HIGH: |
+ case MimeUtil::H264: |
case MimeUtil::VP8: |
return true; |
@@ -295,7 +292,7 @@ struct CodecIDMappings { |
// The "mp4a" strings come from RFC 6381. |
static const CodecIDMappings kUnambiguousCodecStringMap[] = { |
{"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. |
- // avc1/avc3.XXXXXX may be unambiguous; handled by ParseH264CodecID(). |
+ // avc1/avc3.XXXXXX may be unambiguous; handled by ParseAVCCodecId(). |
// hev1/hvc1.XXXXXX may be unambiguous; handled by ParseHEVCCodecID(). |
{"mp3", MimeUtil::MP3}, |
{"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
@@ -336,9 +333,9 @@ static const CodecIDMappings kUnambiguousCodecStringMap[] = { |
// we assume the user is trying to indicate. |
static const CodecIDMappings kAmbiguousCodecStringMap[] = { |
{"mp4a.40", MimeUtil::MPEG4_AAC_LC}, |
- {"avc1", MimeUtil::H264_BASELINE}, |
- {"avc3", MimeUtil::H264_BASELINE}, |
- // avc1/avc3.XXXXXX may be ambiguous; handled by ParseH264CodecID(). |
+ {"avc1", MimeUtil::H264}, |
+ {"avc3", MimeUtil::H264}, |
+ // avc1/avc3.XXXXXX may be ambiguous; handled by ParseAVCCodecId(). |
}; |
#if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
@@ -532,69 +529,15 @@ void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
allow_proprietary_codecs_ = false; |
} |
-static bool IsValidH264Level(const std::string& level_str) { |
- uint32_t level; |
- if (level_str.size() != 2 || !base::HexStringToUInt(level_str, &level)) |
- return false; |
- |
- // Valid levels taken from Table A-1 in ISO-14496-10. |
- // Essentially |level_str| is toHex(10 * level). |
- return ((level >= 10 && level <= 13) || |
- (level >= 20 && level <= 22) || |
- (level >= 30 && level <= 32) || |
- (level >= 40 && level <= 42) || |
- (level >= 50 && level <= 51)); |
-} |
- |
-// Handle parsing H.264 codec IDs as outlined in RFC 6381 and ISO-14496-10. |
-// avc1.42x0yy - H.264 Baseline |
-// avc1.4Dx0yy - H.264 Main |
-// avc1.64x0yy - H.264 High |
-// |
-// avc1.xxxxxx & avc3.xxxxxx are considered ambiguous forms that are trying to |
-// signal H.264 Baseline. For example, the idc_level, profile_idc and |
-// constraint_set3_flag pieces may explicitly require decoder to conform to |
-// baseline profile at the specified level (see Annex A and constraint_set0 in |
-// ISO-14496-10). |
-static bool ParseH264CodecID(const std::string& codec_id, |
- MimeUtil::Codec* codec, |
- bool* is_ambiguous) { |
- // Make sure we have avc1.xxxxxx or avc3.xxxxxx , where xxxxxx are hex digits |
- if (!base::StartsWith(codec_id, "avc1.", base::CompareCase::SENSITIVE) && |
- !base::StartsWith(codec_id, "avc3.", base::CompareCase::SENSITIVE)) { |
- return false; |
- } |
- if (codec_id.size() != 11 || |
- !base::IsHexDigit(codec_id[5]) || !base::IsHexDigit(codec_id[6]) || |
- !base::IsHexDigit(codec_id[7]) || !base::IsHexDigit(codec_id[8]) || |
- !base::IsHexDigit(codec_id[9]) || !base::IsHexDigit(codec_id[10])) { |
- return false; |
- } |
- |
- // Validate constraint flags and reserved bits. |
- if (!base::IsHexDigit(codec_id[7]) || codec_id[8] != '0') { |
- *codec = MimeUtil::H264_BASELINE; |
- *is_ambiguous = true; |
- return true; |
- } |
- |
- // Extract the profile. |
- std::string profile = base::ToUpperASCII(codec_id.substr(5, 2)); |
- if (profile == "42") { |
- *codec = MimeUtil::H264_BASELINE; |
- } else if (profile == "4D") { |
- *codec = MimeUtil::H264_MAIN; |
- } else if (profile == "64") { |
- *codec = MimeUtil::H264_HIGH; |
- } else { |
- *codec = MimeUtil::H264_BASELINE; |
- *is_ambiguous = true; |
- return true; |
- } |
- |
- // Validate level. |
- *is_ambiguous = !IsValidH264Level(codec_id.substr(9)); |
- return true; |
+static bool IsValidH264Level(uint8_t level_idc) { |
+ // Valid levels taken from Table A-1 in ISO/IEC 14496-10. |
+ // Level_idc represents the standard level represented as decimal number |
+ // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2 |
+ return ((level_idc >= 10 && level_idc <= 13) || |
+ (level_idc >= 20 && level_idc <= 22) || |
+ (level_idc >= 30 && level_idc <= 32) || |
+ (level_idc >= 40 && level_idc <= 42) || |
+ (level_idc >= 50 && level_idc <= 51)); |
} |
#if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
@@ -652,7 +595,20 @@ bool MimeUtil::StringToCodec(const std::string& codec_id, |
return true; |
} |
#endif |
- return ParseH264CodecID(codec_id, codec, is_ambiguous); |
+ |
+ VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
+ uint8_t level_idc = 0; |
+ if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { |
+ *codec = MimeUtil::H264; |
+ *is_ambiguous = |
+ (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && |
+ profile != H264PROFILE_HIGH) || |
+ !IsValidH264Level(level_idc); |
+ return true; |
+ } |
+ |
+ DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; |
+ return false; |
} |
bool MimeUtil::IsCodecSupported(Codec codec) const { |
@@ -678,9 +634,7 @@ bool MimeUtil::IsCodecProprietary(Codec codec) const { |
case MPEG4_AAC_LC: |
case MPEG4_AAC_SBR_v1: |
case MPEG4_AAC_SBR_PS_v2: |
- case H264_BASELINE: |
- case H264_MAIN: |
- case H264_HIGH: |
+ case H264: |
case HEVC_MAIN: |
return true; |