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  // The low-frequency effects subset (LFE) of "Loudspeaker configuration for Sound System J"
50  {
51  .nb_channels = 1,
52  .order = AV_CHANNEL_ORDER_NATIVE,
53  .u.mask = AV_CH_LOW_FREQUENCY,
54  },
55  // The surround subset (Ls/Rs) of "Loudspeaker configuration for Sound System I"
56  {
57  .nb_channels = 2,
58  .order = AV_CHANNEL_ORDER_NATIVE,
60  },
61  // The side surround subset (Lss/Rss) of "Loudspeaker configuration for Sound System J"
62  {
63  .nb_channels = 2,
64  .order = AV_CHANNEL_ORDER_NATIVE,
66  },
67  // The rear surround subset (Lrs/Rrs) of "Loudspeaker configuration for Sound System J"
68  {
69  .nb_channels = 2,
70  .order = AV_CHANNEL_ORDER_NATIVE,
72  },
73  // The top front subset (Ltf/Rtf) of "Loudspeaker configuration for Sound System J"
74  {
75  .nb_channels = 2,
76  .order = AV_CHANNEL_ORDER_NATIVE,
78  },
79  // The top back subset (Ltb/Rtb) of "Loudspeaker configuration for Sound System J"
80  {
81  .nb_channels = 2,
82  .order = AV_CHANNEL_ORDER_NATIVE,
84  },
85  // The top 4 channels (Ltf/Rtf/Ltb/Rtb) of "Loudspeaker configuration for Sound System J"
86  {
87  .nb_channels = 4,
88  .order = AV_CHANNEL_ORDER_NATIVE,
91  },
92  // The front 3 channels (L/C/R) of "Loudspeaker configuration for Sound System J"
94  // Subset of "Loudspeaker configuration for Sound System H"
96  // Front subset of "Loudspeaker configuration for Sound System H"
98  // The side subset (SiL/SiR) of "Loudspeaker configuration for Sound System H"
99  {
100  .nb_channels = 2,
101  .order = AV_CHANNEL_ORDER_NATIVE,
102  .u.mask = AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT,
103  },
104  // The top side subset (TpSiL/TpSiR) of "Loudspeaker configuration for Sound System H"
105  {
106  .nb_channels = 2,
107  .order = AV_CHANNEL_ORDER_NATIVE,
109  },
110  // The top 6 channels (TpFL/TpFR/TpSiL/TpSiR/TpBL/TpBR) of "Loudspeaker configuration for Sound System H"
111  {
112  .nb_channels = 6,
113  .order = AV_CHANNEL_ORDER_NATIVE,
117  },
118 };
119 
126  {
127  .nb_channels = 11,
128  .order = AV_CHANNEL_ORDER_NATIVE,
130  },
131  },
141 };
142 
144 {
145  IAMFAudioElement *audio_element = *paudio_element;
146 
147  if (!audio_element)
148  return;
149 
150  for (int i = 0; i < audio_element->nb_substreams; i++)
151  avcodec_parameters_free(&audio_element->substreams[i].codecpar);
152  av_free(audio_element->substreams);
153  av_free(audio_element->layers);
154  av_iamf_audio_element_free(&audio_element->element);
155  av_freep(paudio_element);
156 }
157 
159 {
160  IAMFMixPresentation *mix_presentation = *pmix_presentation;
161 
162  if (!mix_presentation)
163  return;
164 
165  for (int i = 0; i < mix_presentation->count_label; i++)
166  av_free(mix_presentation->language_label[i]);
167  av_free(mix_presentation->language_label);
168  av_iamf_mix_presentation_free(&mix_presentation->mix);
169  av_freep(pmix_presentation);
170 }
171 
173 {
174  if (!c)
175  return;
176 
177  for (int i = 0; i < c->nb_codec_configs; i++) {
178  av_free(c->codec_configs[i]->extradata);
179  av_free(c->codec_configs[i]);
180  }
181  av_freep(&c->codec_configs);
182  c->nb_codec_configs = 0;
183 
184  for (int i = 0; i < c->nb_audio_elements; i++)
185  ff_iamf_free_audio_element(&c->audio_elements[i]);
186  av_freep(&c->audio_elements);
187  c->nb_audio_elements = 0;
188 
189  for (int i = 0; i < c->nb_mix_presentations; i++)
190  ff_iamf_free_mix_presentation(&c->mix_presentations[i]);
191  av_freep(&c->mix_presentations);
192  c->nb_mix_presentations = 0;
193 
194  for (int i = 0; i < c->nb_param_definitions; i++)
195  av_free(c->param_definitions[i]);
196  av_freep(&c->param_definitions);
197  c->nb_param_definitions = 0;
198 }
iamf.h
ff_iamf_free_mix_presentation
void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation)
Definition: iamf.c:158
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:426
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:395
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:429
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:329
AV_CHANNEL_LAYOUT_7POINT2POINT3
#define AV_CHANNEL_LAYOUT_7POINT2POINT3
Definition: channel_layout.h:427
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:428
AV_CHANNEL_LAYOUT_7POINT1POINT2
#define AV_CHANNEL_LAYOUT_7POINT1POINT2
Definition: channel_layout.h:425
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:247
AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_SURROUND
Definition: channel_layout.h:398
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:417
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:410
AV_CHANNEL_LAYOUT_5POINT1POINT2
#define AV_CHANNEL_LAYOUT_5POINT1POINT2
Definition: channel_layout.h:420
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:433
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
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:319
ff_iamf_sound_system_map
const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14]
Definition: iamf.c:120
ff_iamf_uninit_context
void ff_iamf_uninit_context(IAMFContext *c)
Definition: iamf.c:172
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:424
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:143
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:431
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:394
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_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_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_5POINT1
Definition: channel_layout.h:405
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