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

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