OLD | NEW |
---|---|
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 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "media/base/media.h" | |
17 #include "media/base/mime_util.h" | 18 #include "media/base/mime_util.h" |
18 #include "media/media_features.h" | 19 #include "media/media_features.h" |
19 | 20 |
20 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
21 #include "base/android/build_info.h" | 22 #include "base/android/build_info.h" |
23 #include "media/base/android/media_codec_util.h" | |
22 #endif | 24 #endif |
23 | 25 |
24 namespace media { | 26 namespace media { |
25 | 27 |
26 // Singleton utility class for mime types. | 28 // Singleton utility class for mime types. |
27 class MimeUtil { | 29 class MimeUtil { |
28 public: | 30 public: |
29 enum Codec { | 31 enum Codec { |
30 INVALID_CODEC, | 32 INVALID_CODEC, |
31 PCM, | 33 PCM, |
(...skipping 17 matching lines...) Expand all Loading... | |
49 THEORA | 51 THEORA |
50 }; | 52 }; |
51 | 53 |
52 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 54 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
53 | 55 |
54 void ParseCodecString(const std::string& codecs, | 56 void ParseCodecString(const std::string& codecs, |
55 std::vector<std::string>* codecs_out, | 57 std::vector<std::string>* codecs_out, |
56 bool strip); | 58 bool strip); |
57 | 59 |
58 SupportsType IsSupportedMediaFormat( | 60 SupportsType IsSupportedMediaFormat( |
61 bool is_encrypted, | |
ddorwin
2016/02/16 20:34:37
nit: It seems odd that |is_encrypted| is the first
DaleCurtis
2016/02/17 03:01:05
Had to redo all of these changes after the split,
| |
59 const std::string& mime_type, | 62 const std::string& mime_type, |
60 const std::vector<std::string>& codecs) const; | 63 const std::vector<std::string>& codecs) const; |
61 | 64 |
62 void RemoveProprietaryMediaTypesAndCodecsForTests(); | 65 void RemoveProprietaryMediaTypesAndCodecsForTests(); |
63 | 66 |
64 private: | 67 private: |
65 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; | 68 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; |
66 | 69 |
67 typedef base::hash_set<int> CodecSet; | 70 typedef base::hash_set<int> CodecSet; |
68 typedef std::map<std::string, CodecSet> MediaFormatMappings; | 71 typedef std::map<std::string, CodecSet> MediaFormatMappings; |
69 struct CodecEntry { | 72 struct CodecEntry { |
70 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} | 73 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} |
71 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} | 74 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} |
72 Codec codec; | 75 Codec codec; |
73 bool is_ambiguous; | 76 bool is_ambiguous; |
74 }; | 77 }; |
75 typedef std::map<std::string, CodecEntry> StringToCodecMappings; | 78 typedef std::map<std::string, CodecEntry> StringToCodecMappings; |
76 | 79 |
77 MimeUtil(); | 80 MimeUtil(); |
78 | 81 |
79 // For faster lookup, keep hash sets. | 82 // For faster lookup, keep hash sets. |
80 void InitializeMimeTypeMaps(); | 83 void InitializeMimeTypeMaps(); |
81 | 84 |
82 // Returns IsSupported if all codec IDs in |codecs| are unambiguous | 85 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are |
83 // and are supported by the platform. MayBeSupported is returned if | 86 // supported by the platform when contained in |mime_type_lower_case|. |
ddorwin
2016/02/16 20:34:37
"platform" - This was the existing phrasing, but e
DaleCurtis
2016/02/17 03:01:05
Deleted platform from wording here.
| |
84 // at least one codec ID in |codecs| is ambiguous but all the codecs | 87 // MayBeSupported is returned if at least one codec ID in |codecs| is |
85 // are supported by the platform. IsNotSupported is returned if at | 88 // ambiguous but all the codecs are supported by the platform. IsNotSupported |
86 // least one codec ID is not supported by the platform. | 89 // is returned if at least one codec ID is not supported by the platform. |
ddorwin
2016/02/16 20:34:37
nit: two spaces
DaleCurtis
2016/02/17 03:01:05
Done.
| |
87 SupportsType AreSupportedCodecs( | 90 // |is_encrypted| means the codec will be used with encrypted samples. |
ddorwin
2016/02/16 20:34:37
nit: s/samples/blocks/?
DaleCurtis
2016/02/17 03:01:05
Done.
| |
88 const CodecSet& supported_codecs, | 91 SupportsType AreSupportedCodecs(bool is_encrypted, |
89 const std::vector<std::string>& codecs) const; | 92 const std::string& mime_type_lower_case, |
93 const CodecSet& supported_codecs, | |
94 const std::vector<std::string>& codecs) const; | |
90 | 95 |
91 // Converts a codec ID into an Codec enum value and indicates | 96 // Converts a codec ID into an Codec enum value and indicates |
92 // whether the conversion was ambiguous. | 97 // whether the conversion was ambiguous. |
93 // Returns true if this method was able to map |codec_id| to a specific | 98 // Returns true if this method was able to map |codec_id| to a specific |
94 // Codec enum value. |codec| and |is_ambiguous| are only valid if true | 99 // Codec enum value. |codec| and |is_ambiguous| are only valid if true |
95 // is returned. Otherwise their value is undefined after the call. | 100 // is returned. Otherwise their value is undefined after the call. |
96 // |is_ambiguous| is true if |codec_id| did not have enough information to | 101 // |is_ambiguous| is true if |codec_id| did not have enough information to |
97 // unambiguously determine the proper Codec enum value. If |is_ambiguous| | 102 // unambiguously determine the proper Codec enum value. If |is_ambiguous| |
98 // is true |codec| contains the best guess for the intended Codec enum value. | 103 // is true |codec| contains the best guess for the intended Codec enum value. |
99 bool StringToCodec(const std::string& codec_id, | 104 bool StringToCodec(const std::string& codec_id, |
100 Codec* codec, | 105 Codec* codec, |
101 bool* is_ambiguous) const; | 106 bool* is_ambiguous) const; |
102 | 107 |
103 // Returns true if |codec| is supported by the platform. | 108 // Returns true if |codec| and |mime_type_lower_case| are supported by the |
ddorwin
2016/02/16 20:34:37
Add "when contained in" as above?
DaleCurtis
2016/02/17 03:01:05
Done.
| |
104 // Note: This method will return false if the platform supports proprietary | 109 // platform. Note: This method will return false if the platform supports |
ddorwin
2016/02/16 20:34:37
ditto for "platform"
DaleCurtis
2016/02/17 03:01:05
Done.
| |
105 // codecs but |allow_proprietary_codecs_| is set to false. | 110 // proprietary codecs but |allow_proprietary_codecs_| is set to false. |
106 bool IsCodecSupported(Codec codec) const; | 111 // |is_encrypted| means the codec will be used with encrypted samples. |
ddorwin
2016/02/16 20:34:37
ditto for "samples"
DaleCurtis
2016/02/17 03:01:05
Done.
| |
112 bool IsCodecSupported(bool is_encrypted, | |
113 const std::string& mime_type_lower_case, | |
114 Codec codec) const; | |
107 | 115 |
108 // Returns true if |codec| refers to a proprietary codec. | 116 // Returns true if |codec| refers to a proprietary codec. |
109 bool IsCodecProprietary(Codec codec) const; | 117 bool IsCodecProprietary(Codec codec) const; |
110 | 118 |
111 // Returns true and sets |*default_codec| if |mime_type| has a default codec | 119 // Returns true and sets |*default_codec| if |mime_type| has a default codec |
112 // associated with it. Returns false otherwise and the value of | 120 // associated with it. Returns false otherwise and the value of |
113 // |*default_codec| is undefined. | 121 // |*default_codec| is undefined. |
114 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | 122 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, |
115 Codec* default_codec) const; | 123 Codec* default_codec) const; |
116 | 124 |
117 // Returns true if |mime_type_lower_case| has a default codec associated with | 125 // Returns true if |mime_type_lower_case| has a default codec associated with |
118 // it and IsCodecSupported() returns true for that particular codec. | 126 // it and IsCodecSupported() returns true for that particular codec. |
127 // |is_encrypted| means the codec will be used with encrypted samples. | |
119 bool IsDefaultCodecSupportedLowerCase( | 128 bool IsDefaultCodecSupportedLowerCase( |
129 bool is_encrypted, | |
120 const std::string& mime_type_lower_case) const; | 130 const std::string& mime_type_lower_case) const; |
121 | 131 |
122 // A map of mime_types and hash map of the supported codecs for the mime_type. | 132 // A map of mime_types and hash map of the supported codecs for the mime_type. |
123 MediaFormatMappings media_format_map_; | 133 MediaFormatMappings media_format_map_; |
124 | 134 |
125 // Keeps track of whether proprietary codec support should be | 135 // Keeps track of whether proprietary codec support should be |
126 // advertised to callers. | 136 // advertised to callers. |
127 bool allow_proprietary_codecs_; | 137 bool allow_proprietary_codecs_; |
128 | 138 |
129 // Lookup table for string compare based string -> Codec mappings. | 139 // Lookup table for string compare based string -> Codec mappings. |
130 StringToCodecMappings string_to_codec_map_; | 140 StringToCodecMappings string_to_codec_map_; |
131 | 141 |
132 DISALLOW_COPY_AND_ASSIGN(MimeUtil); | 142 DISALLOW_COPY_AND_ASSIGN(MimeUtil); |
133 }; // class MimeUtil | 143 }; // class MimeUtil |
134 | 144 |
135 // This variable is Leaky because it is accessed from WorkerPool threads. | 145 // This variable is Leaky because it is accessed from WorkerPool threads. |
136 static base::LazyInstance<MimeUtil>::Leaky g_media_mime_util = | 146 static base::LazyInstance<MimeUtil>::Leaky g_media_mime_util = |
137 LAZY_INSTANCE_INITIALIZER; | 147 LAZY_INSTANCE_INITIALIZER; |
138 | 148 |
139 #if defined(OS_ANDROID) | 149 #if defined(OS_ANDROID) |
140 static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { | 150 static bool IsCodecSupportedOnAndroid(bool is_encrypted, |
151 const std::string& mime_type_lower_case, | |
152 MimeUtil::Codec codec) { | |
141 switch (codec) { | 153 switch (codec) { |
142 case MimeUtil::INVALID_CODEC: | 154 case MimeUtil::INVALID_CODEC: |
143 return false; | 155 return false; |
144 | 156 |
145 case MimeUtil::PCM: | 157 case MimeUtil::PCM: |
146 case MimeUtil::MP3: | 158 case MimeUtil::MP3: |
147 case MimeUtil::MPEG4_AAC_LC: | 159 case MimeUtil::MPEG4_AAC_LC: |
148 case MimeUtil::MPEG4_AAC_SBR_v1: | 160 case MimeUtil::MPEG4_AAC_SBR_v1: |
149 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | 161 case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
150 case MimeUtil::VORBIS: | 162 case MimeUtil::VORBIS: |
163 return is_encrypted ? MediaCodecUtil::IsMediaCodecAvailable() : true; | |
ddorwin
2016/02/16 20:34:37
Note: The !is_encrypted path works for MSE because
DaleCurtis
2016/02/17 03:01:05
As discussed via chat, added a comment above the s
| |
164 | |
151 case MimeUtil::H264_BASELINE: | 165 case MimeUtil::H264_BASELINE: |
152 case MimeUtil::H264_MAIN: | 166 case MimeUtil::H264_MAIN: |
153 case MimeUtil::H264_HIGH: | 167 case MimeUtil::H264_HIGH: |
168 if (IsUnifiedMediaPipelineEnabled()) { | |
169 return HasPlatformDecoderSupport() && | |
ddorwin
2016/02/16 20:34:37
All HasPlatformDecoderSupport() means is that the
DaleCurtis
2016/02/17 03:01:05
It can mean: no gpu process, vda is blacklisted, o
ddorwin
2016/02/17 21:18:38
The MediaCodec check was added in the next patch s
| |
170 MediaCodecUtil::IsMediaCodecAvailable(); | |
171 } | |
172 return is_encrypted ? MediaCodecUtil::IsMediaCodecAvailable() : true; | |
ddorwin
2016/02/16 20:34:37
Why are encrypted videos not also subject to HasPl
DaleCurtis
2016/02/17 03:01:05
Done.
| |
173 | |
154 case MimeUtil::VP8: | 174 case MimeUtil::VP8: |
155 return true; | 175 if (!is_encrypted) |
ddorwin
2016/02/16 20:34:37
Doesn't encrypted require IsMediaCodecAvailable()
DaleCurtis
2016/02/17 03:01:05
Done.
| |
176 return true; | |
177 | |
178 if (MediaCodecUtil::IsVp8Blacklisted()) | |
ddorwin
2016/02/16 20:34:37
Is VP8 blacklisted for Android MediaPlayer too?
I
DaleCurtis
2016/02/17 03:01:05
No it's only blacklisted for MediaCodec, I've clea
| |
179 return false; | |
180 | |
181 return IsUnifiedMediaPipelineEnabled() ? HasPlatformDecoderSupport() | |
ddorwin
2016/02/16 20:34:37
libvpx can't used for VP8?
DaleCurtis
2016/02/17 03:01:05
This was for encrypted cases, but is unclear, I've
| |
182 : true; | |
156 | 183 |
157 case MimeUtil::AC3: | 184 case MimeUtil::AC3: |
158 case MimeUtil::EAC3: | 185 case MimeUtil::EAC3: |
159 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV | 186 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV |
160 return false; | 187 return false; |
161 | 188 |
162 case MimeUtil::MPEG2_AAC_LC: | 189 case MimeUtil::MPEG2_AAC_LC: |
163 case MimeUtil::MPEG2_AAC_MAIN: | 190 case MimeUtil::MPEG2_AAC_MAIN: |
164 case MimeUtil::MPEG2_AAC_SSR: | 191 case MimeUtil::MPEG2_AAC_SSR: |
165 // MPEG-2 variants of AAC are not supported on Android. | 192 // MPEG-2 variants of AAC are not supported on Android unless the unified |
166 return false; | 193 // media pipeline can be used. |
ddorwin
2016/02/16 20:34:37
... and the software decoders...
DaleCurtis
2016/02/17 03:01:05
Done.
| |
194 return !is_encrypted && IsUnifiedMediaPipelineEnabled(); | |
167 | 195 |
168 case MimeUtil::OPUS: | 196 case MimeUtil::OPUS: |
169 // Opus is supported only in Lollipop+ (API Level 21). | 197 if (!is_encrypted && IsUnifiedMediaPipelineEnabled()) |
170 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 198 return true; |
ddorwin
2016/02/16 20:34:37
Perhaps:
// Software decoder.
DaleCurtis
2016/02/17 03:01:05
Done.
| |
199 | |
200 if (!MediaCodecUtil::PlatformHasOpusSupport()) | |
201 return false; | |
202 | |
203 // Android does not support opus in ogg containers. | |
204 if (base::EndsWith(mime_type_lower_case, "ogg", | |
205 base::CompareCase::SENSITIVE)) { | |
206 return false; | |
207 } | |
208 | |
209 return is_encrypted ? MediaCodecUtil::IsMediaCodecAvailable() : true; | |
171 | 210 |
172 case MimeUtil::HEVC_MAIN: | 211 case MimeUtil::HEVC_MAIN: |
173 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 212 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
174 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to | 213 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to |
175 // http://developer.android.com/reference/android/media/MediaFormat.html | 214 // http://developer.android.com/reference/android/media/MediaFormat.html |
176 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 215 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
177 #else | 216 #else |
178 return false; | 217 return false; |
179 #endif | 218 #endif |
180 | 219 |
181 case MimeUtil::VP9: | 220 case MimeUtil::VP9: { |
182 // VP9 is supported only in KitKat+ (API Level 19). | 221 const bool has_unified_media_pipeline = IsUnifiedMediaPipelineEnabled(); |
183 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 222 if (!is_encrypted && has_unified_media_pipeline) |
223 return true; | |
224 | |
225 if (!MediaCodecUtil::PlatformHasVp9Support()) | |
226 return false; | |
227 | |
228 if (!is_encrypted) | |
229 return true; | |
230 | |
231 if (!MediaCodecUtil::IsMediaCodecAvailable()) | |
232 return false; | |
233 | |
234 return has_unified_media_pipeline ? HasPlatformDecoderSupport() : true; | |
ddorwin
2016/02/16 20:34:37
Why is HasPlatformDecoderSupport() only required f
DaleCurtis
2016/02/17 03:01:05
Again this was confusing, though correct, simplifi
| |
235 } | |
184 | 236 |
185 case MimeUtil::THEORA: | 237 case MimeUtil::THEORA: |
186 return false; | 238 return false; |
187 } | 239 } |
188 | 240 |
189 return false; | 241 return false; |
190 } | 242 } |
191 #endif | 243 #endif |
192 | 244 |
193 enum MediaFormatType { COMMON, PROPRIETARY }; | 245 enum MediaFormatType { COMMON, PROPRIETARY }; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 | 299 |
248 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and | 300 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and |
249 // corresponding media codecs supported by these types/containers. | 301 // corresponding media codecs supported by these types/containers. |
250 // Media formats marked as PROPRIETARY are not supported by Chromium, only | 302 // Media formats marked as PROPRIETARY are not supported by Chromium, only |
251 // Google Chrome browser supports them. | 303 // Google Chrome browser supports them. |
252 static const MediaFormat kFormatCodecMappings[] = { | 304 static const MediaFormat kFormatCodecMappings[] = { |
253 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 305 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
254 {"audio/webm", COMMON, "opus,vorbis"}, | 306 {"audio/webm", COMMON, "opus,vorbis"}, |
255 {"audio/wav", COMMON, "1"}, | 307 {"audio/wav", COMMON, "1"}, |
256 {"audio/x-wav", COMMON, "1"}, | 308 {"audio/x-wav", COMMON, "1"}, |
257 #if defined(OS_ANDROID) | 309 #if !defined(OS_ANDROID) |
258 // Android does not support Opus in Ogg container. | 310 // Note: Android does not support Theora and thus video/ogg. |
259 // Android does not support Theora and thus video/ogg. | |
260 {"audio/ogg", COMMON, "vorbis"}, | |
261 {"application/ogg", COMMON, "vorbis"}, | |
262 #else | |
263 {"video/ogg", COMMON, "opus,theora,vorbis"}, | 311 {"video/ogg", COMMON, "opus,theora,vorbis"}, |
312 #endif | |
264 {"audio/ogg", COMMON, "opus,vorbis"}, | 313 {"audio/ogg", COMMON, "opus,vorbis"}, |
314 // Note: Theora is not supported on Android and will be rejected during the | |
315 // call to IsCodecSupportedOnAndroid(). | |
265 {"application/ogg", COMMON, "opus,theora,vorbis"}, | 316 {"application/ogg", COMMON, "opus,theora,vorbis"}, |
266 #endif | |
267 #if defined(USE_PROPRIETARY_CODECS) | 317 #if defined(USE_PROPRIETARY_CODECS) |
268 {"audio/mpeg", PROPRIETARY, "mp3"}, | 318 {"audio/mpeg", PROPRIETARY, "mp3"}, |
269 {"audio/mp3", PROPRIETARY, ""}, | 319 {"audio/mp3", PROPRIETARY, ""}, |
270 {"audio/x-mp3", PROPRIETARY, ""}, | 320 {"audio/x-mp3", PROPRIETARY, ""}, |
271 {"audio/aac", PROPRIETARY, ""}, // AAC / ADTS | 321 {"audio/aac", PROPRIETARY, ""}, // AAC / ADTS |
272 {"audio/mp4", PROPRIETARY, kMP4AudioCodecsExpression}, | 322 {"audio/mp4", PROPRIETARY, kMP4AudioCodecsExpression}, |
273 {"audio/x-m4a", PROPRIETARY, kMP4AudioCodecsExpression}, | 323 {"audio/x-m4a", PROPRIETARY, kMP4AudioCodecsExpression}, |
274 {"video/mp4", PROPRIETARY, kMP4VideoCodecsExpression}, | 324 {"video/mp4", PROPRIETARY, kMP4VideoCodecsExpression}, |
275 {"video/x-m4v", PROPRIETARY, kMP4VideoCodecsExpression}, | 325 {"video/x-m4v", PROPRIETARY, kMP4VideoCodecsExpression}, |
276 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 326 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 // This is not a valid legacy avc1 codec id - return the original codec id. | 438 // This is not a valid legacy avc1 codec id - return the original codec id. |
389 return codec_id; | 439 return codec_id; |
390 } | 440 } |
391 #endif | 441 #endif |
392 | 442 |
393 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { | 443 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { |
394 InitializeMimeTypeMaps(); | 444 InitializeMimeTypeMaps(); |
395 } | 445 } |
396 | 446 |
397 SupportsType MimeUtil::AreSupportedCodecs( | 447 SupportsType MimeUtil::AreSupportedCodecs( |
448 bool is_encrypted, | |
449 const std::string& mime_type_lower_case, | |
398 const CodecSet& supported_codecs, | 450 const CodecSet& supported_codecs, |
399 const std::vector<std::string>& codecs) const { | 451 const std::vector<std::string>& codecs) const { |
400 DCHECK(!supported_codecs.empty()); | 452 DCHECK(!supported_codecs.empty()); |
401 DCHECK(!codecs.empty()); | 453 DCHECK(!codecs.empty()); |
402 | 454 |
403 SupportsType result = IsSupported; | 455 SupportsType result = IsSupported; |
404 for (size_t i = 0; i < codecs.size(); ++i) { | 456 for (size_t i = 0; i < codecs.size(); ++i) { |
405 bool is_ambiguous = true; | 457 bool is_ambiguous = true; |
406 Codec codec = INVALID_CODEC; | 458 Codec codec = INVALID_CODEC; |
407 if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) | 459 if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) |
408 return IsNotSupported; | 460 return IsNotSupported; |
409 | 461 |
410 if (!IsCodecSupported(codec) || | 462 if (!IsCodecSupported(is_encrypted, mime_type_lower_case, codec) || |
411 supported_codecs.find(codec) == supported_codecs.end()) { | 463 supported_codecs.find(codec) == supported_codecs.end()) { |
412 return IsNotSupported; | 464 return IsNotSupported; |
413 } | 465 } |
414 | 466 |
415 if (is_ambiguous) | 467 if (is_ambiguous) |
416 result = MayBeSupported; | 468 result = MayBeSupported; |
417 } | 469 } |
418 | 470 |
419 return result; | 471 return result; |
420 } | 472 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 for (std::vector<std::string>::iterator it = codecs_out->begin(); | 529 for (std::vector<std::string>::iterator it = codecs_out->begin(); |
478 it != codecs_out->end(); | 530 it != codecs_out->end(); |
479 ++it) { | 531 ++it) { |
480 size_t found = it->find_first_of('.'); | 532 size_t found = it->find_first_of('.'); |
481 if (found != std::string::npos) | 533 if (found != std::string::npos) |
482 it->resize(found); | 534 it->resize(found); |
483 } | 535 } |
484 } | 536 } |
485 | 537 |
486 SupportsType MimeUtil::IsSupportedMediaFormat( | 538 SupportsType MimeUtil::IsSupportedMediaFormat( |
539 bool is_encrypted, | |
487 const std::string& mime_type, | 540 const std::string& mime_type, |
488 const std::vector<std::string>& codecs) const { | 541 const std::vector<std::string>& codecs) const { |
489 const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); | 542 const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); |
490 MediaFormatMappings::const_iterator it_media_format_map = | 543 MediaFormatMappings::const_iterator it_media_format_map = |
491 media_format_map_.find(mime_type_lower_case); | 544 media_format_map_.find(mime_type_lower_case); |
492 if (it_media_format_map == media_format_map_.end()) | 545 if (it_media_format_map == media_format_map_.end()) |
493 return IsNotSupported; | 546 return IsNotSupported; |
494 | 547 |
495 if (it_media_format_map->second.empty()) { | 548 if (it_media_format_map->second.empty()) { |
496 // We get here if the mimetype does not expect a codecs parameter. | 549 // We get here if the mimetype does not expect a codecs parameter. |
497 return (codecs.empty() && | 550 return (codecs.empty() && IsDefaultCodecSupportedLowerCase( |
498 IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) | 551 is_encrypted, mime_type_lower_case)) |
499 ? IsSupported | 552 ? IsSupported |
500 : IsNotSupported; | 553 : IsNotSupported; |
501 } | 554 } |
502 | 555 |
503 if (codecs.empty()) { | 556 if (codecs.empty()) { |
504 // We get here if the mimetype expects to get a codecs parameter, | 557 // We get here if the mimetype expects to get a codecs parameter, |
505 // but didn't get one. If |mime_type_lower_case| does not have a default | 558 // but didn't get one. If |mime_type_lower_case| does not have a default |
506 // codec the best we can do is say "maybe" because we don't have enough | 559 // codec the best we can do is say "maybe" because we don't have enough |
507 // information. | 560 // information. |
508 Codec default_codec = INVALID_CODEC; | 561 Codec default_codec = INVALID_CODEC; |
509 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 562 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
510 return MayBeSupported; | 563 return MayBeSupported; |
511 | 564 |
512 return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported; | 565 return IsCodecSupported(is_encrypted, mime_type_lower_case, default_codec) |
566 ? IsSupported | |
567 : IsNotSupported; | |
513 } | 568 } |
514 | 569 |
515 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 570 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
516 if (mime_type_lower_case == "video/mp2t") { | 571 if (mime_type_lower_case == "video/mp2t") { |
517 std::vector<std::string> codecs_to_check; | 572 std::vector<std::string> codecs_to_check; |
518 for (const auto& codec_id : codecs) { | 573 for (const auto& codec_id : codecs) { |
519 codecs_to_check.push_back(TranslateLegacyAvc1CodecIds(codec_id)); | 574 codecs_to_check.push_back(TranslateLegacyAvc1CodecIds(codec_id)); |
520 } | 575 } |
521 return AreSupportedCodecs(it_media_format_map->second, codecs_to_check); | 576 return AreSupportedCodecs(is_encrypted, mime_type_lower_case, |
577 it_media_format_map->second, codecs_to_check); | |
522 } | 578 } |
523 #endif | 579 #endif |
524 | 580 |
525 return AreSupportedCodecs(it_media_format_map->second, codecs); | 581 return AreSupportedCodecs(is_encrypted, mime_type_lower_case, |
582 it_media_format_map->second, codecs); | |
526 } | 583 } |
527 | 584 |
528 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 585 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
529 for (size_t i = 0; i < arraysize(kFormatCodecMappings); ++i) | 586 for (size_t i = 0; i < arraysize(kFormatCodecMappings); ++i) |
530 if (kFormatCodecMappings[i].format_type == PROPRIETARY) | 587 if (kFormatCodecMappings[i].format_type == PROPRIETARY) |
531 media_format_map_.erase(kFormatCodecMappings[i].mime_type); | 588 media_format_map_.erase(kFormatCodecMappings[i].mime_type); |
532 allow_proprietary_codecs_ = false; | 589 allow_proprietary_codecs_ = false; |
533 } | 590 } |
534 | 591 |
535 static bool IsValidH264Level(const std::string& level_str) { | 592 static bool IsValidH264Level(const std::string& level_str) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 // either H.264 or HEVC/H.265 codec ID because currently those are the only | 705 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
649 // ones that are not added to the |string_to_codec_map_| and require parsing. | 706 // ones that are not added to the |string_to_codec_map_| and require parsing. |
650 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 707 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
651 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | 708 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { |
652 return true; | 709 return true; |
653 } | 710 } |
654 #endif | 711 #endif |
655 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 712 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
656 } | 713 } |
657 | 714 |
658 bool MimeUtil::IsCodecSupported(Codec codec) const { | 715 bool MimeUtil::IsCodecSupported(bool is_encrypted, |
716 const std::string& mime_type_lower_case, | |
717 Codec codec) const { | |
659 DCHECK_NE(codec, INVALID_CODEC); | 718 DCHECK_NE(codec, INVALID_CODEC); |
660 | 719 |
661 #if defined(OS_ANDROID) | 720 #if defined(OS_ANDROID) |
662 if (!IsCodecSupportedOnAndroid(codec)) | 721 if (!IsCodecSupportedOnAndroid(is_encrypted, mime_type_lower_case, codec)) |
663 return false; | 722 return false; |
664 #endif | 723 #endif |
665 | 724 |
666 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 725 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
667 } | 726 } |
668 | 727 |
669 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 728 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
670 switch (codec) { | 729 switch (codec) { |
671 case INVALID_CODEC: | 730 case INVALID_CODEC: |
672 case AC3: | 731 case AC3: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 | 766 |
708 if (mime_type_lower_case == "audio/aac") { | 767 if (mime_type_lower_case == "audio/aac") { |
709 *default_codec = MimeUtil::MPEG4_AAC_LC; | 768 *default_codec = MimeUtil::MPEG4_AAC_LC; |
710 return true; | 769 return true; |
711 } | 770 } |
712 | 771 |
713 return false; | 772 return false; |
714 } | 773 } |
715 | 774 |
716 bool MimeUtil::IsDefaultCodecSupportedLowerCase( | 775 bool MimeUtil::IsDefaultCodecSupportedLowerCase( |
776 bool is_encrypted, | |
717 const std::string& mime_type_lower_case) const { | 777 const std::string& mime_type_lower_case) const { |
718 Codec default_codec = Codec::INVALID_CODEC; | 778 Codec default_codec = Codec::INVALID_CODEC; |
719 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 779 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
720 return false; | 780 return false; |
721 return IsCodecSupported(default_codec); | 781 return IsCodecSupported(is_encrypted, mime_type_lower_case, default_codec); |
722 } | 782 } |
723 | 783 |
724 bool IsSupportedMediaMimeType(const std::string& mime_type) { | 784 bool IsSupportedMediaMimeType(const std::string& mime_type) { |
725 return g_media_mime_util.Get().IsSupportedMediaMimeType(mime_type); | 785 return g_media_mime_util.Get().IsSupportedMediaMimeType(mime_type); |
726 } | 786 } |
727 | 787 |
728 SupportsType IsSupportedMediaFormat(const std::string& mime_type, | 788 SupportsType IsSupportedMediaFormat(const std::string& mime_type, |
ddorwin
2016/02/16 20:34:37
To avoid misuse in the future, should we rename th
DaleCurtis
2016/02/17 03:01:05
Acknowledged.
| |
729 const std::vector<std::string>& codecs) { | 789 const std::vector<std::string>& codecs) { |
730 return g_media_mime_util.Get().IsSupportedMediaFormat(mime_type, codecs); | 790 return g_media_mime_util.Get().IsSupportedMediaFormat(false, mime_type, |
791 codecs); | |
792 } | |
793 | |
794 SupportsType IsSupportedEncryptedMediaFormat( | |
795 const std::string& mime_type, | |
796 const std::vector<std::string>& codecs) { | |
797 return g_media_mime_util.Get().IsSupportedMediaFormat(true, mime_type, | |
798 codecs); | |
731 } | 799 } |
732 | 800 |
733 void ParseCodecString(const std::string& codecs, | 801 void ParseCodecString(const std::string& codecs, |
734 std::vector<std::string>* codecs_out, | 802 std::vector<std::string>* codecs_out, |
735 const bool strip) { | 803 const bool strip) { |
736 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 804 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
737 } | 805 } |
738 | 806 |
739 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 807 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
740 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 808 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
741 } | 809 } |
742 | 810 |
743 } // namespace media | 811 } // namespace media |
OLD | NEW |