Chromium Code Reviews| Index: net/base/mime_util.cc |
| diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
| index f1d44870e47fbef8e205f4debfec8ecf09d629a8..a432877aa94b6ab4193e006481fbae31f1181328 100644 |
| --- a/net/base/mime_util.cc |
| +++ b/net/base/mime_util.cc |
| @@ -7,6 +7,7 @@ |
| #include <map> |
| #include <string> |
| +#include "base/bind.h" |
| #include "base/containers/hash_tables.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| @@ -30,26 +31,6 @@ namespace net { |
| // Singleton utility class for mime types. |
| class MimeUtil : public PlatformMimeUtil { |
| public: |
| - enum Codec { |
| - INVALID_CODEC, |
| - PCM, |
| - MP3, |
| - MPEG2_AAC_LC, |
| - MPEG2_AAC_MAIN, |
| - MPEG2_AAC_SSR, |
| - MPEG4_AAC_LC, |
| - MPEG4_AAC_SBR_v1, |
| - MPEG4_AAC_SBR_PS_v2, |
| - VORBIS, |
| - OPUS, |
| - H264_BASELINE, |
| - H264_MAIN, |
| - H264_HIGH, |
| - VP8, |
| - VP9, |
| - THEORA |
| - }; |
| - |
| bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| std::string* mime_type) const; |
| @@ -89,20 +70,25 @@ class MimeUtil : public PlatformMimeUtil { |
| void RemoveProprietaryMediaTypesAndCodecsForTests(); |
| + // Returns true if the given |codec_id|, identified by a codec id string |
| + // described in RFC 6381, is supported. Returns false if the codec id is not |
| + // recognized or if that codec is not supported. |
| + // Note: This method will return false if the platform supports proprietary |
| + // codecs but |allow_proprietary_codecs_| is set to false. |
| + bool IsCodecSupported(const std::string& codec) const; |
| + |
| + bool DefaultIsCodecSupported(const std::string& codec) const; |
| + |
| + typedef base::Callback<bool(const std::string&)> IsCodecSupportedCB; |
|
Ryan Sleevi
2015/04/21 13:23:29
This seems like a silly typedef duplication (you c
servolk
2015/04/21 22:09:02
This typedef is redundant indeed, so I've removed
Ryan Sleevi
2015/04/22 12:59:57
We intentionally keep the style guide light - we u
|
| + void SetIsCodecSupportedCB(IsCodecSupportedCB is_codec_supported_cb); |
|
Ryan Sleevi
2015/04/21 13:23:29
Same remarks re-const-ref.
servolk
2015/04/21 22:09:02
Done.
|
| + |
| private: |
| friend struct base::DefaultLazyInstanceTraits<MimeUtil>; |
| typedef base::hash_set<std::string> MimeMappings; |
| - typedef base::hash_set<int> CodecSet; |
| + typedef std::vector<std::string> CodecSet; |
| typedef std::map<std::string, CodecSet> StrictMappings; |
| - struct CodecEntry { |
| - CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} |
| - CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} |
| - Codec codec; |
| - bool is_ambiguous; |
| - }; |
| - typedef std::map<std::string, CodecEntry> StringToCodecMappings; |
| MimeUtil(); |
| @@ -122,36 +108,17 @@ class MimeUtil : public PlatformMimeUtil { |
| bool include_platform_types, |
| std::string* mime_type) const; |
| - // Converts a codec ID into an Codec enum value and indicates |
| - // whether the conversion was ambiguous. |
| - // Returns true if this method was able to map |codec_id| to a specific |
| - // Codec enum value. |codec| and |is_ambiguous| are only valid if true |
| - // is returned. Otherwise their value is undefined after the call. |
| - // |is_ambiguous| is true if |codec_id| did not have enough information to |
| - // unambiguously determine the proper Codec enum value. If |is_ambiguous| |
| - // is true |codec| contains the best guess for the intended Codec enum value. |
| - bool StringToCodec(const std::string& codec_id, |
| - 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| refers to a proprietary codec. |
| - bool IsCodecProprietary(Codec codec) const; |
| + bool IsCodecProprietary(const std::string& codec) const; |
| + |
| + // Returns true if |codec| is an ambiguous codec id. |
| + bool IsCodecAmbiguous(const std::string& codec) const; |
| // Returns true and sets |*default_codec| if |mime_type| has a default codec |
| // associated with it. Returns false otherwise and the value of |
| // |*default_codec| is undefined. |
| bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, |
| - Codec* default_codec) const; |
| - |
| - // Returns true if |mime_type_lower_case| has a default codec associated with |
| - // it and IsCodecSupported() returns true for that particular codec. |
| - bool IsDefaultCodecSupportedLowerCase( |
| - const std::string& mime_type_lower_case) const; |
| + std::string* default_codec) const; |
| MimeMappings image_map_; |
| MimeMappings media_map_; |
| @@ -166,8 +133,7 @@ class MimeUtil : public PlatformMimeUtil { |
| // advertised to callers. |
| bool allow_proprietary_codecs_; |
| - // Lookup table for string compare based string -> Codec mappings. |
| - StringToCodecMappings string_to_codec_map_; |
| + IsCodecSupportedCB is_codec_supported_cb_; |
| }; // class MimeUtil |
| // This variable is Leaky because we need to access it from WorkerPool threads. |
| @@ -450,42 +416,27 @@ static const char* const supported_javascript_types[] = { |
| }; |
| #if defined(OS_ANDROID) |
| -static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { |
| - switch (codec) { |
| - case MimeUtil::INVALID_CODEC: |
| - return false; |
| - |
| - case MimeUtil::PCM: |
| - case MimeUtil::MP3: |
| - case MimeUtil::MPEG4_AAC_LC: |
| - case MimeUtil::MPEG4_AAC_SBR_v1: |
| - case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
| - case MimeUtil::H264_BASELINE: |
| - case MimeUtil::H264_MAIN: |
| - case MimeUtil::H264_HIGH: |
| - case MimeUtil::VP8: |
| - case MimeUtil::VORBIS: |
| - return true; |
| - |
| - 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; |
| +bool IsCodecSupportedOnAndroid(const std::string& codec) { |
| + // Theora is not supported |
| + if (codec == "theora") |
| + return false; |
| - case MimeUtil::VP9: |
| - // VP9 is supported only in KitKat+ (API Level 19). |
| - return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| + // VP9 is supported only in KitKat+ (API Level 19). |
| + if (codec == "vp9" || codec == "vp9.0") |
| + return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| - case MimeUtil::OPUS: |
| - // Opus is supported only in Lollipop+ (API Level 21). |
| - return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
| + // Opus is supported only in Lollipop+ (API Level 21). |
| + if (codec == "opus") |
| + return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
| - case MimeUtil::THEORA: |
| - return false; |
| - } |
| + // MPEG-2 variants of AAC are not supported on Android. |
| + // MPEG2_AAC_MAIN / MPEG2_AAC_LC / MPEG2_AAC_SSR |
| + if (codec == "mp4a.66" || codec == "mp4a.67" || codec == "mp4a.68") |
| + return false; |
| - return false; |
| + // For all other codecs use the default Chromium logic to decide |
| + // whether it's supported or not |
| + return DefaultIsCodecSupported(codec); |
| } |
| #endif |
| @@ -494,35 +445,9 @@ struct MediaFormatStrict { |
| const char* const codecs_list; |
| }; |
| -// Following is the list of RFC 6381 compliant codecs: |
| -// mp4a.66 - MPEG-2 AAC MAIN |
| -// mp4a.67 - MPEG-2 AAC LC |
| -// mp4a.68 - MPEG-2 AAC SSR |
| -// mp4a.69 - MPEG-2 extension to MPEG-1 |
| -// mp4a.6B - MPEG-1 audio |
| -// mp4a.40.2 - MPEG-4 AAC LC |
| -// mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for compatibility) |
| -// mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) |
| -// mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for |
| -// compatibility) |
| -// mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) |
| -// |
| -// avc1.42E0xx - H.264 Baseline |
| -// avc1.4D40xx - H.264 Main |
| -// avc1.6400xx - H.264 High |
| -static const char kMP4AudioCodecsExpression[] = |
| - "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| - "mp4a.40.05,mp4a.40.29"; |
| +static const char kMP4AudioCodecsExpression[] = "mp4a.*"; |
| static const char kMP4VideoCodecsExpression[] = |
| - // This is not a complete list of supported avc1 codecs. It is simply used |
| - // to register support for the corresponding Codec enum. Instead of using |
| - // strings in these three arrays, we should use the Codec enum values. |
| - // This will avoid confusion and unnecessary parsing at runtime. |
| - // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only |
| - // mapping from strings to codecs. See crbug.com/461009. |
| - "avc1.42E00A,avc1.4D400A,avc1.64000A," |
| - "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| - "mp4a.40.05,mp4a.40.29"; |
| + "avc1,avc3,avc1.*,avc3.*,mp4a.*"; |
| // These containers are also included in |
| // common_media_types/proprietary_media_types. See crbug.com/461012. |
| @@ -551,49 +476,10 @@ static const MediaFormatStrict format_codec_mappings[] = { |
| {"application/x-mpegurl", kMP4VideoCodecsExpression}, |
| {"application/vnd.apple.mpegurl", kMP4VideoCodecsExpression}}; |
| -struct CodecIDMappings { |
| - const char* const codec_id; |
| - MimeUtil::Codec codec; |
| -}; |
| - |
| -// List of codec IDs that provide enough information to determine the |
| -// codec and profile being requested. |
| -// |
| -// 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(). |
| - {"mp3", MimeUtil::MP3}, |
| - {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
| - {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, |
| - {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, |
| - {"mp4a.69", MimeUtil::MP3}, |
| - {"mp4a.6B", MimeUtil::MP3}, |
| - {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, |
| - {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, |
| - {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, |
| - {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, |
| - {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, |
| - {"vorbis", MimeUtil::VORBIS}, |
| - {"opus", MimeUtil::OPUS}, |
| - {"vp8", MimeUtil::VP8}, |
| - {"vp8.0", MimeUtil::VP8}, |
| - {"vp9", MimeUtil::VP9}, |
| - {"vp9.0", MimeUtil::VP9}, |
| - {"theora", MimeUtil::THEORA}}; |
| - |
| -// List of codec IDs that are ambiguous and don't provide |
| -// enough information to determine the codec and profile. |
| -// The codec in these entries indicate the codec and profile |
| -// 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(). |
| -}; |
| - |
| MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { |
| +#if defined(OS_ANDROID) |
| + SetIsCodecSupportedCB(base::Bind(&IsCodecSupportedOnAndroid)); |
| +#endif |
| InitializeMimeTypeMaps(); |
| } |
| @@ -605,20 +491,26 @@ SupportsType MimeUtil::AreSupportedCodecs( |
| SupportsType result = IsSupported; |
| for (size_t i = 0; i < codecs.size(); ++i) { |
| - bool is_ambiguous = true; |
| - Codec codec = INVALID_CODEC; |
| - if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) |
| + const std::string& codec_id = codecs[i]; |
| + if (!IsCodecSupported(codec_id)) { |
| return IsNotSupported; |
| + } |
| - if (!IsCodecSupported(codec) || |
| - supported_codecs.find(codec) == supported_codecs.end()) { |
| + bool found_in_supported = false; |
| + for (size_t j = 0; j < supported_codecs.size(); ++j) { |
| + if (MatchPattern(codec_id, supported_codecs[j])) { |
| + found_in_supported = true; |
| + break; |
| + } |
| + } |
| + |
| + if (!found_in_supported) { |
| return IsNotSupported; |
| } |
|
Ryan Sleevi
2015/04/21 13:23:29
net doesn't use braces for single-line ifs; also l
servolk
2015/04/21 22:09:02
Done.
|
| - if (is_ambiguous) |
| + if (IsCodecAmbiguous(codecs[i])) |
| result = MayBeSupported; |
| } |
| - |
| return result; |
| } |
| @@ -657,33 +549,12 @@ void MimeUtil::InitializeMimeTypeMaps() { |
| for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
| javascript_map_.insert(supported_javascript_types[i]); |
| - for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { |
| - string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = |
| - CodecEntry(kUnambiguousCodecStringMap[i].codec, false); |
| - } |
| - |
| - for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { |
| - string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = |
| - CodecEntry(kAmbiguousCodecStringMap[i].codec, true); |
| - } |
| - |
| // Initialize the strict supported media types. |
| for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
| - std::vector<std::string> mime_type_codecs; |
| - ParseCodecString(format_codec_mappings[i].codecs_list, |
| - &mime_type_codecs, |
| - false); |
| - |
| - CodecSet codecs; |
| - for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
| - Codec codec = INVALID_CODEC; |
| - bool is_ambiguous = true; |
| - CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); |
| - DCHECK(!is_ambiguous); |
| - codecs.insert(codec); |
| - } |
| - |
| - strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
| + CodecSet supported_codecs; |
| + base::SplitString(format_codec_mappings[i].codecs_list, ',', |
| + &supported_codecs); |
| + strict_format_map_[format_codec_mappings[i].mime_type] = supported_codecs; |
| } |
| } |
| @@ -867,10 +738,7 @@ bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const { |
| bool MimeUtil::AreSupportedMediaCodecs( |
| const std::vector<std::string>& codecs) const { |
| for (size_t i = 0; i < codecs.size(); ++i) { |
| - Codec codec = INVALID_CODEC; |
| - bool is_ambiguous = true; |
| - if (!StringToCodec(codecs[i], &codec, &is_ambiguous) || |
| - !IsCodecSupported(codec)) { |
| + if (!IsCodecSupported(codecs[i])) { |
| return false; |
| } |
| } |
| @@ -912,11 +780,14 @@ SupportsType MimeUtil::IsSupportedStrictMediaMimeType( |
| return codecs.empty() ? MayBeSupported : IsNotSupported; |
| if (it_strict_map->second.empty()) { |
| - // We get here if the mimetype does not expect a codecs parameter. |
| - return (codecs.empty() && |
| - IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) |
| - ? IsSupported |
| - : IsNotSupported; |
| + // We get here if the mimetype does not expect a codecs parameter. |
| + std::string default_codec = ""; |
|
Ryan Sleevi
2015/04/21 13:23:29
This is the inefficient way to instantiate empty s
servolk
2015/04/21 22:09:02
Done.
|
| + if (codecs.empty() && |
| + GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec) && |
| + IsCodecSupported(default_codec)) { |
| + return IsSupported; |
| + } |
| + return IsNotSupported; |
| } |
| if (codecs.empty()) { |
| @@ -924,7 +795,7 @@ SupportsType MimeUtil::IsSupportedStrictMediaMimeType( |
| // but didn't get one. If |mime_type_lower_case| does not have a default |
| // codec the best we can do is say "maybe" because we don't have enough |
| // information. |
| - Codec default_codec = INVALID_CODEC; |
| + std::string default_codec = ""; |
| if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
| return MayBeSupported; |
| @@ -1000,7 +871,6 @@ static bool IsValidH264Level(const std::string& level_str) { |
| // 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 |
| if (codec_id.size() != 11 || |
| @@ -1010,97 +880,93 @@ static bool ParseH264CodecID(const std::string& codec_id, |
| } |
| std::string profile = StringToUpperASCII(codec_id.substr(5, 4)); |
| - if (IsValidH264BaselineProfile(profile)) { |
| - *codec = MimeUtil::H264_BASELINE; |
| - } else if (profile == "4D40") { |
| - *codec = MimeUtil::H264_MAIN; |
| - } else if (profile == "6400") { |
| - *codec = MimeUtil::H264_HIGH; |
| + if (IsValidH264BaselineProfile(profile) || |
| + profile == "4D40" || profile == "6400") { |
| + *is_ambiguous = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9))); |
| } else { |
| - *codec = MimeUtil::H264_BASELINE; |
| *is_ambiguous = true; |
| - return true; |
| } |
| - *is_ambiguous = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9))); |
| return true; |
| } |
| -bool MimeUtil::StringToCodec(const std::string& codec_id, |
| - Codec* codec, |
| - bool* is_ambiguous) const { |
| - StringToCodecMappings::const_iterator itr = |
| - string_to_codec_map_.find(codec_id); |
| - if (itr != string_to_codec_map_.end()) { |
| - *codec = itr->second.codec; |
| - *is_ambiguous = itr->second.is_ambiguous; |
| +bool MimeUtil::IsCodecAmbiguous(const std::string& codec_id) const { |
| + if (codec_id == "avc1" || codec_id == "avc3" || codec_id == "mp4a.40") |
| return true; |
| + bool is_ambiguous = false; |
| + if (ParseH264CodecID(codec_id, &is_ambiguous)) { |
| + return is_ambiguous; |
| } |
|
Ryan Sleevi
2015/04/21 13:23:29
braces
servolk
2015/04/21 22:09:02
Done.
|
| + return false; |
| +} |
| - // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
| - // an H.264 codec ID because currently those are the only ones that can't be |
| - // stored in the |string_to_codec_map_| and require parsing. |
| - return ParseH264CodecID(codec_id, codec, is_ambiguous); |
| +bool MimeUtil::IsCodecSupported(const std::string& codec) const { |
| + if (!is_codec_supported_cb_.is_null()) |
| + return is_codec_supported_cb_.Run(codec); |
| + return DefaultIsCodecSupported(codec); |
| } |
| -bool MimeUtil::IsCodecSupported(Codec codec) const { |
| - DCHECK_NE(codec, INVALID_CODEC); |
| +void MimeUtil::SetIsCodecSupportedCB(IsCodecSupportedCB is_codec_supported_cb) { |
| + is_codec_supported_cb_ = is_codec_supported_cb; |
| +} |
| -#if defined(OS_ANDROID) |
| - if (!IsCodecSupportedOnAndroid(codec)) |
| +bool MimeUtil::IsCodecProprietary(const std::string& codec) const { |
| + if (codec == "1" /*PCM*/ || codec == "vorbis" || codec == "opus" || |
| + codec == "theora" || codec == "vp8" || codec == "vp8.0" || |
| + codec == "vp9" || codec == "vp9.0") |
|
Ryan Sleevi
2015/04/21 13:23:29
Here you've got multi-line diffs where you should
servolk
2015/04/21 22:09:02
Done.
|
| return false; |
| -#endif |
| - return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
| + return true; |
| } |
| -bool MimeUtil::IsCodecProprietary(Codec codec) const { |
| - switch (codec) { |
| - case INVALID_CODEC: |
| - case MP3: |
| - case MPEG2_AAC_LC: |
| - case MPEG2_AAC_MAIN: |
| - case MPEG2_AAC_SSR: |
| - case MPEG4_AAC_LC: |
| - case MPEG4_AAC_SBR_v1: |
| - case MPEG4_AAC_SBR_PS_v2: |
| - case H264_BASELINE: |
| - case H264_MAIN: |
| - case H264_HIGH: |
| - return true; |
| +bool MimeUtil::DefaultIsCodecSupported(const std::string& codec) const { |
| + if (!allow_proprietary_codecs_ && IsCodecProprietary(codec)) |
| + return false; |
| - case PCM: |
| - case VORBIS: |
| - case OPUS: |
| - case VP8: |
| - case VP9: |
| - case THEORA: |
| - return false; |
| + if (codec == "1" /*PCM*/ || codec == "vorbis" || codec == "opus" || |
| + codec == "theora" || codec == "vp8" || codec == "vp8.0" || |
| + codec == "vp9" || codec == "vp9.0") |
|
Ryan Sleevi
2015/04/21 13:23:29
ditto + braces
servolk
2015/04/21 22:09:02
Done.
|
| + return true; |
| + |
| + if (codec == "mp3" || codec == "mp4a.66" || codec == "mp4a.67" || |
| + codec == "mp4a.68" || codec == "mp4a.69" || codec == "mp4a.6B" || |
| + codec == "mp4a.40.2" || codec == "mp4a.40.02" || codec == "mp4a.40.29" || |
| + codec == "mp4a.40.5" || codec == "mp4a.40.05" || codec == "mp4a.40") |
| + return true; |
|
Ryan Sleevi
2015/04/21 13:23:29
+braces and +whitespace
servolk
2015/04/21 22:09:02
Done.
|
| +#if defined(ENABLE_MPEG2TS_STREAM_PARSER) |
| + // iOS 3.0 to 3.1.2 used non-standard codec ids for H.264 Baseline and Main |
| + // profiles in HTTP Live Streaming (HLS). Apple recommends using these |
| + // non-standard strings for compatibility with older iOS devices, and so many |
| + // HLS apps still use these. See |
| + // https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html |
| + // mp4a.40.34 is also Apple-specific name for MP3 in mpeg2ts container for HLS |
| + if (codec == "avc1.66.30" || codec == "avc1.77.30" || codec == "mp4a.40.34") |
| + return true; |
| +#endif |
| + |
| + bool is_ambiguous = true; |
| + if (codec == "avc1" || codec == "avc3" || |
| + ParseH264CodecID(codec, &is_ambiguous)) { |
| + return true; |
| } |
| - return true; |
| + // Unknown codec id |
| + return false; |
| } |
| bool MimeUtil::GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, |
| - Codec* default_codec) const { |
| + std::string* default_codec) const { |
| if (mime_type_lower_case == "audio/mpeg" || |
| mime_type_lower_case == "audio/mp3" || |
| mime_type_lower_case == "audio/x-mp3") { |
| - *default_codec = MimeUtil::MP3; |
| + DCHECK(default_codec); |
| + *default_codec = "mp3"; |
| return true; |
| } |
| return false; |
| } |
| -bool MimeUtil::IsDefaultCodecSupportedLowerCase( |
| - 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); |
| -} |
| - |
| //---------------------------------------------------------------------------- |
| // Wrappers for the singleton |
| //---------------------------------------------------------------------------- |
| @@ -1186,6 +1052,18 @@ void ParseCodecString(const std::string& codecs, |
| g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
| } |
| +bool IsCodecSupported(const std::string& codec_id) { |
| + return g_mime_util.Get().IsCodecSupported(codec_id); |
| +} |
| + |
| +bool DefaultIsCodecSupported(const std::string& codec_id) { |
| + return g_mime_util.Get().DefaultIsCodecSupported(codec_id); |
| +} |
| + |
| +void SetIsCodecSupportedCB(IsCodecSupportedCB is_codec_supported_cb) { |
| + return g_mime_util.Get().SetIsCodecSupportedCB(is_codec_supported_cb); |
| +} |
| + |
| namespace { |
| // From http://www.w3schools.com/media/media_mimeref.asp and |