Index: media/base/mime_util_internal.cc |
diff --git a/media/base/mime_util_internal.cc b/media/base/mime_util_internal.cc |
index 9b9471c4347345a07fdb83ca527e027794c416b6..f07d3f807a45b8fec6c9163bd3afc29c578fc77c 100644 |
--- a/media/base/mime_util_internal.cc |
+++ b/media/base/mime_util_internal.cc |
@@ -408,6 +408,70 @@ void MimeUtil::SplitCodecsToVector(const std::string& codecs, |
} |
} |
+bool MimeUtil::ParseVideoCodecString(const std::string& mime_type, |
+ const std::string& codec_id, |
+ bool* out_is_ambiguous, |
+ VideoCodec* out_codec, |
+ VideoCodecProfile* out_profile, |
+ uint8_t* out_level, |
+ VideoColorSpace* out_colorspace) { |
+ DCHECK(out_is_ambiguous); |
+ DCHECK(out_codec); |
+ DCHECK(out_profile); |
+ DCHECK(out_level); |
+ DCHECK(out_colorspace); |
+ |
+ Codec mime_internal_codec; |
+ bool parsed_ok = ParseCodecString(base::ToLowerASCII(mime_type), codec_id, |
+ &mime_internal_codec, out_is_ambiguous, |
+ out_profile, out_level, out_colorspace); |
+ if (!parsed_ok) |
+ return false; |
+ |
+ *out_codec = MimeUtilToVideoCodec(mime_internal_codec); |
+ if (*out_codec == kUnknownVideoCodec) |
+ return false; |
+ |
+ return true; |
+} |
+ |
+bool MimeUtil::ParseAudioCodecString(const std::string& mime_type, |
+ const std::string& codec_id, |
+ bool* out_is_ambiguous, |
+ AudioCodec* out_codec) { |
+ DCHECK(out_is_ambiguous); |
+ DCHECK(out_codec); |
+ |
+ Codec mime_internal_codec; |
+ |
+ // Some audio containers unambiguously imply a codec. |
+ if (codec_id.empty()) { |
+ if (!GetDefaultCodec(mime_type, &mime_internal_codec)) |
+ return false; |
+ |
+ *out_is_ambiguous = false; |
+ } else { |
+ // Not part of audio parsing, but its possible users will mistakenly put |
tguilbert
2017/05/08 23:19:57
Pure curiosity and not a CL comment: why do we han
|
+ // video codecs in the audio config string, causing the common parsing algo |
+ // to set these output values. Passing non-null values avoids issues. |
+ VideoCodecProfile out_profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
+ uint8_t out_level = 0; |
+ VideoColorSpace out_colorspace; |
+ |
+ if (!ParseCodecString(base::ToLowerASCII(mime_type), codec_id, |
+ &mime_internal_codec, out_is_ambiguous, &out_profile, |
+ &out_level, &out_colorspace)) { |
+ return false; |
+ } |
+ } |
+ |
+ *out_codec = MimeUtilToAudioCodec(mime_internal_codec); |
+ if (*out_codec == kUnknownAudioCodec) |
+ return false; |
+ |
+ return true; |
+} |
+ |
SupportsType MimeUtil::IsSupportedMediaFormat( |
const std::string& mime_type, |
const std::vector<std::string>& codecs, |
@@ -814,6 +878,9 @@ bool MimeUtil::IsCodecProprietary(Codec codec) const { |
bool MimeUtil::GetDefaultCodec(const std::string& mime_type, |
Codec* default_codec) const { |
+ // Codecs below are unambiguously implied by the mime type string. DO NOT add |
+ // default codecs for ambiguous mime types. |
+ |
if (mime_type == "audio/mpeg" || mime_type == "audio/mp3" || |
mime_type == "audio/x-mp3") { |
*default_codec = MimeUtil::MP3; |