|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Alliance for Open Media. All rights reserved |
| 3 | + * |
| 4 | + * This source code is subject to the terms of the BSD 3-Clause Clear License |
| 5 | + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
| 6 | + * License was not distributed with this source code in the LICENSE file, you |
| 7 | + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the |
| 8 | + * Alliance for Open Media Patent License 1.0 was not distributed with this |
| 9 | + * source code in the PATENTS file, you can obtain it at |
| 10 | + * www.aomedia.org/license/patent. |
| 11 | + */ |
| 12 | +#ifndef CLI_LOOKUP_TABLES_H_ |
| 13 | +#define CLI_LOOKUP_TABLES_H_ |
| 14 | + |
| 15 | +#include <array> |
| 16 | +#include <utility> |
| 17 | + |
| 18 | +#include "iamf/cli/proto/arbitrary_obu.pb.h" |
| 19 | +#include "iamf/cli/proto/audio_element.pb.h" |
| 20 | +#include "iamf/cli/proto/codec_config.pb.h" |
| 21 | +#include "iamf/cli/proto/ia_sequence_header.pb.h" |
| 22 | +#include "iamf/cli/proto/mix_presentation.pb.h" |
| 23 | +#include "iamf/cli/proto/param_definitions.pb.h" |
| 24 | +#include "iamf/cli/proto/parameter_block.pb.h" |
| 25 | +#include "iamf/cli/proto/parameter_data.pb.h" |
| 26 | +#include "iamf/obu/audio_element.h" |
| 27 | +#include "iamf/obu/codec_config.h" |
| 28 | +#include "iamf/obu/decoder_config/aac_decoder_config.h" |
| 29 | +#include "iamf/obu/decoder_config/flac_decoder_config.h" |
| 30 | +#include "iamf/obu/demixing_info_parameter_data.h" |
| 31 | +#include "iamf/obu/ia_sequence_header.h" |
| 32 | +#include "iamf/obu/mix_presentation.h" |
| 33 | +#include "iamf/obu/obu_header.h" |
| 34 | + |
| 35 | +namespace iamf_tools { |
| 36 | + |
| 37 | +/*!\brief Backing data for lookup tables. |
| 38 | + * |
| 39 | + * This class stores `inline static constexpr` pairs of values, which are |
| 40 | + * guaranteed to only have a single copy in the program. |
| 41 | + * |
| 42 | + * This data backs the creation of run-time lookup tables using |
| 43 | + * `ObuUtil::BuildStaticMapFromPairs`. Or the inverted version of those lookup |
| 44 | + * tables using `BuildStaticMapFromInvertedPairs`. |
| 45 | + */ |
| 46 | +class LookupTables { |
| 47 | + public: |
| 48 | + inline static constexpr auto kProtoAndInternalProfileVersions = []() { |
| 49 | + using enum iamf_tools_cli_proto::ProfileVersion; |
| 50 | + using enum ProfileVersion; |
| 51 | + return std::to_array< |
| 52 | + std::pair<iamf_tools_cli_proto::ProfileVersion, ProfileVersion>>({ |
| 53 | + {PROFILE_VERSION_SIMPLE, kIamfSimpleProfile}, |
| 54 | + {PROFILE_VERSION_BASE, kIamfBaseProfile}, |
| 55 | + {PROFILE_VERSION_BASE_ENHANCED, kIamfBaseEnhancedProfile}, |
| 56 | + {PROFILE_VERSION_RESERVED_255, kIamfReserved255Profile}, |
| 57 | + }); |
| 58 | + }(); |
| 59 | + |
| 60 | + inline static constexpr auto kProtoAndInternalDMixPModes = []() { |
| 61 | + using enum iamf_tools_cli_proto::DMixPMode; |
| 62 | + using enum DemixingInfoParameterData::DMixPMode; |
| 63 | + return std::to_array<std::pair<iamf_tools_cli_proto::DMixPMode, |
| 64 | + DemixingInfoParameterData::DMixPMode>>( |
| 65 | + {{DMIXP_MODE_1, kDMixPMode1}, |
| 66 | + {DMIXP_MODE_2, kDMixPMode2}, |
| 67 | + {DMIXP_MODE_3, kDMixPMode3}, |
| 68 | + {DMIXP_MODE_RESERVED_A, kDMixPModeReserved1}, |
| 69 | + {DMIXP_MODE_1_N, kDMixPMode1_n}, |
| 70 | + {DMIXP_MODE_2_N, kDMixPMode2_n}, |
| 71 | + {DMIXP_MODE_3_N, kDMixPMode3_n}, |
| 72 | + {DMIXP_MODE_RESERVED_B, kDMixPModeReserved2}}); |
| 73 | + }(); |
| 74 | + |
| 75 | + inline static constexpr auto kProtoAndInternalCodecIds = []() { |
| 76 | + using enum iamf_tools_cli_proto::CodecId; |
| 77 | + using enum CodecConfig::CodecId; |
| 78 | + return std::to_array< |
| 79 | + std::pair<iamf_tools_cli_proto::CodecId, CodecConfig::CodecId>>({ |
| 80 | + {CODEC_ID_OPUS, kCodecIdOpus}, |
| 81 | + {CODEC_ID_FLAC, kCodecIdFlac}, |
| 82 | + {CODEC_ID_AAC_LC, kCodecIdAacLc}, |
| 83 | + {CODEC_ID_LPCM, kCodecIdLpcm}, |
| 84 | + }); |
| 85 | + }(); |
| 86 | + |
| 87 | + inline static constexpr auto kProtoAndInternalFlacBlockTypes = []() { |
| 88 | + using enum iamf_tools_cli_proto::FlacBlockType; |
| 89 | + using enum FlacMetaBlockHeader::FlacBlockType; |
| 90 | + return std::to_array<std::pair<iamf_tools_cli_proto::FlacBlockType, |
| 91 | + FlacMetaBlockHeader::FlacBlockType>>( |
| 92 | + {{FLAC_BLOCK_TYPE_STREAMINFO, kFlacStreamInfo}, |
| 93 | + {FLAC_BLOCK_TYPE_PADDING, kFlacPadding}, |
| 94 | + {FLAC_BLOCK_TYPE_APPLICATION, kFlacApplication}, |
| 95 | + {FLAC_BLOCK_TYPE_SEEKTABLE, kFlacSeektable}, |
| 96 | + {FLAC_BLOCK_TYPE_VORBIS_COMMENT, kFlacVorbisComment}, |
| 97 | + {FLAC_BLOCK_TYPE_CUESHEET, kFlacCuesheet}, |
| 98 | + {FLAC_BLOCK_TYPE_PICTURE, kFlacPicture}}); |
| 99 | + }(); |
| 100 | + |
| 101 | + inline static constexpr auto kProtoAndInternalSampleFrequencyIndices = []() { |
| 102 | + using enum iamf_tools_cli_proto::SampleFrequencyIndex; |
| 103 | + using enum AudioSpecificConfig::SampleFrequencyIndex; |
| 104 | + return std::to_array<std::pair<iamf_tools_cli_proto::SampleFrequencyIndex, |
| 105 | + AudioSpecificConfig::SampleFrequencyIndex>>( |
| 106 | + {{AAC_SAMPLE_FREQUENCY_INDEX_96000, kSampleFrequencyIndex96000}, |
| 107 | + {AAC_SAMPLE_FREQUENCY_INDEX_88200, kSampleFrequencyIndex88200}, |
| 108 | + {AAC_SAMPLE_FREQUENCY_INDEX_64000, kSampleFrequencyIndex64000}, |
| 109 | + {AAC_SAMPLE_FREQUENCY_INDEX_48000, kSampleFrequencyIndex48000}, |
| 110 | + {AAC_SAMPLE_FREQUENCY_INDEX_44100, kSampleFrequencyIndex44100}, |
| 111 | + {AAC_SAMPLE_FREQUENCY_INDEX_32000, kSampleFrequencyIndex32000}, |
| 112 | + {AAC_SAMPLE_FREQUENCY_INDEX_23000, kSampleFrequencyIndex23000}, |
| 113 | + {AAC_SAMPLE_FREQUENCY_INDEX_22050, kSampleFrequencyIndex22050}, |
| 114 | + {AAC_SAMPLE_FREQUENCY_INDEX_16000, kSampleFrequencyIndex16000}, |
| 115 | + {AAC_SAMPLE_FREQUENCY_INDEX_12000, kSampleFrequencyIndex12000}, |
| 116 | + {AAC_SAMPLE_FREQUENCY_INDEX_11025, kSampleFrequencyIndex11025}, |
| 117 | + {AAC_SAMPLE_FREQUENCY_INDEX_8000, kSampleFrequencyIndex8000}, |
| 118 | + {AAC_SAMPLE_FREQUENCY_INDEX_7350, kSampleFrequencyIndex7350}, |
| 119 | + {AAC_SAMPLE_FREQUENCY_INDEX_RESERVED_A, |
| 120 | + kSampleFrequencyIndexReservedA}, |
| 121 | + {AAC_SAMPLE_FREQUENCY_INDEX_RESERVED_B, |
| 122 | + kSampleFrequencyIndexReservedB}, |
| 123 | + {AAC_SAMPLE_FREQUENCY_INDEX_ESCAPE_VALUE, |
| 124 | + kSampleFrequencyIndexEscapeValue}}); |
| 125 | + }(); |
| 126 | + |
| 127 | + inline static constexpr auto kProtoAndInternalLoudspeakerLayouts = []() { |
| 128 | + using enum iamf_tools_cli_proto::LoudspeakerLayout; |
| 129 | + using enum ChannelAudioLayerConfig::LoudspeakerLayout; |
| 130 | + return std::to_array<std::pair<iamf_tools_cli_proto::LoudspeakerLayout, |
| 131 | + ChannelAudioLayerConfig::LoudspeakerLayout>>( |
| 132 | + { |
| 133 | + {LOUDSPEAKER_LAYOUT_MONO, kLayoutMono}, |
| 134 | + {LOUDSPEAKER_LAYOUT_STEREO, kLayoutStereo}, |
| 135 | + {LOUDSPEAKER_LAYOUT_5_1_CH, kLayout5_1_ch}, |
| 136 | + {LOUDSPEAKER_LAYOUT_5_1_2_CH, kLayout5_1_2_ch}, |
| 137 | + {LOUDSPEAKER_LAYOUT_5_1_4_CH, kLayout5_1_4_ch}, |
| 138 | + {LOUDSPEAKER_LAYOUT_7_1_CH, kLayout7_1_ch}, |
| 139 | + {LOUDSPEAKER_LAYOUT_7_1_2_CH, kLayout7_1_2_ch}, |
| 140 | + {LOUDSPEAKER_LAYOUT_7_1_4_CH, kLayout7_1_4_ch}, |
| 141 | + {LOUDSPEAKER_LAYOUT_3_1_2_CH, kLayout3_1_2_ch}, |
| 142 | + {LOUDSPEAKER_LAYOUT_BINAURAL, kLayoutBinaural}, |
| 143 | + {LOUDSPEAKER_LAYOUT_RESERVED_10, kLayoutReserved10}, |
| 144 | + {LOUDSPEAKER_LAYOUT_RESERVED_14, kLayoutReserved14}, |
| 145 | + {LOUDSPEAKER_LAYOUT_EXPANDED, kLayoutExpanded}, |
| 146 | + }); |
| 147 | + }(); |
| 148 | + |
| 149 | + inline static constexpr auto kProtoAndInternalExpandedLoudspeakerLayouts = |
| 150 | + []() { |
| 151 | + using enum iamf_tools_cli_proto::ExpandedLoudspeakerLayout; |
| 152 | + using enum ChannelAudioLayerConfig::ExpandedLoudspeakerLayout; |
| 153 | + return std::to_array< |
| 154 | + std::pair<iamf_tools_cli_proto::ExpandedLoudspeakerLayout, |
| 155 | + ChannelAudioLayerConfig::ExpandedLoudspeakerLayout>>({ |
| 156 | + {EXPANDED_LOUDSPEAKER_LAYOUT_LFE, kExpandedLayoutLFE}, |
| 157 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_S, kExpandedLayoutStereoS}, |
| 158 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_SS, kExpandedLayoutStereoSS}, |
| 159 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_RS, kExpandedLayoutStereoRS}, |
| 160 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_TF, kExpandedLayoutStereoTF}, |
| 161 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_TB, kExpandedLayoutStereoTB}, |
| 162 | + {EXPANDED_LOUDSPEAKER_LAYOUT_TOP_4_CH, kExpandedLayoutTop4Ch}, |
| 163 | + {EXPANDED_LOUDSPEAKER_LAYOUT_3_0_CH, kExpandedLayout3_0_ch}, |
| 164 | + {EXPANDED_LOUDSPEAKER_LAYOUT_9_1_6_CH, kExpandedLayout9_1_6_ch}, |
| 165 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_F, kExpandedLayoutStereoF}, |
| 166 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_SI, kExpandedLayoutStereoSi}, |
| 167 | + {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_TP_SI, |
| 168 | + kExpandedLayoutStereoTpSi}, |
| 169 | + {EXPANDED_LOUDSPEAKER_LAYOUT_TOP_6_CH, kExpandedLayoutTop6Ch}, |
| 170 | + }); |
| 171 | + }(); |
| 172 | + |
| 173 | + inline static constexpr auto kProtoAndInternalSoundSystems = []() { |
| 174 | + using enum iamf_tools_cli_proto::SoundSystem; |
| 175 | + using enum LoudspeakersSsConventionLayout::SoundSystem; |
| 176 | + return std::to_array< |
| 177 | + std::pair<iamf_tools_cli_proto::SoundSystem, |
| 178 | + LoudspeakersSsConventionLayout::SoundSystem>>({ |
| 179 | + {SOUND_SYSTEM_A_0_2_0, kSoundSystemA_0_2_0}, |
| 180 | + {SOUND_SYSTEM_B_0_5_0, kSoundSystemB_0_5_0}, |
| 181 | + {SOUND_SYSTEM_C_2_5_0, kSoundSystemC_2_5_0}, |
| 182 | + {SOUND_SYSTEM_D_4_5_0, kSoundSystemD_4_5_0}, |
| 183 | + {SOUND_SYSTEM_E_4_5_1, kSoundSystemE_4_5_1}, |
| 184 | + {SOUND_SYSTEM_F_3_7_0, kSoundSystemF_3_7_0}, |
| 185 | + {SOUND_SYSTEM_G_4_9_0, kSoundSystemG_4_9_0}, |
| 186 | + {SOUND_SYSTEM_H_9_10_3, kSoundSystemH_9_10_3}, |
| 187 | + {SOUND_SYSTEM_I_0_7_0, kSoundSystemI_0_7_0}, |
| 188 | + {SOUND_SYSTEM_J_4_7_0, kSoundSystemJ_4_7_0}, |
| 189 | + {SOUND_SYSTEM_10_2_7_0, kSoundSystem10_2_7_0}, |
| 190 | + {SOUND_SYSTEM_11_2_3_0, kSoundSystem11_2_3_0}, |
| 191 | + {SOUND_SYSTEM_12_0_1_0, kSoundSystem12_0_1_0}, |
| 192 | + {SOUND_SYSTEM_13_6_9_0, kSoundSystem13_6_9_0}, |
| 193 | + }); |
| 194 | + }(); |
| 195 | + |
| 196 | + inline static constexpr auto kProtoAndInternalInfoTypeBitmasks = []() { |
| 197 | + using enum iamf_tools_cli_proto::LoudnessInfoTypeBitMask; |
| 198 | + using enum LoudnessInfo::InfoTypeBitmask; |
| 199 | + return std::to_array< |
| 200 | + std::pair<iamf_tools_cli_proto::LoudnessInfoTypeBitMask, |
| 201 | + LoudnessInfo::InfoTypeBitmask>>( |
| 202 | + {{LOUDNESS_INFO_TYPE_TRUE_PEAK, kTruePeak}, |
| 203 | + {LOUDNESS_INFO_TYPE_ANCHORED_LOUDNESS, kAnchoredLoudness}, |
| 204 | + {LOUDNESS_INFO_TYPE_RESERVED_4, kInfoTypeBitMask4}, |
| 205 | + {LOUDNESS_INFO_TYPE_RESERVED_8, kInfoTypeBitMask8}, |
| 206 | + {LOUDNESS_INFO_TYPE_RESERVED_16, kInfoTypeBitMask16}, |
| 207 | + {LOUDNESS_INFO_TYPE_RESERVED_32, kInfoTypeBitMask32}, |
| 208 | + {LOUDNESS_INFO_TYPE_RESERVED_64, kInfoTypeBitMask64}, |
| 209 | + {LOUDNESS_INFO_TYPE_RESERVED_128, kInfoTypeBitMask128}}); |
| 210 | + }(); |
| 211 | + |
| 212 | + inline static constexpr auto kProtoArbitraryObuTypeAndInternalObuTypes = |
| 213 | + []() { |
| 214 | + using enum iamf_tools_cli_proto::ArbitraryObuType; |
| 215 | + return std::to_array< |
| 216 | + std::pair<iamf_tools_cli_proto::ArbitraryObuType, ObuType>>( |
| 217 | + {{OBU_IA_CODEC_CONFIG, kObuIaCodecConfig}, |
| 218 | + {OBU_IA_AUDIO_ELEMENT, kObuIaAudioElement}, |
| 219 | + {OBU_IA_MIX_PRESENTATION, kObuIaMixPresentation}, |
| 220 | + {OBU_IA_PARAMETER_BLOCK, kObuIaParameterBlock}, |
| 221 | + {OBU_IA_TEMPORAL_DELIMITER, kObuIaTemporalDelimiter}, |
| 222 | + {OBU_IA_AUDIO_FRAME, kObuIaAudioFrame}, |
| 223 | + {OBU_IA_AUDIO_FRAME_ID_0, kObuIaAudioFrameId0}, |
| 224 | + {OBU_IA_AUDIO_FRAME_ID_1, kObuIaAudioFrameId1}, |
| 225 | + {OBU_IA_AUDIO_FRAME_ID_2, kObuIaAudioFrameId2}, |
| 226 | + {OBU_IA_AUDIO_FRAME_ID_3, kObuIaAudioFrameId3}, |
| 227 | + {OBU_IA_AUDIO_FRAME_ID_4, kObuIaAudioFrameId4}, |
| 228 | + {OBU_IA_AUDIO_FRAME_ID_5, kObuIaAudioFrameId5}, |
| 229 | + {OBU_IA_AUDIO_FRAME_ID_6, kObuIaAudioFrameId6}, |
| 230 | + {OBU_IA_AUDIO_FRAME_ID_7, kObuIaAudioFrameId7}, |
| 231 | + {OBU_IA_AUDIO_FRAME_ID_8, kObuIaAudioFrameId8}, |
| 232 | + {OBU_IA_AUDIO_FRAME_ID_9, kObuIaAudioFrameId9}, |
| 233 | + {OBU_IA_AUDIO_FRAME_ID_10, kObuIaAudioFrameId10}, |
| 234 | + {OBU_IA_AUDIO_FRAME_ID_11, kObuIaAudioFrameId11}, |
| 235 | + {OBU_IA_AUDIO_FRAME_ID_12, kObuIaAudioFrameId12}, |
| 236 | + {OBU_IA_AUDIO_FRAME_ID_13, kObuIaAudioFrameId13}, |
| 237 | + {OBU_IA_AUDIO_FRAME_ID_14, kObuIaAudioFrameId14}, |
| 238 | + {OBU_IA_AUDIO_FRAME_ID_15, kObuIaAudioFrameId15}, |
| 239 | + {OBU_IA_AUDIO_FRAME_ID_16, kObuIaAudioFrameId16}, |
| 240 | + {OBU_IA_AUDIO_FRAME_ID_17, kObuIaAudioFrameId17}, |
| 241 | + {OBU_IA_RESERVED_24, kObuIaReserved24}, |
| 242 | + {OBU_IA_RESERVED_25, kObuIaReserved25}, |
| 243 | + {OBU_IA_RESERVED_26, kObuIaReserved26}, |
| 244 | + {OBU_IA_RESERVED_27, kObuIaReserved27}, |
| 245 | + {OBU_IA_RESERVED_28, kObuIaReserved28}, |
| 246 | + {OBU_IA_RESERVED_29, kObuIaReserved29}, |
| 247 | + {OBU_IA_RESERVED_30, kObuIaReserved30}, |
| 248 | + {OBU_IA_SEQUENCE_HEADER, kObuIaSequenceHeader}}); |
| 249 | + }(); |
| 250 | +}; |
| 251 | + |
| 252 | +} // namespace iamf_tools |
| 253 | + |
| 254 | +#endif // CLI_LOOKUP_TABLES_H_ |
0 commit comments