Index: net/base/mime_util.cc |
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
index 442910b94c7abd536d0f92ffc4c86c55990f1128..b6f9446791a625e2f7bf60bf065a4375b5d5b8d2 100644 |
--- a/net/base/mime_util.cc |
+++ b/net/base/mime_util.cc |
@@ -78,7 +78,7 @@ class MimeUtil : public PlatformMimeUtil { |
bool strip); |
bool IsStrictMediaMimeType(const std::string& mime_type) const; |
- bool IsSupportedStrictMediaMimeType( |
+ CanPlayType IsSupportedStrictMediaMimeType( |
const std::string& mime_type, |
const std::vector<std::string>& codecs) const; |
@@ -90,12 +90,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 +119,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. |
@@ -460,6 +468,20 @@ static const MediaFormatStrict format_codec_mappings[] = { |
{ "audio/x-mp3", "" } |
}; |
+static const char* kProprietaryAudioCodecsExpression = |
+ "mp4a.40,mp4a.67,mp4a.40.?,mp4a.67.?"; |
+static const char* kProprietaryCodecsExpression = |
+ "avc1,avc3,avc1.??????,avc3.??????,mp4a.40,mp4a.67,mp4a.40.?,mp4a.67.?"; |
+ |
+static const MediaFormatStrict format_mp4_codec_mappings[] = { |
+ { "audio/mp4", kProprietaryAudioCodecsExpression }, |
+ { "audio/x-m4a", kProprietaryAudioCodecsExpression }, |
+ { "video/mp4", kProprietaryCodecsExpression }, |
+ { "video/x-m4v", kProprietaryCodecsExpression }, |
+ { "application/x-mpegurl", kProprietaryCodecsExpression }, |
+ { "application/vnd.apple.mpegurl", kProprietaryCodecsExpression } |
+}; |
+ |
MimeUtil::MimeUtil() { |
InitializeMimeTypeMaps(); |
} |
@@ -477,6 +499,41 @@ 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]))) { |
+ continue; |
+ } |
+ if (codecs[i].find('.') != std::string::npos) { |
+ if (EndsWith(codecs[i], ".", false)) |
+ return false; |
+ |
+ // We check whether the suffix is hexadecimal or not. |
Ryan Sleevi
2014/05/15 22:48:35
Pronouns in comments considered harmful - "We", in
amogh.bihani
2014/05/16 11:25:29
Done.
|
+ std::vector<std::string> split_string; |
+ base::SplitString(codecs[i], '.', &split_string); |
+ std::string number = split_string.back(); |
Ryan Sleevi
2014/05/15 22:48:35
const std::string&
amogh.bihani
2014/05/16 11:25:29
Done.
|
+ for (size_t k = 0; k < number.length(); ++k) { |
+ // We are neglecting case sensitivity as it might break some websites. |
Ryan Sleevi
2014/05/15 22:48:35
// Don't enforce case sensitivity, even though it'
amogh.bihani
2014/05/16 11:25:29
Done.
|
+ if (!IsHexDigit(number.at(k))) |
+ return false; |
+ } |
+ } |
+ // We have a match! Now no need to compare it with other supported codecs. |
Ryan Sleevi
2014/05/15 22:48:35
update
amogh.bihani
2014/05/16 11:25:29
removed it. The "break" explains this.
|
+ codec_matched = true; |
+ break; |
+ } |
+ // Return false if any of the codecs is not matching. |
Ryan Sleevi
2014/05/15 22:48:35
This is perhaps too descriptive - the next two lin
amogh.bihani
2014/05/16 11:25:29
Done.
|
+ 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]); |
@@ -547,6 +604,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 { |
@@ -729,17 +797,30 @@ 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; |
} |
-bool MimeUtil::IsSupportedStrictMediaMimeType( |
+CanPlayType MimeUtil::IsSupportedStrictMediaMimeType( |
const std::string& mime_type, |
const std::vector<std::string>& codecs) const { |
StrictMappings::const_iterator it = strict_format_map_.find(mime_type); |
- return (it != strict_format_map_.end()) && |
- AreSupportedCodecs(it->second, codecs); |
+ if (it != strict_format_map_.end() && AreSupportedCodecs(it->second, codecs)) |
+ return IsSupported; |
+ |
+ StrictExpressionMappings::const_iterator iter = |
+ strict_mp4_format_map_.find(mime_type); |
+ if ((iter != strict_mp4_format_map_.end()) && |
+ AreSupportedCodecsWithProfile(iter->second, codecs)) { |
+ return MayBeSupported; |
+ } |
+ |
+ if (codecs.empty()) |
+ return MayBeSupported; |
+ |
+ return IsNotSupported; |
} |
void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
@@ -817,8 +898,9 @@ bool IsStrictMediaMimeType(const std::string& mime_type) { |
return g_mime_util.Get().IsStrictMediaMimeType(mime_type); |
} |
-bool IsSupportedStrictMediaMimeType(const std::string& mime_type, |
- const std::vector<std::string>& codecs) { |
+CanPlayType IsSupportedStrictMediaMimeType( |
+ const std::string& mime_type, |
+ const std::vector<std::string>& codecs) { |
return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); |
} |