• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, k96000},
107          {AAC_SAMPLE_FREQUENCY_INDEX_88200, k88200},
108          {AAC_SAMPLE_FREQUENCY_INDEX_64000, k64000},
109          {AAC_SAMPLE_FREQUENCY_INDEX_48000, k48000},
110          {AAC_SAMPLE_FREQUENCY_INDEX_44100, k44100},
111          {AAC_SAMPLE_FREQUENCY_INDEX_32000, k32000},
112          {AAC_SAMPLE_FREQUENCY_INDEX_24000, k24000},
113          {AAC_SAMPLE_FREQUENCY_INDEX_22050, k22050},
114          {AAC_SAMPLE_FREQUENCY_INDEX_16000, k16000},
115          {AAC_SAMPLE_FREQUENCY_INDEX_12000, k12000},
116          {AAC_SAMPLE_FREQUENCY_INDEX_11025, k11025},
117          {AAC_SAMPLE_FREQUENCY_INDEX_8000, k8000},
118          {AAC_SAMPLE_FREQUENCY_INDEX_7350, k7350},
119          {AAC_SAMPLE_FREQUENCY_INDEX_RESERVED_A, kReservedA},
120          {AAC_SAMPLE_FREQUENCY_INDEX_RESERVED_B, kReservedB},
121          {AAC_SAMPLE_FREQUENCY_INDEX_ESCAPE_VALUE, kEscapeValue}});
122   }();
123 
124   inline static constexpr auto kProtoAndInternalLoudspeakerLayouts = []() {
125     using enum iamf_tools_cli_proto::LoudspeakerLayout;
126     using enum ChannelAudioLayerConfig::LoudspeakerLayout;
127     return std::to_array<std::pair<iamf_tools_cli_proto::LoudspeakerLayout,
128                                    ChannelAudioLayerConfig::LoudspeakerLayout>>(
129         {
130             {LOUDSPEAKER_LAYOUT_MONO, kLayoutMono},
131             {LOUDSPEAKER_LAYOUT_STEREO, kLayoutStereo},
132             {LOUDSPEAKER_LAYOUT_5_1_CH, kLayout5_1_ch},
133             {LOUDSPEAKER_LAYOUT_5_1_2_CH, kLayout5_1_2_ch},
134             {LOUDSPEAKER_LAYOUT_5_1_4_CH, kLayout5_1_4_ch},
135             {LOUDSPEAKER_LAYOUT_7_1_CH, kLayout7_1_ch},
136             {LOUDSPEAKER_LAYOUT_7_1_2_CH, kLayout7_1_2_ch},
137             {LOUDSPEAKER_LAYOUT_7_1_4_CH, kLayout7_1_4_ch},
138             {LOUDSPEAKER_LAYOUT_3_1_2_CH, kLayout3_1_2_ch},
139             {LOUDSPEAKER_LAYOUT_BINAURAL, kLayoutBinaural},
140             {LOUDSPEAKER_LAYOUT_RESERVED_10, kLayoutReserved10},
141             {LOUDSPEAKER_LAYOUT_RESERVED_14, kLayoutReserved14},
142             {LOUDSPEAKER_LAYOUT_EXPANDED, kLayoutExpanded},
143         });
144   }();
145 
146   inline static constexpr auto kProtoAndInternalExpandedLoudspeakerLayouts =
147       []() {
148         using enum iamf_tools_cli_proto::ExpandedLoudspeakerLayout;
149         using enum ChannelAudioLayerConfig::ExpandedLoudspeakerLayout;
150         return std::to_array<
151             std::pair<iamf_tools_cli_proto::ExpandedLoudspeakerLayout,
152                       ChannelAudioLayerConfig::ExpandedLoudspeakerLayout>>({
153             {EXPANDED_LOUDSPEAKER_LAYOUT_LFE, kExpandedLayoutLFE},
154             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_S, kExpandedLayoutStereoS},
155             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_SS, kExpandedLayoutStereoSS},
156             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_RS, kExpandedLayoutStereoRS},
157             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_TF, kExpandedLayoutStereoTF},
158             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_TB, kExpandedLayoutStereoTB},
159             {EXPANDED_LOUDSPEAKER_LAYOUT_TOP_4_CH, kExpandedLayoutTop4Ch},
160             {EXPANDED_LOUDSPEAKER_LAYOUT_3_0_CH, kExpandedLayout3_0_ch},
161             {EXPANDED_LOUDSPEAKER_LAYOUT_9_1_6_CH, kExpandedLayout9_1_6_ch},
162             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_F, kExpandedLayoutStereoF},
163             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_SI, kExpandedLayoutStereoSi},
164             {EXPANDED_LOUDSPEAKER_LAYOUT_STEREO_TP_SI,
165              kExpandedLayoutStereoTpSi},
166             {EXPANDED_LOUDSPEAKER_LAYOUT_TOP_6_CH, kExpandedLayoutTop6Ch},
167         });
168       }();
169 
170   inline static constexpr auto kProtoAndInternalSoundSystems = []() {
171     using enum iamf_tools_cli_proto::SoundSystem;
172     using enum LoudspeakersSsConventionLayout::SoundSystem;
173     return std::to_array<
174         std::pair<iamf_tools_cli_proto::SoundSystem,
175                   LoudspeakersSsConventionLayout::SoundSystem>>({
176         {SOUND_SYSTEM_A_0_2_0, kSoundSystemA_0_2_0},
177         {SOUND_SYSTEM_B_0_5_0, kSoundSystemB_0_5_0},
178         {SOUND_SYSTEM_C_2_5_0, kSoundSystemC_2_5_0},
179         {SOUND_SYSTEM_D_4_5_0, kSoundSystemD_4_5_0},
180         {SOUND_SYSTEM_E_4_5_1, kSoundSystemE_4_5_1},
181         {SOUND_SYSTEM_F_3_7_0, kSoundSystemF_3_7_0},
182         {SOUND_SYSTEM_G_4_9_0, kSoundSystemG_4_9_0},
183         {SOUND_SYSTEM_H_9_10_3, kSoundSystemH_9_10_3},
184         {SOUND_SYSTEM_I_0_7_0, kSoundSystemI_0_7_0},
185         {SOUND_SYSTEM_J_4_7_0, kSoundSystemJ_4_7_0},
186         {SOUND_SYSTEM_10_2_7_0, kSoundSystem10_2_7_0},
187         {SOUND_SYSTEM_11_2_3_0, kSoundSystem11_2_3_0},
188         {SOUND_SYSTEM_12_0_1_0, kSoundSystem12_0_1_0},
189         {SOUND_SYSTEM_13_6_9_0, kSoundSystem13_6_9_0},
190     });
191   }();
192 
193   inline static constexpr auto kProtoAndInternalInfoTypeBitmasks = []() {
194     using enum iamf_tools_cli_proto::LoudnessInfoTypeBitMask;
195     using enum LoudnessInfo::InfoTypeBitmask;
196     return std::to_array<
197         std::pair<iamf_tools_cli_proto::LoudnessInfoTypeBitMask,
198                   LoudnessInfo::InfoTypeBitmask>>(
199         {{LOUDNESS_INFO_TYPE_TRUE_PEAK, kTruePeak},
200          {LOUDNESS_INFO_TYPE_ANCHORED_LOUDNESS, kAnchoredLoudness},
201          {LOUDNESS_INFO_TYPE_RESERVED_4, kInfoTypeBitMask4},
202          {LOUDNESS_INFO_TYPE_RESERVED_8, kInfoTypeBitMask8},
203          {LOUDNESS_INFO_TYPE_RESERVED_16, kInfoTypeBitMask16},
204          {LOUDNESS_INFO_TYPE_RESERVED_32, kInfoTypeBitMask32},
205          {LOUDNESS_INFO_TYPE_RESERVED_64, kInfoTypeBitMask64},
206          {LOUDNESS_INFO_TYPE_RESERVED_128, kInfoTypeBitMask128}});
207   }();
208 
209   inline static constexpr auto kProtoArbitraryObuTypeAndInternalObuTypes =
210       []() {
211         using enum iamf_tools_cli_proto::ArbitraryObuType;
212         return std::to_array<
213             std::pair<iamf_tools_cli_proto::ArbitraryObuType, ObuType>>(
214             {{OBU_IA_CODEC_CONFIG, kObuIaCodecConfig},
215              {OBU_IA_AUDIO_ELEMENT, kObuIaAudioElement},
216              {OBU_IA_MIX_PRESENTATION, kObuIaMixPresentation},
217              {OBU_IA_PARAMETER_BLOCK, kObuIaParameterBlock},
218              {OBU_IA_TEMPORAL_DELIMITER, kObuIaTemporalDelimiter},
219              {OBU_IA_AUDIO_FRAME, kObuIaAudioFrame},
220              {OBU_IA_AUDIO_FRAME_ID_0, kObuIaAudioFrameId0},
221              {OBU_IA_AUDIO_FRAME_ID_1, kObuIaAudioFrameId1},
222              {OBU_IA_AUDIO_FRAME_ID_2, kObuIaAudioFrameId2},
223              {OBU_IA_AUDIO_FRAME_ID_3, kObuIaAudioFrameId3},
224              {OBU_IA_AUDIO_FRAME_ID_4, kObuIaAudioFrameId4},
225              {OBU_IA_AUDIO_FRAME_ID_5, kObuIaAudioFrameId5},
226              {OBU_IA_AUDIO_FRAME_ID_6, kObuIaAudioFrameId6},
227              {OBU_IA_AUDIO_FRAME_ID_7, kObuIaAudioFrameId7},
228              {OBU_IA_AUDIO_FRAME_ID_8, kObuIaAudioFrameId8},
229              {OBU_IA_AUDIO_FRAME_ID_9, kObuIaAudioFrameId9},
230              {OBU_IA_AUDIO_FRAME_ID_10, kObuIaAudioFrameId10},
231              {OBU_IA_AUDIO_FRAME_ID_11, kObuIaAudioFrameId11},
232              {OBU_IA_AUDIO_FRAME_ID_12, kObuIaAudioFrameId12},
233              {OBU_IA_AUDIO_FRAME_ID_13, kObuIaAudioFrameId13},
234              {OBU_IA_AUDIO_FRAME_ID_14, kObuIaAudioFrameId14},
235              {OBU_IA_AUDIO_FRAME_ID_15, kObuIaAudioFrameId15},
236              {OBU_IA_AUDIO_FRAME_ID_16, kObuIaAudioFrameId16},
237              {OBU_IA_AUDIO_FRAME_ID_17, kObuIaAudioFrameId17},
238              {OBU_IA_RESERVED_24, kObuIaReserved24},
239              {OBU_IA_RESERVED_25, kObuIaReserved25},
240              {OBU_IA_RESERVED_26, kObuIaReserved26},
241              {OBU_IA_RESERVED_27, kObuIaReserved27},
242              {OBU_IA_RESERVED_28, kObuIaReserved28},
243              {OBU_IA_RESERVED_29, kObuIaReserved29},
244              {OBU_IA_RESERVED_30, kObuIaReserved30},
245              {OBU_IA_SEQUENCE_HEADER, kObuIaSequenceHeader}});
246       }();
247 };
248 
249 }  // namespace iamf_tools
250 
251 #endif  // CLI_LOOKUP_TABLES_H_
252