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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "media/base/mime_util.h" | 13 #include "media/base/mime_util.h" |
14 | 14 |
15 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
16 #include "base/android/build_info.h" | 16 #include "base/android/build_info.h" |
17 #endif | 17 #endif |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 // Singleton utility class for mime types. | 21 // Singleton utility class for mime types. |
22 class MimeUtil { | 22 class MimeUtil { |
23 public: | 23 public: |
24 enum Codec { | 24 enum Codec { |
25 INVALID_CODEC, | 25 INVALID_CODEC, |
26 PCM, | 26 PCM, |
27 MP3, | 27 MP3, |
| 28 AC3, |
| 29 EAC3, |
28 MPEG2_AAC_LC, | 30 MPEG2_AAC_LC, |
29 MPEG2_AAC_MAIN, | 31 MPEG2_AAC_MAIN, |
30 MPEG2_AAC_SSR, | 32 MPEG2_AAC_SSR, |
31 MPEG4_AAC_LC, | 33 MPEG4_AAC_LC, |
32 MPEG4_AAC_SBR_v1, | 34 MPEG4_AAC_SBR_v1, |
33 MPEG4_AAC_SBR_PS_v2, | 35 MPEG4_AAC_SBR_PS_v2, |
34 VORBIS, | 36 VORBIS, |
35 OPUS, | 37 OPUS, |
36 H264_BASELINE, | 38 H264_BASELINE, |
37 H264_MAIN, | 39 H264_MAIN, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 151 |
150 case MimeUtil::HEVC_MAIN: | 152 case MimeUtil::HEVC_MAIN: |
151 #if defined(ENABLE_HEVC_DEMUXING) | 153 #if defined(ENABLE_HEVC_DEMUXING) |
152 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to | 154 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to |
153 // http://developer.android.com/reference/android/media/MediaFormat.html | 155 // http://developer.android.com/reference/android/media/MediaFormat.html |
154 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 156 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
155 #else | 157 #else |
156 return false; | 158 return false; |
157 #endif | 159 #endif |
158 | 160 |
| 161 case MimeUtil::AC3: |
| 162 case MimeUtil::EAC3: |
| 163 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV |
| 164 return false; |
| 165 |
159 case MimeUtil::MPEG2_AAC_LC: | 166 case MimeUtil::MPEG2_AAC_LC: |
160 case MimeUtil::MPEG2_AAC_MAIN: | 167 case MimeUtil::MPEG2_AAC_MAIN: |
161 case MimeUtil::MPEG2_AAC_SSR: | 168 case MimeUtil::MPEG2_AAC_SSR: |
162 // MPEG-2 variants of AAC are not supported on Android. | 169 // MPEG-2 variants of AAC are not supported on Android. |
163 return false; | 170 return false; |
164 | 171 |
165 case MimeUtil::VP9: | 172 case MimeUtil::VP9: |
166 // VP9 is supported only in KitKat+ (API Level 19). | 173 // VP9 is supported only in KitKat+ (API Level 19). |
167 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 174 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
168 | 175 |
(...skipping 29 matching lines...) Expand all Loading... |
198 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) | 205 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) |
199 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for | 206 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for |
200 // compatibility) | 207 // compatibility) |
201 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) | 208 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) |
202 // | 209 // |
203 // avc1.42E0xx - H.264 Baseline | 210 // avc1.42E0xx - H.264 Baseline |
204 // avc1.4D40xx - H.264 Main | 211 // avc1.4D40xx - H.264 Main |
205 // avc1.6400xx - H.264 High | 212 // avc1.6400xx - H.264 High |
206 static const char kMP4AudioCodecsExpression[] = | 213 static const char kMP4AudioCodecsExpression[] = |
207 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 214 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 215 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 216 // Only one variant each of ac3 and eac3 codec string is sufficient here, |
| 217 // since these strings are parsed and mapped to MimeUtil::Codec enum values. |
| 218 "ac-3,ec-3," |
| 219 #endif |
208 "mp4a.40.05,mp4a.40.29"; | 220 "mp4a.40.05,mp4a.40.29"; |
209 static const char kMP4VideoCodecsExpression[] = | 221 static const char kMP4VideoCodecsExpression[] = |
210 // This is not a complete list of supported avc1 codecs. It is simply used | 222 // This is not a complete list of supported avc1 codecs. It is simply used |
211 // to register support for the corresponding Codec enum. Instead of using | 223 // to register support for the corresponding Codec enum. Instead of using |
212 // strings in these three arrays, we should use the Codec enum values. | 224 // strings in these three arrays, we should use the Codec enum values. |
213 // This will avoid confusion and unnecessary parsing at runtime. | 225 // This will avoid confusion and unnecessary parsing at runtime. |
214 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only | 226 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only |
215 // mapping from strings to codecs. See crbug.com/461009. | 227 // mapping from strings to codecs. See crbug.com/461009. |
216 "avc1.42E00A,avc1.4D400A,avc1.64000A," | 228 "avc1.42E00A,avc1.4D400A,avc1.64000A," |
217 #if defined(ENABLE_HEVC_DEMUXING) | 229 #if defined(ENABLE_HEVC_DEMUXING) |
218 // Any valid unambiguous HEVC codec id will work here, since these strings | 230 // Any valid unambiguous HEVC codec id will work here, since these strings |
219 // are parsed and mapped to MimeUtil::Codec enum values. | 231 // are parsed and mapped to MimeUtil::Codec enum values. |
220 "hev1.1.6.L93.B0," | 232 "hev1.1.6.L93.B0," |
221 #endif | 233 #endif |
222 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 234 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 235 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 236 // Only one variant each of ac3 and eac3 codec string is sufficient here, |
| 237 // since these strings are parsed and mapped to MimeUtil::Codec enum values. |
| 238 "ac-3,ec-3," |
| 239 #endif |
223 "mp4a.40.05,mp4a.40.29"; | 240 "mp4a.40.05,mp4a.40.29"; |
224 #endif // USE_PROPRIETARY_CODECS | 241 #endif // USE_PROPRIETARY_CODECS |
225 | 242 |
226 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and | 243 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and |
227 // corresponding media codecs supported by these types/containers. | 244 // corresponding media codecs supported by these types/containers. |
228 // Media formats marked as PROPRIETARY are not supported by Chromium, only | 245 // Media formats marked as PROPRIETARY are not supported by Chromium, only |
229 // Google Chrome browser supports them. | 246 // Google Chrome browser supports them. |
230 static const MediaFormat kFormatCodecMappings[] = { | 247 static const MediaFormat kFormatCodecMappings[] = { |
231 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 248 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
232 {"audio/webm", COMMON, "opus,vorbis"}, | 249 {"audio/webm", COMMON, "opus,vorbis"}, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, | 295 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
279 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, | 296 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, |
280 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, | 297 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, |
281 {"mp4a.69", MimeUtil::MP3}, | 298 {"mp4a.69", MimeUtil::MP3}, |
282 {"mp4a.6B", MimeUtil::MP3}, | 299 {"mp4a.6B", MimeUtil::MP3}, |
283 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, | 300 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, |
284 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, | 301 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, |
285 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, | 302 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, |
286 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, | 303 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, |
287 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, | 304 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, |
| 305 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 306 // TODO(servolk): Strictly speaking only mp4a.A5 and mp4a.A6 codec ids are |
| 307 // valid according to RFC 6381 section 3.3, 3.4. Lower-case oti (mp4a.a5 and |
| 308 // mp4a.a6) should be rejected. But we used to allow those in older versions |
| 309 // of Chromecast firmware and some apps (notably MPL) depend on those codec |
| 310 // types being supported, so they should be allowed for now |
| 311 // (crbug.com/564960). |
| 312 {"ac-3", MimeUtil::AC3}, |
| 313 {"mp4a.a5", MimeUtil::AC3}, |
| 314 {"mp4a.A5", MimeUtil::AC3}, |
| 315 {"ec-3", MimeUtil::EAC3}, |
| 316 {"mp4a.a6", MimeUtil::EAC3}, |
| 317 {"mp4a.A6", MimeUtil::EAC3}, |
| 318 #endif |
288 {"vorbis", MimeUtil::VORBIS}, | 319 {"vorbis", MimeUtil::VORBIS}, |
289 {"opus", MimeUtil::OPUS}, | 320 {"opus", MimeUtil::OPUS}, |
290 {"vp8", MimeUtil::VP8}, | 321 {"vp8", MimeUtil::VP8}, |
291 {"vp8.0", MimeUtil::VP8}, | 322 {"vp8.0", MimeUtil::VP8}, |
292 {"vp9", MimeUtil::VP9}, | 323 {"vp9", MimeUtil::VP9}, |
293 {"vp9.0", MimeUtil::VP9}, | 324 {"vp9.0", MimeUtil::VP9}, |
294 {"theora", MimeUtil::THEORA}}; | 325 {"theora", MimeUtil::THEORA}}; |
295 | 326 |
296 // List of codec IDs that are ambiguous and don't provide | 327 // List of codec IDs that are ambiguous and don't provide |
297 // enough information to determine the codec and profile. | 328 // enough information to determine the codec and profile. |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 if (!IsCodecSupportedOnAndroid(codec)) | 656 if (!IsCodecSupportedOnAndroid(codec)) |
626 return false; | 657 return false; |
627 #endif | 658 #endif |
628 | 659 |
629 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 660 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
630 } | 661 } |
631 | 662 |
632 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 663 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
633 switch (codec) { | 664 switch (codec) { |
634 case INVALID_CODEC: | 665 case INVALID_CODEC: |
| 666 case AC3: |
| 667 case EAC3: |
635 case MP3: | 668 case MP3: |
636 case MPEG2_AAC_LC: | 669 case MPEG2_AAC_LC: |
637 case MPEG2_AAC_MAIN: | 670 case MPEG2_AAC_MAIN: |
638 case MPEG2_AAC_SSR: | 671 case MPEG2_AAC_SSR: |
639 case MPEG4_AAC_LC: | 672 case MPEG4_AAC_LC: |
640 case MPEG4_AAC_SBR_v1: | 673 case MPEG4_AAC_SBR_v1: |
641 case MPEG4_AAC_SBR_PS_v2: | 674 case MPEG4_AAC_SBR_PS_v2: |
642 case H264_BASELINE: | 675 case H264_BASELINE: |
643 case H264_MAIN: | 676 case H264_MAIN: |
644 case H264_HIGH: | 677 case H264_HIGH: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 std::vector<std::string>* codecs_out, | 728 std::vector<std::string>* codecs_out, |
696 const bool strip) { | 729 const bool strip) { |
697 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 730 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
698 } | 731 } |
699 | 732 |
700 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 733 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
701 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 734 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
702 } | 735 } |
703 | 736 |
704 } // namespace media | 737 } // namespace media |
OLD | NEW |