diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-20 00:53:01 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-20 00:53:01 +0000 |
commit | 074248931d91c43c612ee611342a5c354f580b2e (patch) | |
tree | 654b9a2a73672ae31daba1161fa969c8646bd11a /net | |
parent | 57675d4d32433b20aa1852690c69ddbf18693f1f (diff) | |
download | chromium_src-074248931d91c43c612ee611342a5c354f580b2e.zip chromium_src-074248931d91c43c612ee611342a5c354f580b2e.tar.gz chromium_src-074248931d91c43c612ee611342a5c354f580b2e.tar.bz2 |
Chromium side changes for enabling VP8 and WebM support.
Patches by Frank Galligan (fgalligan@google.com), Tom Finegan (tomfinegan@google.com) and James Zern (jzern@google.com).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2093007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/mime_util.cc | 85 | ||||
-rw-r--r-- | net/base/mime_util.h | 22 | ||||
-rw-r--r-- | net/base/mime_util_unittest.cc | 9 |
3 files changed, 105 insertions, 11 deletions
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc index 5d975e6..976aab2 100644 --- a/net/base/mime_util.cc +++ b/net/base/mime_util.cc @@ -1,7 +1,8 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <map> #include <string> #include "net/base/mime_util.h" @@ -41,7 +42,12 @@ class MimeUtil : public PlatformMimeUtil { bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; void ParseCodecString(const std::string& codecs, - std::vector<std::string>* codecs_out); + std::vector<std::string>* codecs_out, + bool strip); + + bool IsStrictMediaMimeType(const std::string& mime_type) const; + bool IsSupportedStrictMediaMimeType(const std::string& mime_type, + const std::vector<std::string>& codecs) const; private: friend struct DefaultSingletonTraits<MimeUtil>; @@ -59,6 +65,9 @@ class MimeUtil : public PlatformMimeUtil { MimeMappings javascript_map_; MimeMappings view_source_map_; MimeMappings codecs_map_; + + typedef std::map<std::string, base::hash_set<std::string> > StrictMappings; + StrictMappings strict_format_map_; }; // class MimeUtil struct MimeInfo { @@ -78,6 +87,8 @@ static const MimeInfo primary_mappings[] = { { "audio/mp3", "mp3" }, { "video/ogg", "ogv,ogm" }, { "audio/ogg", "ogg,oga" }, + { "video/webm", "webm" }, + { "audio/webm", "webm" }, { "application/xhtml+xml", "xhtml,xht" }, { "application/x-chrome-extension", "crx" } }; @@ -188,6 +199,8 @@ static const char* const supported_media_types[] = { "video/ogg", "audio/ogg", "application/ogg", + "video/webm", + "audio/webm", #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) // MPEG-4. @@ -214,6 +227,7 @@ static const char* const supported_media_codecs[] = { #endif "theora", "vorbis", + "vp8" }; // Note: does not include javascript types list (see supported_javascript_types) @@ -277,6 +291,16 @@ static const char* const view_source_types[] = { "image/svg+xml" }; +struct MediaFormatStrict { + const char* mime_type; + const char* codecs_list; +}; + +static const MediaFormatStrict format_codec_mappings[] = { + { "video/webm", "vorbis,vp8,vp8.0" }, + { "audio/webm", "vorbis" } +}; + void MimeUtil::InitializeMimeTypeMaps() { for (size_t i = 0; i < arraysize(supported_image_types); ++i) image_map_.insert(supported_image_types[i]); @@ -301,6 +325,19 @@ void MimeUtil::InitializeMimeTypeMaps() { for (size_t i = 0; i < arraysize(supported_media_codecs); ++i) codecs_map_.insert(supported_media_codecs[i]); + + // 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); + + MimeMappings codecs; + for (size_t j = 0; j < mime_type_codecs.size(); ++j) + codecs.insert(mime_type_codecs[j]); + strict_format_map_[format_codec_mappings[i].mime_type] = codecs; + } } bool MimeUtil::IsSupportedImageMimeType(const char* mime_type) const { @@ -378,12 +415,16 @@ bool MimeUtil::AreSupportedMediaCodecs( } void MimeUtil::ParseCodecString(const std::string& codecs, - std::vector<std::string>* codecs_out) { + std::vector<std::string>* codecs_out, + bool strip) { std::string no_quote_codecs; TrimString(codecs, "\"", &no_quote_codecs); SplitString(no_quote_codecs, ',', codecs_out); - // Truncate each string at the '.' + if (!strip) + return; + + // Strip everything past the first '.' for (std::vector<std::string>::iterator it = codecs_out->begin(); it != codecs_out->end(); ++it) { @@ -393,6 +434,28 @@ 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()) + return false; + return true; +} + +bool MimeUtil::IsSupportedStrictMediaMimeType(const std::string& mime_type, + const std::vector<std::string>& codecs) const { + StrictMappings::const_iterator it = strict_format_map_.find(mime_type); + + if (it == strict_format_map_.end()) + return false; + + const MimeMappings strict_codecs_map = it->second; + for (size_t i = 0; i < codecs.size(); ++i) { + if (strict_codecs_map.find(codecs[i]) == strict_codecs_map.end()) { + return false; + } + } + return true; +} + //---------------------------------------------------------------------------- // Wrappers for the singleton //---------------------------------------------------------------------------- @@ -448,9 +511,19 @@ bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { return GetMimeUtil()->AreSupportedMediaCodecs(codecs); } +bool IsStrictMediaMimeType(const std::string& mime_type) { + return GetMimeUtil()->IsStrictMediaMimeType(mime_type); +} + +bool IsSupportedStrictMediaMimeType(const std::string& mime_type, + const std::vector<std::string>& codecs) { + return GetMimeUtil()->IsSupportedStrictMediaMimeType(mime_type, codecs); +} + void ParseCodecString(const std::string& codecs, - std::vector<std::string>* codecs_out) { - GetMimeUtil()->ParseCodecString(codecs, codecs_out); + std::vector<std::string>* codecs_out, + const bool strip) { + GetMimeUtil()->ParseCodecString(codecs, codecs_out, strip); } } // namespace net diff --git a/net/base/mime_util.h b/net/base/mime_util.h index 1846087..eebc2e8 100644 --- a/net/base/mime_util.h +++ b/net/base/mime_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -50,11 +50,25 @@ bool MatchesMimeType(const std::string &mime_type_pattern, bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs); // Parses a codec string, populating |codecs_out| with the prefix of each codec -// in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", |codecs_out| -// will contain {"aaa", "dd"}. +// in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", if +// |strip| == true |codecs_out| will contain {"aaa", "dd"}, if |strip| == false +// |codecs_out| will contain {"aaa.b.c", "dd.eee"}. // See http://www.ietf.org/rfc/rfc4281.txt. void ParseCodecString(const std::string& codecs, - std::vector<std::string>* codecs_out); + std::vector<std::string>* codecs_out, + bool strip); + +// Check to see if a particular MIME type is in our list which only supports a +// certain subset of codecs. +bool IsStrictMediaMimeType(const std::string& mime_type); + +// Check to see if a particular MIME type is in our list which only supports a +// certain subset of codecs. Returns true if and only if all codecs are +// supported for that specific MIME type, false otherwise. If this returns +// false you will still need to check if the media MIME tpyes and codecs are +// supported. +bool IsSupportedStrictMediaMimeType(const std::string& mime_type, + const std::vector<std::string>& codecs); } // namespace net diff --git a/net/base/mime_util_unittest.cc b/net/base/mime_util_unittest.cc index 0300da8..51b7f3a 100644 --- a/net/base/mime_util_unittest.cc +++ b/net/base/mime_util_unittest.cc @@ -118,10 +118,17 @@ TEST(MimeUtilTest, ParseCodecString) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { std::vector<std::string> codecs_out; - net::ParseCodecString(tests[i].original, &codecs_out); + net::ParseCodecString(tests[i].original, &codecs_out, true); EXPECT_EQ(tests[i].expected_size, codecs_out.size()); for (size_t j = 0; j < tests[i].expected_size; ++j) { EXPECT_EQ(tests[i].results[j], codecs_out[j]); } } + + // Test without stripping the codec type. + std::vector<std::string> codecs_out; + net::ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); + EXPECT_EQ(2u, codecs_out.size()); + EXPECT_STREQ("avc1.42E01E", codecs_out[0].c_str()); + EXPECT_STREQ("mp4a.40.2", codecs_out[1].c_str()); } |