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

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

Issue 1769833003: Consolidate MPEG*_AAC_* MimeUtil::Codec enum values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Consolidate comments about codec string variants. Created 4 years, 9 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_internal.h ('k') | media/base/mime_util_unittest.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 #include "media/base/mime_util_internal.h" 5 #include "media/base/mime_util_internal.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 10 matching lines...) Expand all
21 namespace internal { 21 namespace internal {
22 22
23 enum MediaFormatType { COMMON, PROPRIETARY }; 23 enum MediaFormatType { COMMON, PROPRIETARY };
24 24
25 struct MediaFormat { 25 struct MediaFormat {
26 const char* const mime_type; 26 const char* const mime_type;
27 MediaFormatType format_type; 27 MediaFormatType format_type;
28 const char* const codecs_list; 28 const char* const codecs_list;
29 }; 29 };
30 30
31 // Strings used as the |codecs_list| only need one valid unambiguous variant for
32 // each supported MimeUtil::Codec enum value. Each codec string is parsed and
33 // mapped to corresponding MimeUtil::Codec value. See https://crbug.com/461009.
31 #if defined(USE_PROPRIETARY_CODECS) 34 #if defined(USE_PROPRIETARY_CODECS)
32 // Following is the list of RFC 6381 compliant codecs:
33 // mp4a.66 - MPEG-2 AAC MAIN
34 // mp4a.67 - MPEG-2 AAC LC
35 // mp4a.68 - MPEG-2 AAC SSR
36 // mp4a.69 - MPEG-2 extension to MPEG-1
37 // mp4a.6B - MPEG-1 audio
38 // mp4a.40.2 - MPEG-4 AAC LC
39 // mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for compatibility)
40 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR)
41 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for
42 // compatibility)
43 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS)
44 //
45 // avc1.42E0xx - H.264 Baseline
46 // avc1.4D40xx - H.264 Main
47 // avc1.6400xx - H.264 High
48 static const char kMP4AudioCodecsExpression[] = 35 static const char kMP4AudioCodecsExpression[] =
49 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5,"
50 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 36 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
51 // Only one variant each of ac3 and eac3 codec string is sufficient here, 37 "ac-3,ec-3," // AC-3 and E-AC-3.
52 // since these strings are parsed and mapped to MimeUtil::Codec enum values.
53 "ac-3,ec-3,"
54 #endif 38 #endif
55 "mp4a.40.05,mp4a.40.29"; 39 "mp4a.66,mp4a.69,mp4a.40.2"; // MPEG-2 AAC, MP3, and MPEG-4 AAC.
56 static const char kMP4VideoCodecsExpression[] = 40 static const char kMP4VideoCodecsExpression[] =
57 // This is not a complete list of supported avc1 codecs. It is simply used 41 "avc1.42E00A,"
58 // to register support for the corresponding Codec enum. Instead of using
59 // strings in these three arrays, we should use the Codec enum values.
60 // This will avoid confusion and unnecessary parsing at runtime.
61 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only
62 // mapping from strings to codecs. See crbug.com/461009.
63 "avc1.42E00A,avc1.4D400A,avc1.64000A,"
64 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) 42 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
65 // Any valid unambiguous HEVC codec id will work here, since these strings
66 // are parsed and mapped to MimeUtil::Codec enum values.
67 "hev1.1.6.L93.B0," 43 "hev1.1.6.L93.B0,"
68 #endif 44 #endif
69 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5,"
70 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 45 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
71 // Only one variant each of ac3 and eac3 codec string is sufficient here, 46 "ac-3,ec-3," // AC-3 and E-AC-3.
72 // since these strings are parsed and mapped to MimeUtil::Codec enum values.
73 "ac-3,ec-3,"
74 #endif 47 #endif
75 "mp4a.40.05,mp4a.40.29"; 48 "mp4a.66,mp4a.69,mp4a.40.2"; // MPEG-2 AAC, MP3, and MPEG-4 AAC.
76 #endif // USE_PROPRIETARY_CODECS 49 #endif // USE_PROPRIETARY_CODECS
77 50
78 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and 51 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and
79 // corresponding media codecs supported by these types/containers. 52 // corresponding media codecs supported by these types/containers.
80 // Media formats marked as PROPRIETARY are not supported by Chromium, only 53 // Media formats marked as PROPRIETARY are not supported by Chromium, only
81 // Google Chrome browser supports them. 54 // Google Chrome browser supports them.
82 static const MediaFormat kFormatCodecMappings[] = { 55 static const MediaFormat kFormatCodecMappings[] = {
83 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, 56 {"video/webm", COMMON, "opus,vorbis,vp8,vp9"},
84 {"audio/webm", COMMON, "opus,vorbis"}, 57 {"audio/webm", COMMON, "opus,vorbis"},
85 {"audio/wav", COMMON, "1"}, 58 {"audio/wav", COMMON, "1"},
86 {"audio/x-wav", COMMON, "1"}, 59 {"audio/x-wav", COMMON, "1"},
87 #if defined(OS_ANDROID) 60 #if defined(OS_ANDROID)
88 // Android does not support Opus in Ogg container. 61 // Android does not support Opus in Ogg container.
89 // Android does not support Theora and thus video/ogg. 62 // Android does not support Theora and thus video/ogg.
90 {"audio/ogg", COMMON, "vorbis"}, 63 {"audio/ogg", COMMON, "vorbis"},
91 {"application/ogg", COMMON, "vorbis"}, 64 {"application/ogg", COMMON, "vorbis"},
92 #else 65 #else
93 {"video/ogg", COMMON, "opus,theora,vorbis"}, 66 {"video/ogg", COMMON, "opus,theora,vorbis"},
(...skipping 27 matching lines...) Expand all
121 94
122 // List of codec IDs that provide enough information to determine the 95 // List of codec IDs that provide enough information to determine the
123 // codec and profile being requested. 96 // codec and profile being requested.
124 // 97 //
125 // The "mp4a" strings come from RFC 6381. 98 // The "mp4a" strings come from RFC 6381.
126 static const CodecIDMappings kUnambiguousCodecStringMap[] = { 99 static const CodecIDMappings kUnambiguousCodecStringMap[] = {
127 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. 100 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous.
128 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseAVCCodecId(). 101 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseAVCCodecId().
129 // hev1/hvc1.XXXXXX may be unambiguous; handled by ParseHEVCCodecID(). 102 // hev1/hvc1.XXXXXX may be unambiguous; handled by ParseHEVCCodecID().
130 {"mp3", MimeUtil::MP3}, 103 {"mp3", MimeUtil::MP3},
131 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, 104 // Following is the list of RFC 6381 compliant audio codecs:
132 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, 105 // mp4a.66 - MPEG-2 AAC MAIN
133 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, 106 // mp4a.67 - MPEG-2 AAC LC
107 // mp4a.68 - MPEG-2 AAC SSR
108 // mp4a.69 - MPEG-2 extension to MPEG-1 (MP3)
109 // mp4a.6B - MPEG-1 audio (MP3)
110 // mp4a.40.2 - MPEG-4 AAC LC
111 // mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for compatibility)
112 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR)
113 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for
114 // compatibility)
115 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS)
116 {"mp4a.66", MimeUtil::MPEG2_AAC},
117 {"mp4a.67", MimeUtil::MPEG2_AAC},
118 {"mp4a.68", MimeUtil::MPEG2_AAC},
134 {"mp4a.69", MimeUtil::MP3}, 119 {"mp4a.69", MimeUtil::MP3},
135 {"mp4a.6B", MimeUtil::MP3}, 120 {"mp4a.6B", MimeUtil::MP3},
136 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, 121 {"mp4a.40.2", MimeUtil::MPEG4_AAC},
137 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, 122 {"mp4a.40.02", MimeUtil::MPEG4_AAC},
138 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, 123 {"mp4a.40.5", MimeUtil::MPEG4_AAC},
139 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, 124 {"mp4a.40.05", MimeUtil::MPEG4_AAC},
140 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, 125 {"mp4a.40.29", MimeUtil::MPEG4_AAC},
141 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 126 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
142 // TODO(servolk): Strictly speaking only mp4a.A5 and mp4a.A6 codec ids are 127 // TODO(servolk): Strictly speaking only mp4a.A5 and mp4a.A6 codec ids are
143 // valid according to RFC 6381 section 3.3, 3.4. Lower-case oti (mp4a.a5 and 128 // valid according to RFC 6381 section 3.3, 3.4. Lower-case oti (mp4a.a5 and
144 // mp4a.a6) should be rejected. But we used to allow those in older versions 129 // mp4a.a6) should be rejected. But we used to allow those in older versions
145 // of Chromecast firmware and some apps (notably MPL) depend on those codec 130 // of Chromecast firmware and some apps (notably MPL) depend on those codec
146 // types being supported, so they should be allowed for now 131 // types being supported, so they should be allowed for now
147 // (crbug.com/564960). 132 // (crbug.com/564960).
148 {"ac-3", MimeUtil::AC3}, 133 {"ac-3", MimeUtil::AC3},
149 {"mp4a.a5", MimeUtil::AC3}, 134 {"mp4a.a5", MimeUtil::AC3},
150 {"mp4a.A5", MimeUtil::AC3}, 135 {"mp4a.A5", MimeUtil::AC3},
151 {"ec-3", MimeUtil::EAC3}, 136 {"ec-3", MimeUtil::EAC3},
152 {"mp4a.a6", MimeUtil::EAC3}, 137 {"mp4a.a6", MimeUtil::EAC3},
153 {"mp4a.A6", MimeUtil::EAC3}, 138 {"mp4a.A6", MimeUtil::EAC3},
154 #endif 139 #endif
155 {"vorbis", MimeUtil::VORBIS}, 140 {"vorbis", MimeUtil::VORBIS},
156 {"opus", MimeUtil::OPUS}, 141 {"opus", MimeUtil::OPUS},
157 {"vp8", MimeUtil::VP8}, 142 {"vp8", MimeUtil::VP8},
158 {"vp8.0", MimeUtil::VP8}, 143 {"vp8.0", MimeUtil::VP8},
159 {"vp9", MimeUtil::VP9}, 144 {"vp9", MimeUtil::VP9},
160 {"vp9.0", MimeUtil::VP9}, 145 {"vp9.0", MimeUtil::VP9},
161 {"theora", MimeUtil::THEORA}}; 146 {"theora", MimeUtil::THEORA}};
162 147
163 // List of codec IDs that are ambiguous and don't provide 148 // List of codec IDs that are ambiguous and don't provide
164 // enough information to determine the codec and profile. 149 // enough information to determine the codec and profile.
165 // The codec in these entries indicate the codec and profile 150 // The codec in these entries indicate the codec and profile
166 // we assume the user is trying to indicate. 151 // we assume the user is trying to indicate.
167 static const CodecIDMappings kAmbiguousCodecStringMap[] = { 152 static const CodecIDMappings kAmbiguousCodecStringMap[] = {
168 {"mp4a.40", MimeUtil::MPEG4_AAC_LC}, 153 {"mp4a.40", MimeUtil::MPEG4_AAC},
169 {"avc1", MimeUtil::H264}, 154 {"avc1", MimeUtil::H264},
170 {"avc3", MimeUtil::H264}, 155 {"avc3", MimeUtil::H264},
171 // avc1/avc3.XXXXXX may be ambiguous; handled by ParseAVCCodecId(). 156 // avc1/avc3.XXXXXX may be ambiguous; handled by ParseAVCCodecId().
172 }; 157 };
173 158
174 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) 159 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
175 static const char kHexString[] = "0123456789ABCDEF"; 160 static const char kHexString[] = "0123456789ABCDEF";
176 static char IntToHex(int i) { 161 static char IntToHex(int i) {
177 DCHECK_GE(i, 0) << i << " not a hex value"; 162 DCHECK_GE(i, 0) << i << " not a hex value";
178 DCHECK_LE(i, 15) << i << " not a hex value"; 163 DCHECK_LE(i, 15) << i << " not a hex value";
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 case EAC3: 440 case EAC3:
456 case THEORA: 441 case THEORA:
457 return false; 442 return false;
458 443
459 // ---------------------------------------------------------------------- 444 // ----------------------------------------------------------------------
460 // The remaining codecs may be supported depending on platform abilities. 445 // The remaining codecs may be supported depending on platform abilities.
461 // ---------------------------------------------------------------------- 446 // ----------------------------------------------------------------------
462 447
463 case PCM: 448 case PCM:
464 case MP3: 449 case MP3:
465 case MPEG4_AAC_LC: 450 case MPEG4_AAC:
466 case MPEG4_AAC_SBR_v1:
467 case MPEG4_AAC_SBR_PS_v2:
468 case VORBIS: 451 case VORBIS:
469 // These codecs are always supported; via a platform decoder (when used 452 // These codecs are always supported; via a platform decoder (when used
470 // with MSE/EME), a software decoder (the unified pipeline), or with 453 // with MSE/EME), a software decoder (the unified pipeline), or with
471 // MediaPlayer. 454 // MediaPlayer.
472 DCHECK(!is_encrypted || platform_info.has_platform_decoders); 455 DCHECK(!is_encrypted || platform_info.has_platform_decoders);
473 return true; 456 return true;
474 457
475 case MPEG2_AAC_LC: 458 case MPEG2_AAC:
476 case MPEG2_AAC_MAIN:
477 case MPEG2_AAC_SSR:
478 // MPEG-2 variants of AAC are not supported on Android unless the unified 459 // MPEG-2 variants of AAC are not supported on Android unless the unified
479 // media pipeline can be used. These codecs will be decoded in software. 460 // media pipeline can be used. These codecs will be decoded in software.
461 // See https:crbug.com/544268 for details.
480 return !is_encrypted && platform_info.is_unified_media_pipeline_enabled; 462 return !is_encrypted && platform_info.is_unified_media_pipeline_enabled;
481 463
482 case OPUS: 464 case OPUS:
483 // If clear, the unified pipeline can always decode Opus in software. 465 // If clear, the unified pipeline can always decode Opus in software.
484 if (!is_encrypted && platform_info.is_unified_media_pipeline_enabled) 466 if (!is_encrypted && platform_info.is_unified_media_pipeline_enabled)
485 return true; 467 return true;
486 468
487 // Otherwise, platform support is required. 469 // Otherwise, platform support is required.
488 if (!platform_info.supports_opus) 470 if (!platform_info.supports_opus)
489 return false; 471 return false;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 581
600 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); 582 return allow_proprietary_codecs_ || !IsCodecProprietary(codec);
601 } 583 }
602 584
603 bool MimeUtil::IsCodecProprietary(Codec codec) const { 585 bool MimeUtil::IsCodecProprietary(Codec codec) const {
604 switch (codec) { 586 switch (codec) {
605 case INVALID_CODEC: 587 case INVALID_CODEC:
606 case AC3: 588 case AC3:
607 case EAC3: 589 case EAC3:
608 case MP3: 590 case MP3:
609 case MPEG2_AAC_LC: 591 case MPEG2_AAC:
610 case MPEG2_AAC_MAIN: 592 case MPEG4_AAC:
611 case MPEG2_AAC_SSR:
612 case MPEG4_AAC_LC:
613 case MPEG4_AAC_SBR_v1:
614 case MPEG4_AAC_SBR_PS_v2:
615 case H264: 593 case H264:
616 case HEVC_MAIN: 594 case HEVC_MAIN:
617 return true; 595 return true;
618 596
619 case PCM: 597 case PCM:
620 case VORBIS: 598 case VORBIS:
621 case OPUS: 599 case OPUS:
622 case VP8: 600 case VP8:
623 case VP9: 601 case VP9:
624 case THEORA: 602 case THEORA:
625 return false; 603 return false;
626 } 604 }
627 605
628 return true; 606 return true;
629 } 607 }
630 608
631 bool MimeUtil::GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, 609 bool MimeUtil::GetDefaultCodecLowerCase(const std::string& mime_type_lower_case,
632 Codec* default_codec) const { 610 Codec* default_codec) const {
633 if (mime_type_lower_case == "audio/mpeg" || 611 if (mime_type_lower_case == "audio/mpeg" ||
634 mime_type_lower_case == "audio/mp3" || 612 mime_type_lower_case == "audio/mp3" ||
635 mime_type_lower_case == "audio/x-mp3") { 613 mime_type_lower_case == "audio/x-mp3") {
636 *default_codec = MimeUtil::MP3; 614 *default_codec = MimeUtil::MP3;
637 return true; 615 return true;
638 } 616 }
639 617
640 if (mime_type_lower_case == "audio/aac") { 618 if (mime_type_lower_case == "audio/aac") {
641 *default_codec = MimeUtil::MPEG4_AAC_LC; 619 *default_codec = MimeUtil::MPEG4_AAC;
642 return true; 620 return true;
643 } 621 }
644 622
645 return false; 623 return false;
646 } 624 }
647 625
648 bool MimeUtil::IsDefaultCodecSupportedLowerCase( 626 bool MimeUtil::IsDefaultCodecSupportedLowerCase(
649 const std::string& mime_type_lower_case, 627 const std::string& mime_type_lower_case,
650 bool is_encrypted) const { 628 bool is_encrypted) const {
651 Codec default_codec = Codec::INVALID_CODEC; 629 Codec default_codec = Codec::INVALID_CODEC;
652 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) 630 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec))
653 return false; 631 return false;
654 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); 632 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted);
655 } 633 }
656 634
657 } // namespace internal 635 } // namespace internal
658 } // namespace media 636 } // namespace media
OLDNEW
« no previous file with comments | « media/base/mime_util_internal.h ('k') | media/base/mime_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698