Chromium Code Reviews| Index: net/base/mime_util.cc |
| diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
| index fdb16fd8f7ef0b0f22b2d2e232198587ce19344d..3542ad9340a756304e7134441317d01555c43b33 100644 |
| --- a/net/base/mime_util.cc |
| +++ b/net/base/mime_util.cc |
| @@ -81,6 +81,9 @@ class MimeUtil : public PlatformMimeUtil { |
| bool IsSupportedStrictMediaMimeType( |
| const std::string& mime_type, |
| const std::vector<std::string>& codecs) const; |
| + bool IsSupportedStrictMP4OrHLSMediaMimeType( |
| + const std::string& mime_type, |
| + const std::vector<std::string>& codecs) const; |
| void RemoveProprietaryMediaTypesAndCodecsForTests(); |
| @@ -90,12 +93,19 @@ class MimeUtil : public PlatformMimeUtil { |
| typedef base::hash_set<std::string> MimeMappings; |
| typedef std::map<std::string, MimeMappings> StrictMappings; |
| + typedef std::vector<std::string> MimeExpressionMappings; |
| + typedef std::map<std::string, MimeExpressionMappings> |
| + StrictExpressionMappings; |
| + |
| MimeUtil(); |
| // Returns true if |codecs| is nonempty and all the items in it are present in |
| // |supported_codecs|. |
| static bool AreSupportedCodecs(const MimeMappings& supported_codecs, |
| const std::vector<std::string>& codecs); |
| + static bool AreSupportedCodecsWithProfile( |
| + const MimeExpressionMappings& supported_codecs, |
| + const std::vector<std::string>& codecs); |
| // For faster lookup, keep hash sets. |
| void InitializeMimeTypeMaps(); |
| @@ -112,6 +122,7 @@ class MimeUtil : public PlatformMimeUtil { |
| MimeMappings codecs_map_; |
| StrictMappings strict_format_map_; |
| + StrictExpressionMappings strict_mp4_format_map_; |
| }; // class MimeUtil |
| // This variable is Leaky because we need to access it from WorkerPool threads. |
| @@ -444,6 +455,16 @@ static const MediaFormatStrict format_codec_mappings[] = { |
| { "audio/x-mp3", "" } |
| }; |
| +static const MediaFormatStrict format_mp4_codec_mappings[] = { |
| + {"audio/mp4", "mp4a,mp4a.40,mp4a.40.?"}, |
|
acolwell GONE FROM CHROMIUM
2014/05/12 14:54:18
mp4a is not valid. mp4a.67 should be added to this
amogh.bihani
2014/05/15 09:05:53
Done.
|
| + {"audio/x-m4a", "mp4a,mp4a.40,mp4a.40.?"}, |
| + {"video/mp4", "avc1,avc3,avc1.??????,avc3.??????,mp4a,mp4a.40,mp4a.40.?"}, |
|
acolwell GONE FROM CHROMIUM
2014/05/12 14:54:18
nit: perhaps move this into a static constant so i
amogh.bihani
2014/05/15 09:05:53
Done.
|
| + {"video/x-m4v", "avc1,avc3,avc1.??????,avc3.??????,mp4a,mp4a.40,mp4a.40.?"}, |
| + {"application/x-mpegurl", |
| + "avc1,avc3,avc1.??????,avc3.??????,mp4a,mp4a.40,mp4a.40.?"}, |
| + {"application/vnd.apple.mpegurl", |
| + "avc1,avc3,avc1.??????,avc3.??????,mp4a,mp4a.40,mp4a.40.?"}}; |
| + |
| MimeUtil::MimeUtil() { |
| InitializeMimeTypeMaps(); |
| } |
| @@ -461,6 +482,31 @@ bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, |
| return !codecs.empty(); |
| } |
| +bool MimeUtil::AreSupportedCodecsWithProfile( |
| + const MimeExpressionMappings& supported_codecs, |
| + const std::vector<std::string>& codecs) { |
| + for (size_t i = 0; i < codecs.size(); ++i) { |
| + bool codec_matched = false; |
| + for (size_t j = 0; j < supported_codecs.size(); ++j) { |
| + if (MatchPattern(static_cast<base::StringPiece>(codecs[i]), |
|
acolwell GONE FROM CHROMIUM
2014/05/12 14:54:18
nit: reverse condition & continue
amogh.bihani
2014/05/15 09:05:53
Done.
|
| + static_cast<base::StringPiece>(supported_codecs[j]))) { |
| + codec_matched = true; |
| + std::vector<std::string> split_string; |
| + base::SplitString(codecs[i], '.', &split_string); |
| + if (split_string.size() > 1 && |
| + !IsUpperCaseHexNumber(split_string.back())) { |
|
acolwell GONE FROM CHROMIUM
2014/05/12 14:54:18
I don't think we should enforce upper case here. Y
amogh.bihani
2014/05/15 09:05:53
Done.
|
| + codec_matched = false; |
|
acolwell GONE FROM CHROMIUM
2014/05/12 14:54:18
nit: just return false here and move codec_matched
amogh.bihani
2014/05/15 09:05:53
Done.
|
| + } |
| + break; |
| + } |
| + } |
| + // Return false if any of the codecs is not matching. |
| + if (!codec_matched) |
| + return false; |
| + } |
| + return !codecs.empty(); |
| +} |
| + |
| void MimeUtil::InitializeMimeTypeMaps() { |
| for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
| image_map_.insert(supported_image_types[i]); |
| @@ -521,6 +567,17 @@ void MimeUtil::InitializeMimeTypeMaps() { |
| } |
| strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
| } |
| + for (size_t i = 0; i < arraysize(format_mp4_codec_mappings); ++i) { |
| + std::vector<std::string> mime_type_codecs; |
| + ParseCodecString( |
| + format_mp4_codec_mappings[i].codecs_list, &mime_type_codecs, false); |
| + |
| + MimeExpressionMappings codecs; |
| + for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
| + codecs.push_back(mime_type_codecs[j]); |
| + } |
| + strict_mp4_format_map_[format_mp4_codec_mappings[i].mime_type] = codecs; |
| + } |
| } |
| bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
| @@ -703,7 +760,8 @@ void MimeUtil::ParseCodecString(const std::string& codecs, |
| } |
| bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { |
| - if (strict_format_map_.find(mime_type) == strict_format_map_.end()) |
| + if (strict_format_map_.find(mime_type) == strict_format_map_.end() && |
| + strict_mp4_format_map_.find(mime_type) == strict_mp4_format_map_.end()) |
| return false; |
| return true; |
| } |
| @@ -716,6 +774,15 @@ bool MimeUtil::IsSupportedStrictMediaMimeType( |
| AreSupportedCodecs(it->second, codecs); |
| } |
| +bool MimeUtil::IsSupportedStrictMP4OrHLSMediaMimeType( |
| + const std::string& mime_type, |
| + const std::vector<std::string>& codecs) const { |
| + StrictExpressionMappings::const_iterator it = |
| + strict_mp4_format_map_.find(mime_type); |
| + return (it != strict_mp4_format_map_.end() && |
| + AreSupportedCodecsWithProfile(it->second, codecs)); |
| +} |
| + |
| void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
| for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { |
| non_image_map_.erase(proprietary_media_types[i]); |
| @@ -796,6 +863,13 @@ bool IsSupportedStrictMediaMimeType(const std::string& mime_type, |
| return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); |
| } |
| +bool IsSupportedStrictMP4OrHLSMediaMimeType( |
| + const std::string& mime_type, |
| + const std::vector<std::string>& codecs) { |
| + return g_mime_util.Get().IsSupportedStrictMP4OrHLSMediaMimeType(mime_type, |
| + codecs); |
| +} |
| + |
| void ParseCodecString(const std::string& codecs, |
| std::vector<std::string>* codecs_out, |
| const bool strip) { |