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

Side by Side Diff: media/base/mime_util_internal.h

Issue 2864593003: Add MimeUtil::Parse{Audio|Video}CodecString (Closed)
Patch Set: Feedback && Proprietary Codecs fix && Rebase Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « media/base/mime_util.cc ('k') | media/base/mime_util_internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_MIME_UTIL_INTERNAL_H_ 5 #ifndef MEDIA_BASE_MIME_UTIL_INTERNAL_H_
6 #define MEDIA_BASE_MIME_UTIL_INTERNAL_H_ 6 #define MEDIA_BASE_MIME_UTIL_INTERNAL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "media/base/media_export.h" 14 #include "media/base/media_export.h"
15 #include "media/base/mime_util.h" 15 #include "media/base/mime_util.h"
16 #include "media/base/video_codecs.h" 16 #include "media/base/video_codecs.h"
17 #include "media/base/video_color_space.h"
17 18
18 namespace media { 19 namespace media {
19 20
20 class VideoColorSpace;
21
22 namespace internal { 21 namespace internal {
23 22
24 // Internal utility class for handling mime types. Should only be invoked by 23 // Internal utility class for handling mime types. Should only be invoked by
25 // tests and the functions within mime_util.cc -- NOT for direct use by others. 24 // tests and the functions within mime_util.cc -- NOT for direct use by others.
26 class MEDIA_EXPORT MimeUtil { 25 class MEDIA_EXPORT MimeUtil {
27 public: 26 public:
28 MimeUtil(); 27 MimeUtil();
29 ~MimeUtil(); 28 ~MimeUtil();
30 29
31 enum Codec { 30 enum Codec {
(...skipping 19 matching lines...) Expand all
51 // Platform configuration structure. Controls which codecs are supported at 50 // Platform configuration structure. Controls which codecs are supported at
52 // runtime. Also used by tests to simulate platform differences. 51 // runtime. Also used by tests to simulate platform differences.
53 struct PlatformInfo { 52 struct PlatformInfo {
54 bool has_platform_decoders = false; 53 bool has_platform_decoders = false;
55 54
56 bool has_platform_vp8_decoder = false; 55 bool has_platform_vp8_decoder = false;
57 bool has_platform_vp9_decoder = false; 56 bool has_platform_vp9_decoder = false;
58 bool supports_opus = false; 57 bool supports_opus = false;
59 }; 58 };
60 59
60 struct ParsedCodecResult {
61 Codec codec;
62 bool is_ambiguous;
63 VideoCodecProfile video_profile;
64 uint8_t video_level;
65 VideoColorSpace video_color_space;
66 };
67
61 // See mime_util.h for more information on these methods. 68 // See mime_util.h for more information on these methods.
62 bool IsSupportedMediaMimeType(const std::string& mime_type) const; 69 bool IsSupportedMediaMimeType(const std::string& mime_type) const;
63 void SplitCodecsToVector(const std::string& codecs, 70 void SplitCodecsToVector(const std::string& codecs,
64 std::vector<std::string>* codecs_out, 71 std::vector<std::string>* codecs_out,
65 bool strip); 72 bool strip);
73 bool ParseVideoCodecString(const std::string& mime_type,
74 const std::string& codec_id,
75 bool* out_is_ambiguous,
76 VideoCodec* out_codec,
77 VideoCodecProfile* out_profile,
78 uint8_t* out_level,
79 VideoColorSpace* out_color_space);
80 bool ParseAudioCodecString(const std::string& mime_type,
81 const std::string& codec_id,
82 bool* out_is_ambiguous,
83 AudioCodec* out_codec);
66 SupportsType IsSupportedMediaFormat(const std::string& mime_type, 84 SupportsType IsSupportedMediaFormat(const std::string& mime_type,
67 const std::vector<std::string>& codecs, 85 const std::vector<std::string>& codecs,
68 bool is_encrypted) const; 86 bool is_encrypted) const;
69 87
70 void RemoveProprietaryMediaTypesAndCodecs(); 88 void RemoveProprietaryMediaTypesAndCodecs();
71 89
72 // Checks android platform specific codec restrictions. Returns true if 90 // Checks android platform specific codec restrictions. Returns true if
73 // |codec| is supported when contained in |mime_type_lower_case|. 91 // |codec| is supported when contained in |mime_type_lower_case|.
74 // |is_encrypted| means the codec will be used with encrypted blocks. 92 // |is_encrypted| means the codec will be used with encrypted blocks.
75 // |platform_info| describes the availability of various platform features; 93 // |platform_info| describes the availability of various platform features;
(...skipping 17 matching lines...) Expand all
93 void AddContainerWithCodecs(const std::string& mime_type, 111 void AddContainerWithCodecs(const std::string& mime_type,
94 const CodecSet& codecs_list, 112 const CodecSet& codecs_list,
95 bool is_proprietary_mime_type); 113 bool is_proprietary_mime_type);
96 114
97 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are 115 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are
98 // supported in |mime_type_lower_case|. MayBeSupported is returned if at least 116 // supported in |mime_type_lower_case|. MayBeSupported is returned if at least
99 // one codec ID in |codecs| is ambiguous but all the codecs are supported. 117 // one codec ID in |codecs| is ambiguous but all the codecs are supported.
100 // IsNotSupported is returned if |mime_type_lower_case| is not supported or at 118 // IsNotSupported is returned if |mime_type_lower_case| is not supported or at
101 // least one is not supported in |mime_type_lower_case|. |is_encrypted| means 119 // least one is not supported in |mime_type_lower_case|. |is_encrypted| means
102 // the codec will be used with encrypted blocks. 120 // the codec will be used with encrypted blocks.
103 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, 121 SupportsType AreSupportedCodecs(
104 const std::vector<std::string>& codecs, 122 const std::vector<ParsedCodecResult>& parsed_codecs,
105 const std::string& mime_type_lower_case, 123 const std::string& mime_type_lower_case,
106 bool is_encrypted) const; 124 bool is_encrypted) const;
107 125
108 // Converts a codec ID into an Codec enum value and attempts to output the 126 // Parse the combination of |mime_type_lower_case| and |codecs|. Returns true
109 // |out_profile| and |out_level|. 127 // when parsing succeeds and output is written to |out_results|. Returns false
110 // Returns true if this method was able to map |codec_id| with 128 // when parsing fails. Failure may be caused by
111 // |mime_type_lower_case| to a specific Codec enum value. |codec| is only 129 // - invalid/unrecognized codec strings and mime_types
112 // valid if true is returned. 130 // - invalid combinations of codec strings and mime_types (e.g. H264 in WebM)
113 // |ambiguous_codec_string| will be set to true when the codec string matches 131 // See comment for ParseCodecHelper().
114 // one of a small number of non-RFC compliant strings (e.g. "avc"). 132 bool ParseCodecStrings(const std::string& mime_type_lower_case,
115 // |profile| and |level| indicate video codec profile and level (unused for 133 const std::vector<std::string>& codecs,
116 // audio codecs). These will be VIDEO_CODEC_PROFILE_UNKNOWN and 0 respectively 134 std::vector<ParsedCodecResult>* out_results) const;
117 // whenever |codec_id| is incomplete/invalid, or in some cases when 135
118 // |ambiguous_codec_string| is set to true. 136 // Helper to ParseCodecStrings(). Parses a single |codec_id| with
119 // |is_encrypted| means the codec will be used with encrypted blocks. 137 // |mime_type_lower_case| to populate the fields of |out_result|. This helper
120 // |out_color| is the color space described by the 138 // method does not validate the combination of |mime_type_lower_case| and
121 // |codec_id|. 139 // |codec_id|, nor does it handle empty/unprovided codecs; See caller
122 bool ParseCodecString(const std::string& mime_type_lower_case, 140 // ParseCodecStrings().
141 //
142 // |out_result| is only valid when this method returns true (parsing success).
143 // |out_result->is_ambiguous| will be set to true when the codec string
144 // matches one of a fixed number of *non-RFC compliant* strings (e.g. "avc").
145 // Ambiguous video codec strings may fail to provide video profile and/or
146 // level info. In these cases, we use the following values to indicate
147 // "unspecified":
148 // - out_result->video_profile = VIDEO_CODEC_PROFILE_UNKNOWN
149 // - out_result->video_level = 0
150 //
151 // For unambiguous video codecs, |video_profile| and |video_level| will be
152 // set in |out_result|.
153 //
154 // |out_result|'s |video_color_space| will report the codec strings color
155 // space when provided. Most codec strings do not yet describe color, so this
156 // will often be set to the default of REC709.
157 bool ParseCodecHelper(const std::string& mime_type_lower_case,
123 const std::string& codec_id, 158 const std::string& codec_id,
124 Codec* codec, 159 ParsedCodecResult* out_result) const;
125 bool* ambiguous_codec_string,
126 VideoCodecProfile* out_profile,
127 uint8_t* out_level,
128 VideoColorSpace* out_colorspace) const;
129 160
130 // Returns IsSupported if |codec| when platform supports codec contained in 161 // Returns IsSupported if |codec| when platform supports codec contained in
131 // |mime_type_lower_case|. Returns MayBeSupported when platform support is 162 // |mime_type_lower_case|. Returns MayBeSupported when platform support is
132 // unclear. Otherwise returns NotSupported. Note: This method will always 163 // unclear. Otherwise returns NotSupported. Note: This method will always
133 // return NotSupported for proprietary codecs if |allow_proprietary_codecs_| 164 // return NotSupported for proprietary codecs if |allow_proprietary_codecs_|
134 // is set to false. |is_encrypted| means the codec will be used with encrypted 165 // is set to false. |is_encrypted| means the codec will be used with encrypted
135 // blocks. 166 // blocks.
136 // TODO(chcunningham): Make this method return a bool. Platform support should 167 // TODO(chcunningham): Make this method return a bool. Platform support should
137 // always be knowable for a fully specified codec. 168 // always be knowable for a fully specified codec.
138 SupportsType IsCodecSupported(const std::string& mime_type_lower_case, 169 SupportsType IsCodecSupported(const std::string& mime_type_lower_case,
(...skipping 11 matching lines...) Expand all
150 181
151 // Returns true if |codec| refers to a proprietary codec. 182 // Returns true if |codec| refers to a proprietary codec.
152 bool IsCodecProprietary(Codec codec) const; 183 bool IsCodecProprietary(Codec codec) const;
153 184
154 // Returns true and sets |*default_codec| if |mime_type_lower_case| has a 185 // Returns true and sets |*default_codec| if |mime_type_lower_case| has a
155 // default codec associated with it. Returns false otherwise and the value of 186 // default codec associated with it. Returns false otherwise and the value of
156 // |*default_codec| is undefined. 187 // |*default_codec| is undefined.
157 bool GetDefaultCodec(const std::string& mime_type_lower_case, 188 bool GetDefaultCodec(const std::string& mime_type_lower_case,
158 Codec* default_codec) const; 189 Codec* default_codec) const;
159 190
160 // Returns IsSupported if |mime_type_lower_case| has a default codec
161 // associated with it and IsCodecSupported() returns IsSupported for that
162 // particular codec. |is_encrypted| means the codec will be used with
163 // encrypted blocks.
164 SupportsType IsDefaultCodecSupported(const std::string& mime_type_lower_case,
165 bool is_encrypted) const;
166
167 #if defined(OS_ANDROID) 191 #if defined(OS_ANDROID)
168 // Indicates the support of various codecs within the platform. 192 // Indicates the support of various codecs within the platform.
169 PlatformInfo platform_info_; 193 PlatformInfo platform_info_;
170 #endif 194 #endif
171 195
172 // A map of mime_types and hash map of the supported codecs for the mime_type. 196 // A map of mime_types and hash map of the supported codecs for the mime_type.
173 MediaFormatMappings media_format_map_; 197 MediaFormatMappings media_format_map_;
174 198
175 // List of proprietary containers in |media_format_map_|. 199 // List of proprietary containers in |media_format_map_|.
176 std::vector<std::string> proprietary_media_containers_; 200 std::vector<std::string> proprietary_media_containers_;
177 // Whether proprietary codec support should be advertised to callers. 201 // Whether proprietary codec support should be advertised to callers.
178 bool allow_proprietary_codecs_; 202 bool allow_proprietary_codecs_;
179 203
180 DISALLOW_COPY_AND_ASSIGN(MimeUtil); 204 DISALLOW_COPY_AND_ASSIGN(MimeUtil);
181 }; 205 };
182 206
183 } // namespace internal 207 } // namespace internal
184 } // namespace media 208 } // namespace media
185 209
186 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ 210 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_
OLDNEW
« no previous file with comments | « media/base/mime_util.cc ('k') | media/base/mime_util_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698