Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: net/base/mime_util.cc

Issue 254983006: Fix: Adding list of supported codecs for MP4 containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/mime_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mime_util.cc
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc
index fdb16fd8f7ef0b0f22b2d2e232198587ce19344d..fb97820bc969ff7cb3410b7b1ac9e9eec68e2a1b 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 IsSupportedStrictMP4MediaMimeType(
+ 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;
Ryan Sleevi 2014/04/28 22:02:55 style: Formatting is wrong here. Use git-cl format
+
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);
Ryan Sleevi 2014/04/28 22:02:55 Style: Formatting is wrong here
// 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,17 @@ static const MediaFormatStrict format_codec_mappings[] = {
{ "audio/x-mp3", "" }
};
+static const MediaFormatStrict format_mp4_codec_mappings[] = {
+ { "audio/mp4", "mp4a,mp4a.40,mp4a.40.?" },
+ { "audio/x-m4a", "mp4a,mp4a.40,mp4a.40.?" },
+ { "video/mp4", "avc1,avc3,avc1.??????,avc3.??????,mp4a,mp4a.40,mp4a.40.?" },
+ { "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.?" }
Ryan Sleevi 2014/04/28 22:02:55 Why ? instead of *?
amogh.bihani 2014/04/29 03:56:09 Because '*' wildcard can take any number of charac
+};
+
MimeUtil::MimeUtil() {
InitializeMimeTypeMaps();
}
@@ -461,6 +483,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]),
+ 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 &&
+ !IsHigherCaseHexNumber(split_string.back())) {
+ codec_matched = false;
+ }
+ 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 +568,18 @@ 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 +762,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 +776,15 @@ bool MimeUtil::IsSupportedStrictMediaMimeType(
AreSupportedCodecs(it->second, codecs);
}
+bool MimeUtil::IsSupportedStrictMP4MediaMimeType(
+ 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 +865,11 @@ bool IsSupportedStrictMediaMimeType(const std::string& mime_type,
return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs);
}
+bool IsSupportedStrictMP4MediaMimeType(const std::string& mime_type,
+ const std::vector<std::string>& codecs) {
+ return g_mime_util.Get().IsSupportedStrictMP4MediaMimeType(mime_type, codecs);
+}
+
void ParseCodecString(const std::string& codecs,
std::vector<std::string>* codecs_out,
const bool strip) {
« no previous file with comments | « net/base/mime_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698