FFmpeg: libavformat/iamf_parse.c Source File
Go to the documentation of this file. 1 /*
2 * Immersive Audio Model and Formats parsing
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
35
38 {
40
41 if (left < 11 || codec_config->audio_roll_distance >= 0)
43
47
53
56
57 return 0;
58 }
59
62 {
64 int object_type_id,
codec_id, stream_type;
66
69
73
75 if (object_type_id != 0x40)
77
79 if (((stream_type >> 2) != 5) || ((stream_type >> 1) & 1))
81
85
89
94
95 // We pad extradata here because avpriv_mpeg4audio_get_config2() needs it.
99
106
111
113
114 return 0;
115 }
116
119 {
121
124
125 avio_skip(pb, 4);
// METADATA_BLOCK_HEADER
126
130
134
138
141
142 return 0;
143 }
144
147 {
148 static const enum AVCodecID sample_fmt[2][3] = {
151 };
153 int sample_size = (
avio_r8(pb) / 8 - 2);
// 16, 24, 32
156
159
162
163 return 0;
164 }
165
167 {
171 uint8_t *buf;
173 unsigned codec_config_id, nb_samples,
codec_id;
174 int16_t audio_roll_distance;
176
178 if (!buf)
180
184
187
192
196 break;
199 break;
202 break;
203 default:
205 break;
206 }
207
208 for (
int i = 0;
i <
c->nb_codec_configs;
i++)
209 if (
c->codec_configs[
i]->codec_config_id == codec_config_id) {
212 }
213
218 }
219 c->codec_configs =
tmp;
220
221 codec_config =
av_mallocz(
sizeof(*codec_config));
222 if (!codec_config) {
225 }
226
228 codec_config->
codec_id = avcodec_id;
231
235 break;
238 break;
241 break;
244 break;
245 default:
246 break;
247 }
250
255 }
256
257 c->codec_configs[
c->nb_codec_configs++] = codec_config;
258
262
267 if (codec_config)
270 }
272 }
273
275 {
279
286 break;
288 uint8_t buf[6];
290
295
298 if (
ret ==
AOT_ESCAPE)
// violates section 3.11.2, but better check for it
304
314 }
317
319 break;
320 }
322 uint8_t buf[13];
324
329
341
343 break;
344 }
345 }
346
347 return 0;
348 }
349
353 {
354 int nb_layers, k = 0;
355
356 nb_layers =
avio_r8(pb) >> 5;
// get_bits(&gb, 3);
357 // skip_bits(&gb, 5); //reserved
358
359 if (nb_layers > 6 || nb_layers == 0)
361
363 if (!audio_element->
layers)
365
367 for (
int i = 0, n = 0;
i < nb_layers;
i++) {
370 int loudspeaker_layout, output_gain_is_present_flag;
371 int substream_count, coupled_substream_count;
372 int expanded_loudspeaker_layout = -1;
374
376 if (!layer)
378
379 loudspeaker_layout = byte >> 4; // get_bits(&gb, 4);
380 output_gain_is_present_flag = (byte >> 3) & 1; //get_bits1(&gb);
381 if ((byte >> 2) & 1)
382 layer->
flags |= AV_IAMF_LAYER_FLAG_RECON_GAIN;
384 coupled_substream_count =
avio_r8(pb);
385
388
391 if (output_gain_is_present_flag) {
394 }
395
396 if (!
i && loudspeaker_layout == 15)
397 expanded_loudspeaker_layout =
avio_r8(pb);
398 if (expanded_loudspeaker_layout > 0 && expanded_loudspeaker_layout < 13) {
400 } else if (loudspeaker_layout < 10) {
404 } else
406 .nb_channels = substream_count +
407 coupled_substream_count };
408
409 for (int j = 0; j < substream_count; j++) {
411
414
418 }
419
424
425 for (int j = 0; j < n; j++)
427
429 while (coupled_substream_count--) {
458 }
459 }
460
462 while (substream_count--) {
466 }
470 }
471 }
472
476 } else // AV_CHANNEL_ORDER_UNSPEC
478 }
479
480 return 0;
481 }
482
486 {
488 unsigned ambisonics_mode;
489 int output_channel_count, substream_count, order;
491
493 if (ambisonics_mode > 1)
495
496 output_channel_count =
avio_r8(pb);
// C
497 substream_count =
avio_r8(pb);
// N
498 if (audio_element->
nb_substreams != substream_count || output_channel_count == 0)
500
501 order =
floor(sqrt(output_channel_count - 1));
502 /* incomplete order - some harmonics are missing */
503 if ((order + 1) * (order + 1) != output_channel_count)
505
507 if (!audio_element->
layers)
509
512
514 if (!layer)
516
518 if (ambisonics_mode == 0) {
519 for (
int i = 0;
i < substream_count;
i++) {
521
523
527 }
528
532
533 for (
int i = 0;
i < output_channel_count;
i++)
535
539 } else {
540 int coupled_substream_count =
avio_r8(pb);
// M
541 int nb_demixing_matrix = substream_count + coupled_substream_count;
542 int demixing_matrix_size = nb_demixing_matrix * output_channel_count;
543
545
550
551 for (
int i = 0;
i < demixing_matrix_size;
i++)
553
554 for (
int i = 0;
i < substream_count;
i++) {
556
559
560
564 }
565 }
566
567 return 0;
568 }
569
574 {
577 unsigned int parameter_id, parameter_rate,
mode;
578 unsigned int duration = 0, constant_subblock_duration = 0, nb_subblocks = 0;
579 unsigned int total_duration = 0;
580 size_t param_size;
581
583
584 for (
int i = 0;
i <
c->nb_param_definitions;
i++)
585 if (
c->param_definitions[
i]->param->parameter_id == parameter_id) {
587 break;
588 }
589
592
598 if (constant_subblock_duration == 0)
600 else {
601 nb_subblocks =
duration / constant_subblock_duration;
603 }
604 }
605
607 if (!param)
609
610 for (
int i = 0;
i < nb_subblocks;
i++) {
612 unsigned int subblock_duration = constant_subblock_duration;
613
614 if (constant_subblock_duration == 0) {
616 total_duration += subblock_duration;
617 }
else if (
i == nb_subblocks - 1)
618 subblock_duration =
duration -
i * constant_subblock_duration;
619
623 mix->subblock_duration = subblock_duration;
624 break;
625 }
629 // DefaultDemixingInfoParameterData
633 break;
634 }
638 break;
639 }
640 default:
643 }
644 }
645
646 if (!
mode && !constant_subblock_duration && total_duration !=
duration) {
650 }
651
657
663 }
664 } else {
666 sizeof(*
c->param_definitions));
670 }
671 c->param_definitions =
tmp;
672
677 }
682
684 }
685
687 *out_param_definition = param;
688
689 return 0;
690 }
691
693 {
699 uint8_t *buf;
700 unsigned audio_element_id, nb_substreams, codec_config_id, num_parameters;
701 int audio_element_type,
ret;
702
704 if (!buf)
706
710
713
715
716 for (
int i = 0;
i <
c->nb_audio_elements;
i++)
717 if (
c->audio_elements[
i]->audio_element_id == audio_element_id) {
721 }
722
723 audio_element_type =
avio_r8(pbc) >> 5;
725 av_log(
s,
AV_LOG_DEBUG,
"Unknown audio_element_type referenced in an audio element. Ignoring\n");
728 }
729
731
733 if (!codec_config) {
734 av_log(
s,
AV_LOG_ERROR,
"Non existent codec config id %d referenced in an audio element\n", codec_config_id);
737 }
738
743 }
744
749 }
750 c->audio_elements =
tmp;
751
752 audio_element =
av_mallocz(
sizeof(*audio_element));
753 if (!audio_element) {
756 }
757
765 }
767
769 if (!element) {
772 }
774
776
779
784 }
785
787
793
802 }
806 break;
807 }
808 }
809
811 if (num_parameters > 2 && audio_element_type == 0) {
813 " for Channel representations\n", num_parameters);
816 }
817 if (num_parameters && audio_element_type != 0) {
819 " for Scene representations\n", num_parameters);
822 }
823
824 for (
int i = 0;
i < num_parameters;
i++) {
826
834 }
840 }
842 } else {
845 }
848 }
849
858 } else {
860 }
861
862 c->audio_elements[
c->nb_audio_elements++] = audio_element;
863
867
874 }
875
877 {
878 uint8_t buf[128];
879
881
887 if (!*label)
889
890 return 0;
891 }
892
894 {
899 uint8_t *buf;
900 unsigned nb_submixes, mix_presentation_id;
902
904 if (!buf)
906
910
913
915
916 for (
int i = 0;
i <
c->nb_mix_presentations;
i++)
917 if (
c->mix_presentations[
i]->mix_presentation_id == mix_presentation_id) {
921 }
922
927 }
928 c->mix_presentations =
tmp;
929
930 mix_presentation =
av_mallocz(
sizeof(*mix_presentation));
931 if (!mix_presentation) {
934 }
935
941 }
943
951 }
952
957 }
958
960 char *annotation =
NULL;
968 }
969
971 for (
int i = 0;
i < nb_submixes;
i++) {
973 unsigned nb_elements, nb_layouts;
974
976 if (!sub_mix) {
979 }
980
982 for (int j = 0; j < nb_elements; j++) {
985 unsigned int rendering_config_extension_size;
986
988 if (!submix_element) {
991 }
992
994
995 for (
int k = 0; k <
c->nb_audio_elements; k++)
996 if (
c->audio_elements[k]->audio_element_id == submix_element->
audio_element_id) {
997 audio_element =
c->audio_elements[k];
998 break;
999 }
1000
1001 if (!audio_element) {
1002 av_log(
s,
AV_LOG_ERROR,
"Invalid Audio Element with id %u referenced by Mix Parameters %u\n",
1006 }
1007
1008 for (
int k = 0; k < mix_presentation->
count_label; k++) {
1009 char *annotation =
NULL;
1017 }
1018
1020
1022 avio_skip(pbc, rendering_config_extension_size);
1023
1030 }
1031
1036
1038 for (int j = 0; j < nb_layouts; j++) {
1040 int info_type;
1042
1044 if (!submix_layout) {
1047 }
1048
1056 }
1058 int sound_system;
1059 sound_system = (byte >> 2) & 0xF;
1063 }
1065 } else
1067
1071
1072 if (info_type & 1)
1074 if (info_type & 2) {
1075 unsigned int num_anchored_loudness =
avio_r8(pbc);
1076
1077 for (int k = 0; k < num_anchored_loudness; k++) {
1078 unsigned int anchor_element =
avio_r8(pbc);
1084 else
1086 }
1087 }
1088
1089 if (info_type & 0xFC) {
1092 }
1093 }
1094 }
1095
1096 c->mix_presentations[
c->nb_mix_presentations++] = mix_presentation;
1097
1101
1108 }
1109
1112 unsigned *skip_samples, unsigned *discard_padding)
1113 {
1115 int ret, extension_flag, trimming, start;
1116 unsigned skip = 0, discard = 0;
1118
1122
1127
1129 if (*obu_size > INT_MAX)
1131
1133
1134 if (trimming) {
1135 discard =
get_leb(&gb);
// num_samples_to_trim_at_end
1136 skip =
get_leb(&gb);
// num_samples_to_trim_at_start
1137 }
1138
1139 if (skip_samples)
1140 *skip_samples =
skip;
1141 if (discard_padding)
1142 *discard_padding = discard;
1143
1144 if (extension_flag) {
1145 unsigned int extension_bytes;
1146 extension_bytes =
get_leb(&gb);
1147 if (extension_bytes > INT_MAX / 8)
1150 }
1151
1154
1155 size = *obu_size + start;
1158
1160 *start_pos =
size - *obu_size;
1161
1163 }
1164
1166 int max_size, void *log_ctx)
1167 {
1170
1171 while (1) {
1172 unsigned obu_size;
1175
1182
1184 if (len < 0 || obu_size > max_size) {
1188 }
1189
1192 break;
1193 }
1194
1199 break;
1202 break;
1205 break;
1206 default: {
1210 break;
1211 }
1212 }
1216 }
1217 max_size -= obu_size + start_pos;
1218 if (max_size < 0)
1220 if (!max_size)
1221 break;
1222 }
1223
1224 return 0;
1225 }
static int update_extradata(AVCodecParameters *codecpar)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
@ AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS
The layout follows the loudspeaker sound system convention of ITU-2051-3.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define MP4DecConfigDescrTag
void ffio_init_context(FFIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
static int mix(int c0, int c1)
static int get_bits_left(GetBitContext *gb)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define AV_CH_TOP_SIDE_LEFT
enum AVMediaType codec_type
General type of the encoded data.
#define AV_CHANNEL_LAYOUT_STEREO
static int put_bytes_output(const PutBitContext *s)
const AVCodecTag ff_mp4_obj_type[]
This struct describes the properties of an encoded stream.
unsigned int default_w
Default weight value as defined in section 3.6 of IAMF.
unsigned int nb_substreams
AVIAMFParamDefinition * av_iamf_param_definition_alloc(enum AVIAMFParamDefinitionType type, unsigned int nb_subblocks, size_t *out_size)
Allocates memory for AVIAMFParamDefinition, plus an array of.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int get_bits_count(const GetBitContext *s)
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
#define AV_CH_TOP_FRONT_RIGHT
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
int seek_preroll
Audio only.
union AVChannelLayout::@488 u
Details about which channels are present in this layout.
int error
contains the error code or 0 if no error happened
enum AVIAMFSubmixLayoutType layout_type
#define AV_CH_TOP_FRONT_LEFT
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Parameters as defined in section 3.6.1 of IAMF.
AVRational default_mix_gain
Default mix gain value to apply when there are no AVIAMFParamDefinition with element_mix_config's par...
enum AVChannelOrder order
Channel order used in this layout.
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
static int ambisonics_config(void *s, AVIOContext *pb, IAMFAudioElement *audio_element, const IAMFCodecConfig *codec_config)
int nb_channels
Number of channels in this layout.
static int flac_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len)
const AVIAMFMixPresentation * cmix
#define AV_CH_TOP_BACK_LEFT
AVRational digital_peak
The digital (sampled) peak value of the audio signal, as defined in ITU-1770-4.
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVRational integrated_loudness
The program integrated loudness information, as defined in ITU-1770-4.
AVIAMFSubmix * av_iamf_mix_presentation_add_submix(AVIAMFMixPresentation *mix_presentation)
Allocate a submix and add it to a given AVIAMFMixPresentation.
#define MP4DecSpecificDescrTag
@ AOT_ESCAPE
Y Escape Value.
Submix layout as defined in section 3.7.6 of IAMF.
static int put_bits_left(PutBitContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
AVIAMFAudioElement * av_iamf_audio_element_alloc(void)
Allocates a AVIAMFAudioElement, and initializes its fields with default values.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
enum AVIAMFAudioElementType audio_element_type
Audio element type as defined in section 3.6 of IAMF.
static int opus_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len)
Recon Gain Info Parameter Data as defined in section 3.8.3 of IAMF.
#define AV_CH_LAYOUT_STEREO
static int param_parse(void *s, IAMFContext *c, AVIOContext *pb, unsigned int type, const IAMFAudioElement *audio_element, AVIAMFParamDefinition **out_param_definition)
static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
AVIAMFAudioElement * element
element backs celement iff the AVIAMFAudioElement is owned by this structure.
@ AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN
Subblocks are of struct type AVIAMFReconGain.
AVDictionary * annotations
A dictionary of strings describing the submix in different languages.
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_CH_LOW_FREQUENCY
int frame_size
Audio only.
AVIAMFSubmixLayout * av_iamf_submix_add_layout(AVIAMFSubmix *submix)
Allocate a submix layout and add it to a given AVIAMFSubmix.
int avpriv_mpeg4audio_get_config2(MPEG4AudioConfig *c, const uint8_t *buf, int size, int sync_extension, void *logctx)
Parse MPEG-4 systems extradata from a raw buffer to retrieve audio configuration.
unsigned int audio_substream_id
unsigned int substream_count
AVRational dialogue_anchored_loudness
The Dialogue loudness information, as defined in ITU-1770-4.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static __device__ float floor(float a)
static av_always_inline void * av_iamf_param_definition_get_subblock(const AVIAMFParamDefinition *par, unsigned int idx)
Get the subblock at the specified.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum AVIAMFHeadphonesMode headphones_rendering_mode
A value that indicates whether the referenced channel-based Audio Element shall be rendered to stereo...
unsigned int ffio_read_leb(AVIOContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_CH_TOP_SIDE_RIGHT
static void put_bits63(PutBitContext *s, int n, uint64_t value)
Write up to 63 bits into a bitstream.
AVChannelLayout ch_layout
int ff_iamfdec_read_descriptors(IAMFContext *c, AVIOContext *pb, int max_size, void *log_ctx)
unsigned int audio_element_id
Demixing Info Parameter Data as defined in section 3.8.2 of IAMF.
@ AV_CHANNEL_ORDER_AMBISONIC
The audio is represented as the decomposition of the sound field into spherical harmonics.
static unsigned get_leb(GetBitContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
Rational number (pair of numerator and denominator).
unsigned int duration
The accumulated duration of all blocks in this parameter definition, in units of 1 / parameter_rate.
static unsigned int get_bits1(GetBitContext *s)
static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
A layer defining a Channel Layout in the Audio Element.
#define FLAC_STREAMINFO_SIZE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
#define AV_CH_FRONT_CENTER
AVChannelLayout ch_layout
Audio only.
const AVIAMFAudioElement * celement
#define AV_CH_FRONT_LEFT_OF_CENTER
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
int ff_mp4_read_descr(void *logctx, AVIOContext *pb, int *tag)
int sample_rate
Audio only.
@ AV_CHAN_FRONT_RIGHT_OF_CENTER
int ff_iamf_parse_obu_header(const uint8_t *buf, int buf_size, unsigned *obu_size, int *start_pos, enum IAMF_OBU_Type *type, unsigned *skip_samples, unsigned *discard_padding)
unsigned int output_gain_flags
Output gain channel flags as defined in section 3.6.2 of IAMF.
AVCodecID
Identify the syntax and semantics of the bitstream.
unsigned int audio_element_id
The id of the Audio Element this submix element references.
int extradata_size
Size of the extradata content in bytes.
Submix layout as defined in section 3.7 of IAMF.
unsigned int subblock_duration
Duration for the given subblock, in units of 1 / parameter_rate.
unsigned int subblock_duration
Duration for the given subblock, in units of 1 / parameter_rate.
An AVChannelLayout holds information about the channel layout of audio data.
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
static AVRational av_make_q(int num, int den)
Create an AVRational.
unsigned int coupled_substream_count
#define MKBETAG(a, b, c, d)
AVIAMFMixPresentation * av_iamf_mix_presentation_alloc(void)
Allocates a AVIAMFMixPresentation, and initializes its fields with default values.
static const uint8_t header[24]
int avio_r8(AVIOContext *s)
IAMFSubStream * substreams
unsigned int constant_subblock_duration
The duration of every subblock in the case where all subblocks, with the optional exception of the la...
AVIAMFSubmixElement * av_iamf_submix_add_element(AVIAMFSubmix *submix)
Allocate a submix element and add it to a given AVIAMFSubmix.
int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
Change the AVChannelOrder of a channel layout.
Information on how to combine one or more audio streams, as defined in section 3.6 of IAMF.
static int ipcm_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
@ AV_CHAN_TOP_FRONT_RIGHT
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define AV_CH_TOP_BACK_RIGHT
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Mix Gain Parameter Data as defined in section 3.8.1 of IAMF.
#define AV_CH_FRONT_RIGHT_OF_CENTER
@ AV_CHAN_FRONT_LEFT_OF_CENTER
int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
Initialize a custom channel layout with the specified number of channels.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
#define i(width, name, range_min, range_max)
unsigned int parameter_id
Identifier for the parameter substream.
AVRational * demixing_matrix
Demixing matrix as defined in section 3.6.3 of IAMF.
#define av_malloc_array(a, b)
Information on how to render and mix one or more AVIAMFAudioElement to generate the final audio outpu...
static int aac_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len, void *logctx)
static int param_definition(const IAMFContext *iamf, const IAMFParamDefinition *param_def, AVIOContext *dyn_bc, void *log_ctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
unsigned int nb_subblocks
Number of subblocks in the array.
@ AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
unsigned int avio_rb16(AVIOContext *s)
#define AV_INPUT_BUFFER_PADDING_SIZE
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
static int label_string(AVIOContext *pb, char **label)
AVRational default_mix_gain
Default mix gain value to apply when there are no AVIAMFParamDefinition with output_mix_config's para...
AVRational album_anchored_loudness
The Album loudness information, as defined in ITU-1770-4.
uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, uint64_t mask)
Find out what channels from a given set are present in a channel layout, without regard for their pos...
AVRational true_peak
The true peak of the audio signal, as defined in ITU-1770-4.
AVChannelLayout sound_system
Channel layout matching one of Sound Systems A to J of ITU-2051-3, plus 7.1.2ch, 3....
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static av_const int sign_extend(int val, unsigned bits)
int eof_reached
true if was unable to read due to error or eof
@ AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN
Subblocks are of struct type AVIAMFMixGain.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static int mix_presentation_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
AVIAMFLayer * av_iamf_audio_element_add_layer(AVIAMFAudioElement *audio_element)
Allocate a layer and add it to a given AVIAMFAudioElement.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
char * av_strdup(const char *s)
Duplicate a string.
AVIAMFParamDefinition * demixing_info
Demixing information used to reconstruct a scalable channel audio representation.
unsigned int dmixp_mode
Pre-defined combination of demixing parameters.
AVIAMFParamDefinition * output_mix_config
Information required for post-processing the mixed audio signal to generate the audio signal for play...
enum AVIAMFAmbisonicsMode ambisonics_mode
Ambisonics mode as defined in section 3.6.3 of IAMF.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define AV_CHANNEL_LAYOUT_BINAURAL
#define AV_CHANNEL_LAYOUT_MONO
@ AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL
The layout is binaural.
unsigned int flags
A bitmask which may contain a combination of AV_IAMF_LAYER_FLAG_* flags.
AVRational output_gain
Output gain as defined in section 3.6.2 of IAMF.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
AVIAMFParamDefinition * element_mix_config
Information required required for applying any processing to the referenced and rendered Audio Elemen...
@ AV_CHAN_AMBISONIC_BASE
Range of channels between AV_CHAN_AMBISONIC_BASE and AV_CHAN_AMBISONIC_END represent Ambisonic compon...
unsigned int parameter_rate
Sample rate for the parameter substream.
Submix element as defined in section 3.7 of IAMF.
@ AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL
unsigned int codec_config_id
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
AVIAMFParamDefinition * recon_gain_info
Recon gain information used to reconstruct a scalable channel audio representation.
AVIAMFMixPresentation * mix
mix backs cmix iff the AVIAMFMixPresentation is owned by this structure.
static int scalable_channel_layout_config(void *s, AVIOContext *pb, IAMFAudioElement *audio_element, const IAMFCodecConfig *codec_config)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
AVCodecParameters * codecpar
unsigned int mix_presentation_id
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
@ AV_IAMF_PARAMETER_DEFINITION_DEMIXING
Subblocks are of struct type AVIAMFDemixingInfo.
Generated on Tue Nov 18 2025 19:23:27 for FFmpeg by
doxygen
1.8.17