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