FFmpeg
iamf.h
Go to the documentation of this file.
1 /*
2  * Immersive Audio Model and Formats common helpers and structs
3  * Copyright (c) 2023 James Almer <jamrial@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVFORMAT_IAMF_H
23 #define AVFORMAT_IAMF_H
24 
25 #include <stddef.h>
26 #include <stdint.h>
27 
30 #include "libavutil/iamf.h"
31 #include "libavcodec/codec_id.h"
32 #include "libavcodec/codec_par.h"
33 
34 #define MAX_IAMF_OBU_HEADER_SIZE (1 + 8 * 3)
35 
36 // OBU types (section 3.2).
62  // 24~30 reserved.
64 };
65 
66 typedef struct IAMFCodecConfig {
67  unsigned codec_config_id;
69  uint32_t codec_tag;
70  unsigned nb_samples;
74  uint8_t *extradata;
76 
77 typedef struct IAMFLayer {
78  unsigned int substream_count;
80 } IAMFLayer;
81 
82 typedef struct IAMFSubStream {
83  unsigned int audio_substream_id;
84 
85  // demux
88 
89 typedef struct IAMFAudioElement {
91  /**
92  * element backs celement iff the AVIAMFAudioElement
93  * is owned by this structure.
94  */
96  unsigned int audio_element_id;
97 
99  unsigned int nb_substreams;
100 
101  unsigned int codec_config_id;
102 
104  unsigned int nb_layers;
106 
107 typedef struct IAMFMixPresentation {
109  /**
110  * mix backs cmix iff the AVIAMFMixPresentation
111  * is owned by this structure.
112  */
114  unsigned int mix_presentation_id;
115 
116  // demux
117  unsigned int count_label;
120 
121 typedef struct IAMFParamDefinition {
124  int mode;
125  size_t param_size;
127 
128 typedef struct IAMFContext {
137 } IAMFContext;
138 
143 };
144 
146  SOUND_SYSTEM_A_0_2_0 = 0, // "Loudspeaker configuration for Sound System A"
147  SOUND_SYSTEM_B_0_5_0 = 1, // "Loudspeaker configuration for Sound System B"
148  SOUND_SYSTEM_C_2_5_0 = 2, // "Loudspeaker configuration for Sound System C"
149  SOUND_SYSTEM_D_4_5_0 = 3, // "Loudspeaker configuration for Sound System D"
150  SOUND_SYSTEM_E_4_5_1 = 4, // "Loudspeaker configuration for Sound System E"
151  SOUND_SYSTEM_F_3_7_0 = 5, // "Loudspeaker configuration for Sound System F"
152  SOUND_SYSTEM_G_4_9_0 = 6, // "Loudspeaker configuration for Sound System G"
153  SOUND_SYSTEM_H_9_10_3 = 7, // "Loudspeaker configuration for Sound System H"
154  SOUND_SYSTEM_I_0_7_0 = 8, // "Loudspeaker configuration for Sound System I"
155  SOUND_SYSTEM_J_4_7_0 = 9, // "Loudspeaker configuration for Sound System J"
156  SOUND_SYSTEM_10_2_7_0 = 10, // "Loudspeaker configuration for Sound System I" + Ltf + Rtf
157  SOUND_SYSTEM_11_2_3_0 = 11, // Front subset of "Loudspeaker configuration for Sound System J"
158  SOUND_SYSTEM_12_0_1_0 = 12, // Mono
159  SOUND_SYSTEM_13_9_1_6 = 13, // Subset of "Loudspeaker configuration for Sound System H"
160 };
161 
165 };
166 
170 extern const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14];
171 
173  unsigned int codec_config_id)
174 {
175  IAMFCodecConfig *codec_config = NULL;
176 
177  for (int i = 0; i < c->nb_codec_configs; i++) {
178  if (c->codec_configs[i]->codec_config_id == codec_config_id)
179  codec_config = c->codec_configs[i];
180  }
181 
182  return codec_config;
183 }
184 
186  unsigned int parameter_id)
187 {
189 
190  for (int i = 0; i < iamf->nb_param_definitions; i++)
191  if (iamf->param_definitions[i]->param->parameter_id == parameter_id) {
193  break;
194  }
195 
196  return param_definition;
197 }
198 
199 void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element);
200 void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation);
203 
204 #endif /* AVFORMAT_IAMF_H */
IAMF_OBU_IA_AUDIO_FRAME_ID15
@ IAMF_OBU_IA_AUDIO_FRAME_ID15
Definition: iamf.h:59
iamf.h
SOUND_SYSTEM_E_4_5_1
@ SOUND_SYSTEM_E_4_5_1
Definition: iamf.h:150
FF_VISIBILITY_PUSH_HIDDEN
#define FF_VISIBILITY_PUSH_HIDDEN
Definition: attributes_internal.h:30
IAMF_ANCHOR_ELEMENT_UNKNWONW
@ IAMF_ANCHOR_ELEMENT_UNKNWONW
Definition: iamf.h:140
IAMFParamDefinition::param_size
size_t param_size
Definition: iamf.h:125
IAMF_OBU_IA_SEQUENCE_HEADER
@ IAMF_OBU_IA_SEQUENCE_HEADER
Definition: iamf.h:63
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
SOUND_SYSTEM_13_9_1_6
@ SOUND_SYSTEM_13_9_1_6
Definition: iamf.h:159
IAMFAudioElement::nb_substreams
unsigned int nb_substreams
Definition: iamf.h:99
IAMF_OBU_IA_AUDIO_FRAME_ID9
@ IAMF_OBU_IA_AUDIO_FRAME_ID9
Definition: iamf.h:53
SOUND_SYSTEM_12_0_1_0
@ SOUND_SYSTEM_12_0_1_0
Definition: iamf.h:158
IAMF_OBU_IA_AUDIO_FRAME_ID1
@ IAMF_OBU_IA_AUDIO_FRAME_ID1
Definition: iamf.h:45
IAMFParamDefinition::param
AVIAMFParamDefinition * param
Definition: iamf.h:123
AVIAMFParamDefinition
Parameters as defined in section 3.6.1 of IAMF.
Definition: iamf.h:193
ff_iamf_get_param_definition
static IAMFParamDefinition * ff_iamf_get_param_definition(const IAMFContext *iamf, unsigned int parameter_id)
Definition: iamf.h:185
ff_iamf_expanded_scalable_ch_layouts
const AVChannelLayout ff_iamf_expanded_scalable_ch_layouts[13]
Definition: iamf.c:48
ff_iamf_scalable_ch_layouts
const FF_VISIBILITY_PUSH_HIDDEN AVChannelLayout ff_iamf_scalable_ch_layouts[10]
Definition: iamf.c:27
SOUND_SYSTEM_J_4_7_0
@ SOUND_SYSTEM_J_4_7_0
Definition: iamf.h:155
IAMFSoundSystemMap::id
enum IAMF_Sound_System id
Definition: iamf.h:163
IAMF_OBU_IA_AUDIO_FRAME_ID14
@ IAMF_OBU_IA_AUDIO_FRAME_ID14
Definition: iamf.h:58
IAMFMixPresentation::cmix
const AVIAMFMixPresentation * cmix
Definition: iamf.h:108
SOUND_SYSTEM_10_2_7_0
@ SOUND_SYSTEM_10_2_7_0
Definition: iamf.h:156
IAMFParamDefinition::mode
int mode
Definition: iamf.h:124
IAMFCodecConfig::extradata
uint8_t * extradata
Definition: iamf.h:74
IAMFParamDefinition
Definition: iamf.h:121
IAMFCodecConfig::codec_tag
uint32_t codec_tag
Definition: iamf.h:69
IAMF_ANCHOR_ELEMENT_ALBUM
@ IAMF_ANCHOR_ELEMENT_ALBUM
Definition: iamf.h:142
IAMF_OBU_IA_PARAMETER_BLOCK
@ IAMF_OBU_IA_PARAMETER_BLOCK
Definition: iamf.h:41
IAMFAudioElement::element
AVIAMFAudioElement * element
element backs celement iff the AVIAMFAudioElement is owned by this structure.
Definition: iamf.h:95
IAMFContext::audio_elements
IAMFAudioElement ** audio_elements
Definition: iamf.h:131
IAMF_OBU_IA_AUDIO_FRAME_ID8
@ IAMF_OBU_IA_AUDIO_FRAME_ID8
Definition: iamf.h:52
IAMFCodecConfig::sample_rate
int sample_rate
Definition: iamf.h:72
codec_id.h
IAMF_OBU_IA_MIX_PRESENTATION
@ IAMF_OBU_IA_MIX_PRESENTATION
Definition: iamf.h:40
attributes_internal.h
IAMFSubStream::audio_substream_id
unsigned int audio_substream_id
Definition: iamf.h:83
SOUND_SYSTEM_H_9_10_3
@ SOUND_SYSTEM_H_9_10_3
Definition: iamf.h:153
IAMFLayer::substream_count
unsigned int substream_count
Definition: iamf.h:78
IAMF_Sound_System
IAMF_Sound_System
Definition: iamf.h:145
IAMF_OBU_IA_AUDIO_FRAME_ID7
@ IAMF_OBU_IA_AUDIO_FRAME_ID7
Definition: iamf.h:51
IAMFAudioElement::nb_layers
unsigned int nb_layers
Definition: iamf.h:104
IAMFContext::nb_mix_presentations
int nb_mix_presentations
Definition: iamf.h:134
IAMFAudioElement::audio_element_id
unsigned int audio_element_id
Definition: iamf.h:96
SOUND_SYSTEM_A_0_2_0
@ SOUND_SYSTEM_A_0_2_0
Definition: iamf.h:146
IAMFSoundSystemMap::layout
AVChannelLayout layout
Definition: iamf.h:164
NULL
#define NULL
Definition: coverity.c:32
IAMF_OBU_IA_AUDIO_ELEMENT
@ IAMF_OBU_IA_AUDIO_ELEMENT
Definition: iamf.h:39
ff_iamf_get_codec_config
static IAMFCodecConfig * ff_iamf_get_codec_config(const IAMFContext *c, unsigned int codec_config_id)
Definition: iamf.h:172
IAMFContext::nb_codec_configs
int nb_codec_configs
Definition: iamf.h:130
IAMF_OBU_IA_CODEC_CONFIG
@ IAMF_OBU_IA_CODEC_CONFIG
Definition: iamf.h:38
IAMF_OBU_IA_AUDIO_FRAME_ID5
@ IAMF_OBU_IA_AUDIO_FRAME_ID5
Definition: iamf.h:49
IAMFSubStream
Definition: iamf.h:82
IAMF_Anchor_Element
IAMF_Anchor_Element
Definition: iamf.h:139
IAMFAudioElement::layers
IAMFLayer * layers
Definition: iamf.h:103
ff_iamf_free_mix_presentation
void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation)
Definition: iamf.c:145
IAMFAudioElement::celement
const AVIAMFAudioElement * celement
Definition: iamf.h:90
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
IAMF_OBU_IA_AUDIO_FRAME_ID10
@ IAMF_OBU_IA_AUDIO_FRAME_ID10
Definition: iamf.h:54
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
SOUND_SYSTEM_11_2_3_0
@ SOUND_SYSTEM_11_2_3_0
Definition: iamf.h:157
IAMFLayer
Definition: iamf.h:77
IAMF_OBU_IA_AUDIO_FRAME_ID13
@ IAMF_OBU_IA_AUDIO_FRAME_ID13
Definition: iamf.h:57
IAMFAudioElement
Definition: iamf.h:89
IAMFCodecConfig::nb_samples
unsigned nb_samples
Definition: iamf.h:70
IAMFContext::nb_param_definitions
int nb_param_definitions
Definition: iamf.h:136
ff_iamf_free_audio_element
void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element)
Definition: iamf.c:130
SOUND_SYSTEM_D_4_5_0
@ SOUND_SYSTEM_D_4_5_0
Definition: iamf.h:149
IAMFCodecConfig
Definition: iamf.h:66
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:318
IAMFCodecConfig::extradata_size
int extradata_size
Definition: iamf.h:73
ff_iamf_sound_system_map
const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14]
Definition: iamf.c:107
IAMFLayer::coupled_substream_count
unsigned int coupled_substream_count
Definition: iamf.h:79
IAMF_OBU_IA_AUDIO_FRAME_ID12
@ IAMF_OBU_IA_AUDIO_FRAME_ID12
Definition: iamf.h:56
IAMF_OBU_IA_AUDIO_FRAME_ID2
@ IAMF_OBU_IA_AUDIO_FRAME_ID2
Definition: iamf.h:46
IAMFContext
Definition: iamf.h:128
IAMFAudioElement::substreams
IAMFSubStream * substreams
Definition: iamf.h:98
AVIAMFAudioElement
Information on how to combine one or more audio streams, as defined in section 3.6 of IAMF.
Definition: iamf.h:356
FF_VISIBILITY_POP_HIDDEN
#define FF_VISIBILITY_POP_HIDDEN
Definition: attributes_internal.h:31
IAMFSoundSystemMap
Definition: iamf.h:162
IAMFContext::param_definitions
IAMFParamDefinition ** param_definitions
Definition: iamf.h:135
IAMFParamDefinition::audio_element
const IAMFAudioElement * audio_element
Definition: iamf.h:122
IAMFContext::nb_audio_elements
int nb_audio_elements
Definition: iamf.h:132
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVIAMFParamDefinition::parameter_id
unsigned int parameter_id
Identifier for the paremeter substream.
Definition: iamf.h:218
IAMF_OBU_IA_AUDIO_FRAME_ID3
@ IAMF_OBU_IA_AUDIO_FRAME_ID3
Definition: iamf.h:47
AVIAMFMixPresentation
Information on how to render and mix one or more AVIAMFAudioElement to generate the final audio outpu...
Definition: iamf.h:613
param_definition
static int param_definition(const IAMFContext *iamf, const IAMFParamDefinition *param_def, AVIOContext *dyn_bc, void *log_ctx)
Definition: iamf_writer.c:607
IAMFContext::codec_configs
IAMFCodecConfig ** codec_configs
Definition: iamf.h:129
IAMF_OBU_IA_AUDIO_FRAME_ID6
@ IAMF_OBU_IA_AUDIO_FRAME_ID6
Definition: iamf.h:50
IAMF_OBU_IA_AUDIO_FRAME
@ IAMF_OBU_IA_AUDIO_FRAME
Definition: iamf.h:43
SOUND_SYSTEM_C_2_5_0
@ SOUND_SYSTEM_C_2_5_0
Definition: iamf.h:148
IAMFMixPresentation::count_label
unsigned int count_label
Definition: iamf.h:117
ff_iamf_uninit_context
void ff_iamf_uninit_context(IAMFContext *c)
Definition: iamf.c:159
SOUND_SYSTEM_F_3_7_0
@ SOUND_SYSTEM_F_3_7_0
Definition: iamf.h:151
IAMF_OBU_IA_AUDIO_FRAME_ID0
@ IAMF_OBU_IA_AUDIO_FRAME_ID0
Definition: iamf.h:44
IAMF_OBU_Type
IAMF_OBU_Type
Definition: iamf.h:37
IAMFMixPresentation
Definition: iamf.h:107
channel_layout.h
IAMFMixPresentation::language_label
char ** language_label
Definition: iamf.h:118
SOUND_SYSTEM_G_4_9_0
@ SOUND_SYSTEM_G_4_9_0
Definition: iamf.h:152
IAMFCodecConfig::codec_id
enum AVCodecID codec_id
Definition: iamf.h:68
IAMFCodecConfig::codec_config_id
unsigned codec_config_id
Definition: iamf.h:67
IAMF_ANCHOR_ELEMENT_DIALOGUE
@ IAMF_ANCHOR_ELEMENT_DIALOGUE
Definition: iamf.h:141
IAMF_OBU_IA_AUDIO_FRAME_ID11
@ IAMF_OBU_IA_AUDIO_FRAME_ID11
Definition: iamf.h:55
IAMF_OBU_IA_AUDIO_FRAME_ID4
@ IAMF_OBU_IA_AUDIO_FRAME_ID4
Definition: iamf.h:48
IAMFContext::mix_presentations
IAMFMixPresentation ** mix_presentations
Definition: iamf.h:133
codec_par.h
IAMF_OBU_IA_AUDIO_FRAME_ID16
@ IAMF_OBU_IA_AUDIO_FRAME_ID16
Definition: iamf.h:60
SOUND_SYSTEM_B_0_5_0
@ SOUND_SYSTEM_B_0_5_0
Definition: iamf.h:147
IAMFAudioElement::codec_config_id
unsigned int codec_config_id
Definition: iamf.h:101
IAMF_OBU_IA_TEMPORAL_DELIMITER
@ IAMF_OBU_IA_TEMPORAL_DELIMITER
Definition: iamf.h:42
IAMFMixPresentation::mix
AVIAMFMixPresentation * mix
mix backs cmix iff the AVIAMFMixPresentation is owned by this structure.
Definition: iamf.h:113
IAMFSubStream::codecpar
AVCodecParameters * codecpar
Definition: iamf.h:86
IAMFCodecConfig::audio_roll_distance
int audio_roll_distance
Definition: iamf.h:71
IAMFMixPresentation::mix_presentation_id
unsigned int mix_presentation_id
Definition: iamf.h:114
SOUND_SYSTEM_I_0_7_0
@ SOUND_SYSTEM_I_0_7_0
Definition: iamf.h:154
IAMF_OBU_IA_AUDIO_FRAME_ID17
@ IAMF_OBU_IA_AUDIO_FRAME_ID17
Definition: iamf.h:61