1 /*
2 * Immersive Audio Model and Formats helper functions and defines
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
22 #include <stddef.h>
23 #include <stdint.h>
24
31
32 #define IAMF_ADD_FUNC_TEMPLATE(parent_type, parent_name, child_type, child_name, suffix) \
33 child_type *av_iamf_ ## parent_name ## _add_ ## child_name(parent_type *parent_name) \
34 { \
35 child_type **child_name ## suffix, *child_name; \
36 \
37 if (parent_name->nb_## child_name ## suffix == UINT_MAX) \
38 return NULL; \
39 \
40 child_name ## suffix = av_realloc_array(parent_name->child_name ## suffix, \
41 parent_name->nb_## child_name ## suffix + 1, \
42 sizeof(*parent_name->child_name ## suffix)); \
43 if (!child_name ## suffix) \
44 return NULL; \
45 \
46 parent_name->child_name ## suffix = child_name ## suffix; \
47 \
48 child_name = parent_name->child_name ## suffix[parent_name->nb_## child_name ## suffix] \
49 = av_mallocz(sizeof(*child_name)); \
50 if (!child_name) \
51 return NULL; \
52 \
53 child_name->av_class = &child_name ## _class; \
54 av_opt_set_defaults(child_name); \
55 parent_name->nb_## child_name ## suffix++; \
56 \
57 return child_name; \
58 }
59
60 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
61
62 //
63 // Param Definition
64 //
65 #define OFFSET(x) offsetof(AVIAMFMixGain, x)
72 {
"control_point_relative_time",
"set control_point_relative_time",
OFFSET(control_point_relative_time),
AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0.0, 1.0,
FLAGS },
74 };
75
81 };
82
83 #undef OFFSET
84 #define OFFSET(x) offsetof(AVIAMFDemixingInfo, x)
89 };
90
96 };
97
98 #undef OFFSET
99 #define OFFSET(x) offsetof(AVIAMFReconGain, x)
103 };
104
110 };
111
112 #undef OFFSET
113 #define OFFSET(x) offsetof(AVIAMFParamDefinition, x)
118 {
"constant_subblock_duration",
"set constant_subblock_duration",
OFFSET(constant_subblock_duration),
AV_OPT_TYPE_UINT, {.i64 = 0 }, 0, UINT_MAX,
FLAGS },
120 };
121
123 {
124 uintptr_t
i = (uintptr_t)*opaque;
126
130 break;
133 break;
136 break;
137 default:
138 break;
139 }
140
142 *opaque = (
void*)(
i + 1);
144 }
145
152 };
153
155 {
157 }
158
160 unsigned int nb_subblocks,
size_t *
out_size)
161 {
162
163 struct MixGainStruct {
166 };
167 struct DemixStruct {
170 };
171 struct ReconGainStruct {
174 };
175 size_t subblocks_offset, subblock_size;
178
181 subblocks_offset = offsetof(struct MixGainStruct, m);
183 break;
185 subblocks_offset = offsetof(struct DemixStruct, d);
187 break;
189 subblocks_offset = offsetof(
struct ReconGainStruct,
r);
191 break;
192 default:
194 }
195
196 size = subblocks_offset;
197 if (nb_subblocks > (SIZE_MAX -
size) / subblock_size)
199 size += subblock_size * nb_subblocks;
200
202 if (!par)
204
207
212
213 for (
int i = 0;
i < nb_subblocks;
i++) {
215
219 break;
222 break;
225 break;
226 default:
228 }
229
231 }
232
235
236 return par;
237 }
238
239 //
240 // Audio Element
241 //
242 #undef OFFSET
243 #define OFFSET(x) offsetof(AVIAMFLayer, x)
247 {.i64 = 0 }, 0, AV_IAMF_LAYER_FLAG_RECON_GAIN,
FLAGS, .unit =
"flags" },
249 {.i64 = AV_IAMF_LAYER_FLAG_RECON_GAIN }, INT_MIN, INT_MAX,
FLAGS, .unit =
"flags"},
251 {.i64 = 0 }, 0, (1 << 6) - 1,
FLAGS, .unit =
"output_gain_flags" },
253 {.i64 = 1 << 5 }, INT_MIN, INT_MAX,
FLAGS, .unit =
"output_gain_flags"},
255 {.i64 = 1 << 4 }, INT_MIN, INT_MAX,
FLAGS, .unit =
"output_gain_flags"},
257 {.i64 = 1 << 3 }, INT_MIN, INT_MAX,
FLAGS, .unit =
"output_gain_flags"},
259 {.i64 = 1 << 2 }, INT_MIN, INT_MAX,
FLAGS, .unit =
"output_gain_flags"},
261 {.i64 = 1 << 1 }, INT_MIN, INT_MAX,
FLAGS, .unit =
"output_gain_flags"},
263 {.i64 = 1 << 0 }, INT_MIN, INT_MAX,
FLAGS, .unit =
"output_gain_flags"},
273 };
274
280 };
281
282 #undef OFFSET
283 #define OFFSET(x) offsetof(AVIAMFAudioElement, x)
294 };
295
297 {
298 uintptr_t
i = (uintptr_t)*opaque;
300
303
305 *opaque = (
void*)(
i + 1);
307 }
308
315 };
316
318 {
320 }
321
323 {
325
326 if (audio_element) {
329 }
330
331 return audio_element;
332 }
333
335
337 {
339
340 if (!audio_element)
341 return;
342
348 }
350
354 }
355
356 //
357 // Mix Presentation
358 //
359 #undef OFFSET
360 #define OFFSET(x) offsetof(AVIAMFSubmixElement, x)
362 {
"headphones_rendering_mode",
"Headphones rendering mode",
OFFSET(headphones_rendering_mode),
AV_OPT_TYPE_INT,
372 };
373
375 {
377 if (!prev)
379
381 }
382
384 {
385 uintptr_t
i = (uintptr_t)*opaque;
387
390
392 *opaque = (
void*)(
i + 1);
394 }
395
403 };
404
406
407 #undef OFFSET
408 #define OFFSET(x) offsetof(AVIAMFSubmixLayout, x)
421 {
"dialog_anchored_loudness",
"Anchored loudness (Dialog)",
OFFSET(dialogue_anchored_loudness),
AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, -128.0, 128.0,
FLAGS },
424 };
425
431 };
432
434
435 #undef OFFSET
436 #define OFFSET(x) offsetof(AVIAMFSubmix, x)
440 };
441
443 {
445 if (!prev)
447
449 }
450
452 {
453 uintptr_t
i = (uintptr_t)*opaque;
455
457 case 0:
459 break;
460 case 1:
462 break;
463 case 2:
465 break;
466 default:
467 break;
468 }
469
471 *opaque = (
void*)(
i + 1);
473 }
474
482 };
483
484 #undef OFFSET
485 #define OFFSET(x) offsetof(AVIAMFMixPresentation, x)
489 };
490
491 #undef OFFSET
492 #undef FLAGS
493
495 {
496 uintptr_t
i = (uintptr_t)*opaque;
498
501
503 *opaque = (
void*)(
i + 1);
505 }
506
513 };
514
516 {
518 }
519
521 {
523
524 if (mix_presentation) {
527 }
528
529 return mix_presentation;
530 }
531
533
535 {
537
538 if (!mix_presentation)
539 return;
540
548 }
550 for (
int j = 0; j < sub_mix->
nb_layouts; j++) {
554 }
558 }
561
563 }