Commit 293e1434 authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Misc cleanups for mime util GetStringToCodecMap()

- Define StringToCodecMap to avoid typing the long name multiple times.
- base::NoDestructor supports emplace; no need to create a map first.
- KEEP_FIRST_OF_DUPES is the default behavior; no need to specify.
- Remove #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING), because:
  * It's causing clang format to misbehave.
  * We should keep the mapping simple and should not restrict feature
    here, especially since MimeUtil::Codec::EAC3 is defined
    unconditionally.
- Reformatted by "git cl format"

Bug: 897767
Test: No functionality change.
Change-Id: Iac8d8b8ae5a9a1acbab89105c121f1d80badd536
Reviewed-on: https://chromium-review.googlesource.com/c/1294598Reviewed-by: default avatarSergey Volk <servolk@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601734}
parent 19846feb
...@@ -30,58 +30,64 @@ ...@@ -30,58 +30,64 @@
namespace media { namespace media {
namespace internal { namespace internal {
// A map from codec string to MimeUtil::Codec.
using StringToCodecMap = base::flat_map<std::string, MimeUtil::Codec>;
// Wrapped to avoid static initializer startup cost. // Wrapped to avoid static initializer startup cost.
const base::flat_map<std::string, MimeUtil::Codec>& GetStringToCodecMap() { const StringToCodecMap& GetStringToCodecMap() {
static const base::NoDestructor<base::flat_map<std::string, MimeUtil::Codec>> static const base::NoDestructor<StringToCodecMap> kStringToCodecMap({
kStringToCodecMap(base::flat_map<std::string, MimeUtil::Codec>( // We only allow this for WAV so it isn't ambiguous.
{ {"1", MimeUtil::PCM},
// We only allow this for WAV so it isn't ambiguous. // avc1/avc3.XXXXXX may be unambiguous; handled by
{"1", MimeUtil::PCM}, // ParseAVCCodecId(). hev1/hvc1.XXXXXX may be unambiguous;
// avc1/avc3.XXXXXX may be unambiguous; handled by // handled by ParseHEVCCodecID(). vp9, vp9.0,
// ParseAVCCodecId(). hev1/hvc1.XXXXXX may be unambiguous; // vp09.xx.xx.xx.xx.xx.xx.xx may be unambiguous; handled by
// handled by ParseHEVCCodecID(). vp9, vp9.0, // ParseVp9CodecID().
// vp09.xx.xx.xx.xx.xx.xx.xx may be unambiguous; handled by {"mp3", MimeUtil::MP3},
// ParseVp9CodecID(). // Following is the list of RFC 6381 compliant audio codec
{"mp3", MimeUtil::MP3}, // strings:
// Following is the list of RFC 6381 compliant audio codec // mp4a.66 - MPEG-2 AAC MAIN
// strings: // mp4a.67 - MPEG-2 AAC LC
// mp4a.66 - MPEG-2 AAC MAIN // mp4a.68 - MPEG-2 AAC SSR
// mp4a.67 - MPEG-2 AAC LC // mp4a.69 - MPEG-2 extension to MPEG-1 (MP3)
// mp4a.68 - MPEG-2 AAC SSR // mp4a.6B - MPEG-1 audio (MP3)
// mp4a.69 - MPEG-2 extension to MPEG-1 (MP3) // mp4a.40.2 - MPEG-4 AAC LC
// mp4a.6B - MPEG-1 audio (MP3) // mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for
// mp4a.40.2 - MPEG-4 AAC LC // compatibility)
// mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR)
// compatibility) // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0
// mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) // in aud-oti for compatibility)
// mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS)
// in aud-oti for compatibility) {"mp4a.66", MimeUtil::MPEG2_AAC},
// mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) {"mp4a.67", MimeUtil::MPEG2_AAC},
{"mp4a.66", MimeUtil::MPEG2_AAC}, {"mp4a.68", MimeUtil::MPEG2_AAC},
{"mp4a.67", MimeUtil::MPEG2_AAC}, {"mp4a.69", MimeUtil::MP3},
{"mp4a.68", MimeUtil::MPEG2_AAC}, {"mp4a.69", MimeUtil::MP3}, {"mp4a.6B", MimeUtil::MP3},
{"mp4a.6B", MimeUtil::MP3}, {"mp4a.40.2", MimeUtil::MPEG4_AAC}, {"mp4a.40.2", MimeUtil::MPEG4_AAC},
{"mp4a.40.02", MimeUtil::MPEG4_AAC}, {"mp4a.40.02", MimeUtil::MPEG4_AAC},
{"mp4a.40.5", MimeUtil::MPEG4_AAC}, {"mp4a.40.5", MimeUtil::MPEG4_AAC},
{"mp4a.40.05", MimeUtil::MPEG4_AAC}, {"mp4a.40.05", MimeUtil::MPEG4_AAC},
{"mp4a.40.29", MimeUtil::MPEG4_AAC}, {"mp4a.40.29", MimeUtil::MPEG4_AAC},
#if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) // TODO(servolk): Strictly speaking only mp4a.A5 and mp4a.A6
// TODO(servolk): Strictly speaking only mp4a.A5 and mp4a.A6 // codec ids are valid according to RFC 6381 section 3.3, 3.4.
// codec ids are valid according to RFC 6381 section 3.3, 3.4. // Lower-case oti (mp4a.a5 and mp4a.a6) should be rejected. But
// Lower-case oti (mp4a.a5 and mp4a.a6) should be rejected. But // we used to allow those in older versions of Chromecast
// we used to allow those in older versions of Chromecast // firmware and some apps (notably MPL) depend on those codec
// firmware and some apps (notably MPL) depend on those codec // types being supported, so they should be allowed for now
// types being supported, so they should be allowed for now // (crbug.com/564960).
// (crbug.com/564960). {"ac-3", MimeUtil::AC3},
{"ac-3", MimeUtil::AC3}, {"mp4a.a5", MimeUtil::AC3}, {"mp4a.a5", MimeUtil::AC3},
{"mp4a.A5", MimeUtil::AC3}, {"ec-3", MimeUtil::EAC3}, {"mp4a.A5", MimeUtil::AC3},
{"mp4a.a6", MimeUtil::EAC3}, {"mp4a.A6", MimeUtil::EAC3}, {"ec-3", MimeUtil::EAC3},
#endif {"mp4a.a6", MimeUtil::EAC3},
{"vorbis", MimeUtil::VORBIS}, {"opus", MimeUtil::OPUS}, {"mp4a.A6", MimeUtil::EAC3},
{"flac", MimeUtil::FLAC}, {"vp8", MimeUtil::VP8}, {"vorbis", MimeUtil::VORBIS},
{"vp8.0", MimeUtil::VP8}, {"theora", MimeUtil::THEORA}, {"opus", MimeUtil::OPUS},
}, {"flac", MimeUtil::FLAC},
base::KEEP_FIRST_OF_DUPES)); {"vp8", MimeUtil::VP8},
{"vp8.0", MimeUtil::VP8},
{"theora", MimeUtil::THEORA},
});
return *kStringToCodecMap; return *kStringToCodecMap;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment