FFmpeg
iamf.c
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 
23 #include "libavutil/iamf.h"
24 #include "libavutil/mem.h"
25 #include "iamf.h"
26 
30  // "Loudspeaker configuration for Sound System B"
32  // "Loudspeaker configuration for Sound System C"
34  // "Loudspeaker configuration for Sound System D"
36  // "Loudspeaker configuration for Sound System I"
38  // "Loudspeaker configuration for Sound System I" + Ltf + Rtf
40  // "Loudspeaker configuration for Sound System J"
42  // Front subset of "Loudspeaker configuration for Sound System J"
44  // Binaural
46 };
47 
49  {
50  .nb_channels = 1,
51  .order = AV_CHANNEL_ORDER_NATIVE,
52  .u.mask = AV_CH_LOW_FREQUENCY,
53  },
54  {
55  .nb_channels = 2,
56  .order = AV_CHANNEL_ORDER_NATIVE,
58  },
59  {
60  .nb_channels = 2,
61  .order = AV_CHANNEL_ORDER_NATIVE,
63  },
64  {
65  .nb_channels = 2,
66  .order = AV_CHANNEL_ORDER_NATIVE,
68  },
69  {
70  .nb_channels = 2,
71  .order = AV_CHANNEL_ORDER_NATIVE,
73  },
74  {
75  .nb_channels = 2,
76  .order = AV_CHANNEL_ORDER_NATIVE,
78  },
79  {
80  .nb_channels = 4,
81  .order = AV_CHANNEL_ORDER_NATIVE,
84  },
88  {
89  .nb_channels = 2,
90  .order = AV_CHANNEL_ORDER_NATIVE,
92  },
93  {
94  .nb_channels = 2,
95  .order = AV_CHANNEL_ORDER_NATIVE,
97  },
98  {
99  .nb_channels = 6,
100  .order = AV_CHANNEL_ORDER_NATIVE,
104  },
105 };
106 
113  {
114  .nb_channels = 11,
115  .order = AV_CHANNEL_ORDER_NATIVE,
117  },
118  },
128 };
129 
131 {
132  IAMFAudioElement *audio_element = *paudio_element;
133 
134  if (!audio_element)
135  return;
136 
137  for (int i = 0; i < audio_element->nb_substreams; i++)
138  avcodec_parameters_free(&audio_element->substreams[i].codecpar);
139  av_free(audio_element->substreams);
140  av_free(audio_element->layers);
141  av_iamf_audio_element_free(&audio_element->element);
142  av_freep(paudio_element);
143 }
144 
146 {
147  IAMFMixPresentation *mix_presentation = *pmix_presentation;
148 
149  if (!mix_presentation)
150  return;
151 
152  for (int i = 0; i < mix_presentation->count_label; i++)
153  av_free(mix_presentation->language_label[i]);
154  av_free(mix_presentation->language_label);
155  av_iamf_mix_presentation_free(&mix_presentation->mix);
156  av_freep(pmix_presentation);
157 }
158 
160 {
161  if (!c)
162  return;
163 
164  for (int i = 0; i < c->nb_codec_configs; i++) {
165  av_free(c->codec_configs[i]->extradata);
166  av_free(c->codec_configs[i]);
167  }
168  av_freep(&c->codec_configs);
169  c->nb_codec_configs = 0;
170 
171  for (int i = 0; i < c->nb_audio_elements; i++)
172  ff_iamf_free_audio_element(&c->audio_elements[i]);
173  av_freep(&c->audio_elements);
174  c->nb_audio_elements = 0;
175 
176  for (int i = 0; i < c->nb_mix_presentations; i++)
177  ff_iamf_free_mix_presentation(&c->mix_presentations[i]);
178  av_freep(&c->mix_presentations);
179  c->nb_mix_presentations = 0;
180 
181  for (int i = 0; i < c->nb_param_definitions; i++)
182  av_free(c->param_definitions[i]);
183  av_freep(&c->param_definitions);
184  c->nb_param_definitions = 0;
185 }
iamf.h
ff_iamf_free_mix_presentation
void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation)
Definition: iamf.c:145
SOUND_SYSTEM_E_4_5_1
@ SOUND_SYSTEM_E_4_5_1
Definition: iamf.h:150
AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK
Definition: channel_layout.h:424
AV_CH_TOP_SIDE_LEFT
#define AV_CH_TOP_SIDE_LEFT
Definition: channel_layout.h:200
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:394
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
AV_CHANNEL_LAYOUT_9POINT1POINT6
#define AV_CHANNEL_LAYOUT_9POINT1POINT6
Definition: channel_layout.h:427
AV_CH_TOP_FRONT_RIGHT
#define AV_CH_TOP_FRONT_RIGHT
Definition: channel_layout.h:189
SOUND_SYSTEM_12_0_1_0
@ SOUND_SYSTEM_12_0_1_0
Definition: iamf.h:158
av_iamf_mix_presentation_free
void av_iamf_mix_presentation_free(AVIAMFMixPresentation **pmix_presentation)
Free an AVIAMFMixPresentation and all its contents.
Definition: iamf.c:534
AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_LEFT
Definition: channel_layout.h:187
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:328
AV_CHANNEL_LAYOUT_7POINT2POINT3
#define AV_CHANNEL_LAYOUT_7POINT2POINT3
Definition: channel_layout.h:425
SOUND_SYSTEM_J_4_7_0
@ SOUND_SYSTEM_J_4_7_0
Definition: iamf.h:155
SOUND_SYSTEM_10_2_7_0
@ SOUND_SYSTEM_10_2_7_0
Definition: iamf.h:156
AV_CH_TOP_BACK_LEFT
#define AV_CH_TOP_BACK_LEFT
Definition: channel_layout.h:190
AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK
Definition: channel_layout.h:426
AV_CHANNEL_LAYOUT_7POINT1POINT2
#define AV_CHANNEL_LAYOUT_7POINT1POINT2
Definition: channel_layout.h:423
AV_CH_BACK_LEFT
#define AV_CH_BACK_LEFT
Definition: channel_layout.h:179
av_iamf_audio_element_free
void av_iamf_audio_element_free(AVIAMFAudioElement **paudio_element)
Free an AVIAMFAudioElement and all its contents.
Definition: iamf.c:336
AV_CH_LAYOUT_5POINT1POINT4_BACK
#define AV_CH_LAYOUT_5POINT1POINT4_BACK
Definition: channel_layout.h:246
AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_SURROUND
Definition: channel_layout.h:397
IAMFAudioElement::element
AVIAMFAudioElement * element
element backs celement iff the AVIAMFAudioElement is owned by this structure.
Definition: iamf.h:95
AV_CH_LOW_FREQUENCY
#define AV_CH_LOW_FREQUENCY
Definition: channel_layout.h:178
AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_7POINT1
Definition: channel_layout.h:416
SOUND_SYSTEM_H_9_10_3
@ SOUND_SYSTEM_H_9_10_3
Definition: iamf.h:153
AV_CH_TOP_SIDE_RIGHT
#define AV_CH_TOP_SIDE_RIGHT
Definition: channel_layout.h:201
SOUND_SYSTEM_A_0_2_0
@ SOUND_SYSTEM_A_0_2_0
Definition: iamf.h:146
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:66
AV_CHANNEL_LAYOUT_3POINT1POINT2
#define AV_CHANNEL_LAYOUT_3POINT1POINT2
Definition: channel_layout.h:409
IAMFAudioElement::layers
IAMFLayer * layers
Definition: iamf.h:103
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
AV_CHANNEL_LAYOUT_22POINT2
#define AV_CHANNEL_LAYOUT_22POINT2
Definition: channel_layout.h:431
ff_iamf_expanded_scalable_ch_layouts
const AVChannelLayout ff_iamf_expanded_scalable_ch_layouts[13]
Definition: iamf.c:48
AV_CH_BOTTOM_FRONT_CENTER
#define AV_CH_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:202
SOUND_SYSTEM_11_2_3_0
@ SOUND_SYSTEM_11_2_3_0
Definition: iamf.h:157
IAMFAudioElement
Definition: iamf.h:89
AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
#define AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
Definition: channel_layout.h:419
SOUND_SYSTEM_D_4_5_0
@ SOUND_SYSTEM_D_4_5_0
Definition: iamf.h:149
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:318
ff_iamf_sound_system_map
const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14]
Definition: iamf.c:107
ff_iamf_uninit_context
void ff_iamf_uninit_context(IAMFContext *c)
Definition: iamf.c:159
IAMFContext
Definition: iamf.h:128
IAMFAudioElement::substreams
IAMFSubStream * substreams
Definition: iamf.h:98
AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_BACK_RIGHT
Definition: channel_layout.h:192
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:125
IAMFSoundSystemMap
Definition: iamf.h:162
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK
Definition: channel_layout.h:422
AV_CH_SIDE_RIGHT
#define AV_CH_SIDE_RIGHT
Definition: channel_layout.h:185
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_free_audio_element
void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element)
Definition: iamf.c:130
SOUND_SYSTEM_F_3_7_0
@ SOUND_SYSTEM_F_3_7_0
Definition: iamf.h:151
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
mem.h
AV_CHANNEL_LAYOUT_BINAURAL
#define AV_CHANNEL_LAYOUT_BINAURAL
Definition: channel_layout.h:429
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:393
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
SOUND_SYSTEM_B_0_5_0
@ SOUND_SYSTEM_B_0_5_0
Definition: iamf.h:147
iamf.h
ff_iamf_scalable_ch_layouts
const AVChannelLayout ff_iamf_scalable_ch_layouts[10]
Definition: iamf.c:27
AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:406
AV_CH_BACK_RIGHT
#define AV_CH_BACK_RIGHT
Definition: channel_layout.h:180
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
AV_CH_SIDE_LEFT
#define AV_CH_SIDE_LEFT
Definition: channel_layout.h:184
SOUND_SYSTEM_I_0_7_0
@ SOUND_SYSTEM_I_0_7_0
Definition: iamf.h:154