FFmpeg
iamf_parse.c
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 
22 #include "libavutil/avassert.h"
23 #include "libavutil/iamf.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/log.h"
26 #include "libavutil/mem.h"
27 #include "libavcodec/get_bits.h"
28 #include "libavcodec/flac.h"
29 #include "libavcodec/leb.h"
30 #include "libavcodec/mpeg4audio.h"
31 #include "libavcodec/put_bits.h"
32 #include "avio_internal.h"
33 #include "iamf_parse.h"
34 #include "isom.h"
35 
36 static int opus_decoder_config(IAMFCodecConfig *codec_config,
37  AVIOContext *pb, int len)
38 {
39  int left = len - avio_tell(pb);
40 
41  if (left < 11)
42  return AVERROR_INVALIDDATA;
43 
44  codec_config->extradata = av_malloc(left + 8);
45  if (!codec_config->extradata)
46  return AVERROR(ENOMEM);
47 
48  AV_WB32(codec_config->extradata, MKBETAG('O','p','u','s'));
49  AV_WB32(codec_config->extradata + 4, MKBETAG('H','e','a','d'));
50  codec_config->extradata_size = avio_read(pb, codec_config->extradata + 8, left);
51  if (codec_config->extradata_size < left)
52  return AVERROR_INVALIDDATA;
53 
54  codec_config->extradata_size += 8;
55  codec_config->sample_rate = 48000;
56 
57  return 0;
58 }
59 
60 static int aac_decoder_config(IAMFCodecConfig *codec_config,
61  AVIOContext *pb, int len, void *logctx)
62 {
63  MPEG4AudioConfig cfg = { 0 };
64  int object_type_id, codec_id, stream_type;
65  int ret, tag, left;
66 
67  tag = avio_r8(pb);
69  return AVERROR_INVALIDDATA;
70 
71  object_type_id = avio_r8(pb);
72  if (object_type_id != 0x40)
73  return AVERROR_INVALIDDATA;
74 
75  stream_type = avio_r8(pb);
76  if (((stream_type >> 2) != 5) || ((stream_type >> 1) & 1))
77  return AVERROR_INVALIDDATA;
78 
79  avio_skip(pb, 3); // buffer size db
80  avio_skip(pb, 4); // rc_max_rate
81  avio_skip(pb, 4); // avg bitrate
82 
83  codec_id = ff_codec_get_id(ff_mp4_obj_type, object_type_id);
84  if (codec_id && codec_id != codec_config->codec_id)
85  return AVERROR_INVALIDDATA;
86 
87  tag = avio_r8(pb);
89  return AVERROR_INVALIDDATA;
90 
91  left = len - avio_tell(pb);
92  if (left <= 0)
93  return AVERROR_INVALIDDATA;
94 
95  codec_config->extradata = av_malloc(left);
96  if (!codec_config->extradata)
97  return AVERROR(ENOMEM);
98 
99  codec_config->extradata_size = avio_read(pb, codec_config->extradata, left);
100  if (codec_config->extradata_size < left)
101  return AVERROR_INVALIDDATA;
102 
103  ret = avpriv_mpeg4audio_get_config2(&cfg, codec_config->extradata,
104  codec_config->extradata_size, 1, logctx);
105  if (ret < 0)
106  return ret;
107 
108  codec_config->sample_rate = cfg.sample_rate;
109 
110  return 0;
111 }
112 
113 static int flac_decoder_config(IAMFCodecConfig *codec_config,
114  AVIOContext *pb, int len)
115 {
116  int left;
117 
118  avio_skip(pb, 4); // METADATA_BLOCK_HEADER
119 
120  left = len - avio_tell(pb);
122  return AVERROR_INVALIDDATA;
123 
124  codec_config->extradata = av_malloc(left);
125  if (!codec_config->extradata)
126  return AVERROR(ENOMEM);
127 
128  codec_config->extradata_size = avio_read(pb, codec_config->extradata, left);
129  if (codec_config->extradata_size < left)
130  return AVERROR_INVALIDDATA;
131 
132  codec_config->sample_rate = AV_RB24(codec_config->extradata + 10) >> 4;
133 
134  return 0;
135 }
136 
137 static int ipcm_decoder_config(IAMFCodecConfig *codec_config,
138  AVIOContext *pb, int len)
139 {
140  static const enum AVCodecID sample_fmt[2][3] = {
143  };
144  int sample_format = avio_r8(pb); // 0 = BE, 1 = LE
145  int sample_size = (avio_r8(pb) / 8 - 2); // 16, 24, 32
146  if (sample_format > 1 || sample_size > 2)
147  return AVERROR_INVALIDDATA;
148 
149  codec_config->codec_id = sample_fmt[sample_format][sample_size];
150  codec_config->sample_rate = avio_rb32(pb);
151 
152  if (len - avio_tell(pb))
153  return AVERROR_INVALIDDATA;
154 
155  return 0;
156 }
157 
158 static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
159 {
160  IAMFCodecConfig **tmp, *codec_config = NULL;
161  FFIOContext b;
162  AVIOContext *pbc;
163  uint8_t *buf;
164  enum AVCodecID avcodec_id;
165  unsigned codec_config_id, nb_samples, codec_id;
166  int16_t seek_preroll;
167  int ret;
168 
169  buf = av_malloc(len);
170  if (!buf)
171  return AVERROR(ENOMEM);
172 
173  ret = avio_read(pb, buf, len);
174  if (ret != len) {
175  if (ret >= 0)
177  goto fail;
178  }
179 
180  ffio_init_context(&b, buf, len, 0, NULL, NULL, NULL, NULL);
181  pbc = &b.pub;
182 
183  codec_config_id = ffio_read_leb(pbc);
184  codec_id = avio_rb32(pbc);
185  nb_samples = ffio_read_leb(pbc);
186  seek_preroll = avio_rb16(pbc);
187 
188  switch(codec_id) {
189  case MKBETAG('O','p','u','s'):
190  avcodec_id = AV_CODEC_ID_OPUS;
191  break;
192  case MKBETAG('m','p','4','a'):
193  avcodec_id = AV_CODEC_ID_AAC;
194  break;
195  case MKBETAG('f','L','a','C'):
196  avcodec_id = AV_CODEC_ID_FLAC;
197  break;
198  default:
199  avcodec_id = AV_CODEC_ID_NONE;
200  break;
201  }
202 
203  for (int i = 0; i < c->nb_codec_configs; i++)
204  if (c->codec_configs[i]->codec_config_id == codec_config_id) {
206  goto fail;
207  }
208 
209  tmp = av_realloc_array(c->codec_configs, c->nb_codec_configs + 1, sizeof(*c->codec_configs));
210  if (!tmp) {
211  ret = AVERROR(ENOMEM);
212  goto fail;
213  }
214  c->codec_configs = tmp;
215 
216  codec_config = av_mallocz(sizeof(*codec_config));
217  if (!codec_config) {
218  ret = AVERROR(ENOMEM);
219  goto fail;
220  }
221 
222  codec_config->codec_config_id = codec_config_id;
223  codec_config->codec_id = avcodec_id;
224  codec_config->nb_samples = nb_samples;
225  codec_config->seek_preroll = seek_preroll;
226 
227  switch(codec_id) {
228  case MKBETAG('O','p','u','s'):
229  ret = opus_decoder_config(codec_config, pbc, len);
230  break;
231  case MKBETAG('m','p','4','a'):
232  ret = aac_decoder_config(codec_config, pbc, len, s);
233  break;
234  case MKBETAG('f','L','a','C'):
235  ret = flac_decoder_config(codec_config, pbc, len);
236  break;
237  case MKBETAG('i','p','c','m'):
238  ret = ipcm_decoder_config(codec_config, pbc, len);
239  break;
240  default:
241  break;
242  }
243  if (ret < 0)
244  goto fail;
245 
246  c->codec_configs[c->nb_codec_configs++] = codec_config;
247 
248  len -= avio_tell(pbc);
249  if (len)
250  av_log(s, AV_LOG_WARNING, "Underread in codec_config_obu. %d bytes left at the end\n", len);
251 
252  ret = 0;
253 fail:
254  av_free(buf);
255  if (ret < 0) {
256  if (codec_config)
257  av_free(codec_config->extradata);
258  av_free(codec_config);
259  }
260  return ret;
261 }
262 
263 static int update_extradata(AVCodecParameters *codecpar)
264 {
265  GetBitContext gb;
266  PutBitContext pb;
267  int ret;
268 
269  switch(codecpar->codec_id) {
270  case AV_CODEC_ID_OPUS:
271  AV_WB8(codecpar->extradata + 9, codecpar->ch_layout.nb_channels);
272  break;
273  case AV_CODEC_ID_AAC: {
274  uint8_t buf[5];
275 
276  init_put_bits(&pb, buf, sizeof(buf));
277  ret = init_get_bits8(&gb, codecpar->extradata, codecpar->extradata_size);
278  if (ret < 0)
279  return ret;
280 
281  ret = get_bits(&gb, 5);
282  put_bits(&pb, 5, ret);
283  if (ret == AOT_ESCAPE) // violates section 3.11.2, but better check for it
284  put_bits(&pb, 6, get_bits(&gb, 6));
285  ret = get_bits(&gb, 4);
286  put_bits(&pb, 4, ret);
287  if (ret == 0x0f)
288  put_bits(&pb, 24, get_bits(&gb, 24));
289 
290  skip_bits(&gb, 4);
291  put_bits(&pb, 4, codecpar->ch_layout.nb_channels); // set channel config
292  ret = put_bits_left(&pb);
293  put_bits(&pb, ret, get_bits(&gb, ret));
294  flush_put_bits(&pb);
295 
296  memcpy(codecpar->extradata, buf, sizeof(buf));
297  break;
298  }
299  case AV_CODEC_ID_FLAC: {
300  uint8_t buf[13];
301 
302  init_put_bits(&pb, buf, sizeof(buf));
303  ret = init_get_bits8(&gb, codecpar->extradata, codecpar->extradata_size);
304  if (ret < 0)
305  return ret;
306 
307  put_bits32(&pb, get_bits_long(&gb, 32)); // min/max blocksize
308  put_bits64(&pb, 48, get_bits64(&gb, 48)); // min/max framesize
309  put_bits(&pb, 20, get_bits(&gb, 20)); // samplerate
310  skip_bits(&gb, 3);
311  put_bits(&pb, 3, codecpar->ch_layout.nb_channels - 1);
312  ret = put_bits_left(&pb);
313  put_bits(&pb, ret, get_bits(&gb, ret));
314  flush_put_bits(&pb);
315 
316  memcpy(codecpar->extradata, buf, sizeof(buf));
317  break;
318  }
319  }
320 
321  return 0;
322 }
323 
325  IAMFAudioElement *audio_element,
326  const IAMFCodecConfig *codec_config)
327 {
328  int nb_layers, k = 0;
329 
330  nb_layers = avio_r8(pb) >> 5; // get_bits(&gb, 3);
331  // skip_bits(&gb, 5); //reserved
332 
333  if (nb_layers > 6)
334  return AVERROR_INVALIDDATA;
335 
336  audio_element->layers = av_calloc(nb_layers, sizeof(*audio_element->layers));
337  if (!audio_element->layers)
338  return AVERROR(ENOMEM);
339 
340  audio_element->nb_layers = nb_layers;
341  for (int i = 0; i < nb_layers; i++) {
342  AVIAMFLayer *layer;
343  int loudspeaker_layout, output_gain_is_present_flag;
344  int substream_count, coupled_substream_count;
345  int ret, byte = avio_r8(pb);
346 
347  layer = av_iamf_audio_element_add_layer(audio_element->element);
348  if (!layer)
349  return AVERROR(ENOMEM);
350 
351  loudspeaker_layout = byte >> 4; // get_bits(&gb, 4);
352  output_gain_is_present_flag = (byte >> 3) & 1; //get_bits1(&gb);
353  if ((byte >> 2) & 1)
354  layer->flags |= AV_IAMF_LAYER_FLAG_RECON_GAIN;
355  substream_count = avio_r8(pb);
356  coupled_substream_count = avio_r8(pb);
357 
358  audio_element->layers[i].substream_count = substream_count;
359  audio_element->layers[i].coupled_substream_count = coupled_substream_count;
360  if (output_gain_is_present_flag) {
361  layer->output_gain_flags = avio_r8(pb) >> 2; // get_bits(&gb, 6);
362  layer->output_gain = av_make_q(sign_extend(avio_rb16(pb), 16), 1 << 8);
363  }
364 
365  if (loudspeaker_layout < 10)
366  av_channel_layout_copy(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[loudspeaker_layout]);
367  else
369  .nb_channels = substream_count +
370  coupled_substream_count };
371 
372  for (int j = 0; j < substream_count; j++) {
373  IAMFSubStream *substream = &audio_element->substreams[k++];
374 
375  substream->codecpar->ch_layout = coupled_substream_count-- > 0 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
377 
378  ret = update_extradata(substream->codecpar);
379  if (ret < 0)
380  return ret;
381  }
382 
383  }
384 
385  return 0;
386 }
387 
388 static int ambisonics_config(void *s, AVIOContext *pb,
389  IAMFAudioElement *audio_element,
390  const IAMFCodecConfig *codec_config)
391 {
392  AVIAMFLayer *layer;
393  unsigned ambisonics_mode;
394  int output_channel_count, substream_count, order;
395  int ret;
396 
397  ambisonics_mode = ffio_read_leb(pb);
398  if (ambisonics_mode > 1)
399  return 0;
400 
401  output_channel_count = avio_r8(pb); // C
402  substream_count = avio_r8(pb); // N
403  if (audio_element->nb_substreams != substream_count)
404  return AVERROR_INVALIDDATA;
405 
406  order = floor(sqrt(output_channel_count - 1));
407  /* incomplete order - some harmonics are missing */
408  if ((order + 1) * (order + 1) != output_channel_count)
409  return AVERROR_INVALIDDATA;
410 
411  audio_element->layers = av_mallocz(sizeof(*audio_element->layers));
412  if (!audio_element->layers)
413  return AVERROR(ENOMEM);
414 
415  audio_element->nb_layers = 1;
416  audio_element->layers->substream_count = substream_count;
417 
418  layer = av_iamf_audio_element_add_layer(audio_element->element);
419  if (!layer)
420  return AVERROR(ENOMEM);
421 
422  layer->ambisonics_mode = ambisonics_mode;
423  if (ambisonics_mode == 0) {
424  for (int i = 0; i < substream_count; i++) {
425  IAMFSubStream *substream = &audio_element->substreams[i];
426 
428 
429  ret = update_extradata(substream->codecpar);
430  if (ret < 0)
431  return ret;
432  }
433 
435  layer->ch_layout.nb_channels = output_channel_count;
436  layer->ch_layout.u.map = av_calloc(output_channel_count, sizeof(*layer->ch_layout.u.map));
437  if (!layer->ch_layout.u.map)
438  return AVERROR(ENOMEM);
439 
440  for (int i = 0; i < output_channel_count; i++)
441  layer->ch_layout.u.map[i].id = avio_r8(pb) + AV_CHAN_AMBISONIC_BASE;
442  } else {
443  int coupled_substream_count = avio_r8(pb); // M
444  int nb_demixing_matrix = substream_count + coupled_substream_count;
445  int demixing_matrix_size = nb_demixing_matrix * output_channel_count;
446 
447  audio_element->layers->coupled_substream_count = coupled_substream_count;
448 
449  layer->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_AMBISONIC, .nb_channels = output_channel_count };
450  layer->demixing_matrix = av_malloc_array(demixing_matrix_size, sizeof(*layer->demixing_matrix));
451  if (!layer->demixing_matrix)
452  return AVERROR(ENOMEM);
453 
454  for (int i = 0; i < demixing_matrix_size; i++)
455  layer->demixing_matrix[i] = av_make_q(sign_extend(avio_rb16(pb), 16), 1 << 8);
456 
457  for (int i = 0; i < substream_count; i++) {
458  IAMFSubStream *substream = &audio_element->substreams[i];
459 
460  substream->codecpar->ch_layout = coupled_substream_count-- > 0 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
462 
463 
464  ret = update_extradata(substream->codecpar);
465  if (ret < 0)
466  return ret;
467  }
468  }
469 
470  return 0;
471 }
472 
473 static int param_parse(void *s, IAMFContext *c, AVIOContext *pb,
474  unsigned int type,
475  const IAMFAudioElement *audio_element,
476  AVIAMFParamDefinition **out_param_definition)
477 {
479  AVIAMFParamDefinition *param;
480  unsigned int parameter_id, parameter_rate, mode;
481  unsigned int duration = 0, constant_subblock_duration = 0, nb_subblocks = 0;
482  size_t param_size;
483 
484  parameter_id = ffio_read_leb(pb);
485 
486  for (int i = 0; i < c->nb_param_definitions; i++)
487  if (c->param_definitions[i]->param->parameter_id == parameter_id) {
488  param_definition = c->param_definitions[i];
489  break;
490  }
491 
492  parameter_rate = ffio_read_leb(pb);
493  mode = avio_r8(pb) >> 7;
494 
495  if (mode == 0) {
496  duration = ffio_read_leb(pb);
497  if (!duration)
498  return AVERROR_INVALIDDATA;
499  constant_subblock_duration = ffio_read_leb(pb);
500  if (constant_subblock_duration == 0)
501  nb_subblocks = ffio_read_leb(pb);
502  else
503  nb_subblocks = duration / constant_subblock_duration;
504  }
505 
506  param = av_iamf_param_definition_alloc(type, nb_subblocks, &param_size);
507  if (!param)
508  return AVERROR(ENOMEM);
509 
510  for (int i = 0; i < nb_subblocks; i++) {
511  void *subblock = av_iamf_param_definition_get_subblock(param, i);
512  unsigned int subblock_duration = constant_subblock_duration;
513 
514  if (constant_subblock_duration == 0)
515  subblock_duration = ffio_read_leb(pb);
516 
517  switch (type) {
519  AVIAMFMixGain *mix = subblock;
520  mix->subblock_duration = subblock_duration;
521  break;
522  }
524  AVIAMFDemixingInfo *demix = subblock;
525  demix->subblock_duration = subblock_duration;
526  // DefaultDemixingInfoParameterData
527  av_assert0(audio_element);
528  demix->dmixp_mode = avio_r8(pb) >> 5;
529  audio_element->element->default_w = avio_r8(pb) >> 4;
530  break;
531  }
533  AVIAMFReconGain *recon = subblock;
534  recon->subblock_duration = subblock_duration;
535  break;
536  }
537  default:
538  av_free(param);
539  return AVERROR_INVALIDDATA;
540  }
541  }
542 
543  param->parameter_id = parameter_id;
544  param->parameter_rate = parameter_rate;
545  param->duration = duration;
546  param->constant_subblock_duration = constant_subblock_duration;
547  param->nb_subblocks = nb_subblocks;
548 
549  if (param_definition) {
550  if (param_definition->param_size != param_size || memcmp(param_definition->param, param, param_size)) {
551  av_log(s, AV_LOG_ERROR, "Incosistent parameters for parameter_id %u\n", parameter_id);
552  av_free(param);
553  return AVERROR_INVALIDDATA;
554  }
555  } else {
556  IAMFParamDefinition **tmp = av_realloc_array(c->param_definitions, c->nb_param_definitions + 1,
557  sizeof(*c->param_definitions));
558  if (!tmp) {
559  av_free(param);
560  return AVERROR(ENOMEM);
561  }
562  c->param_definitions = tmp;
563 
565  if (!param_definition) {
566  av_free(param);
567  return AVERROR(ENOMEM);
568  }
569  param_definition->param = param;
570  param_definition->mode = !mode;
571  param_definition->param_size = param_size;
572  param_definition->audio_element = audio_element;
573 
574  c->param_definitions[c->nb_param_definitions++] = param_definition;
575  }
576 
577  av_assert0(out_param_definition);
578  *out_param_definition = param;
579 
580  return 0;
581 }
582 
583 static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
584 {
585  const IAMFCodecConfig *codec_config;
586  AVIAMFAudioElement *element;
587  IAMFAudioElement **tmp, *audio_element = NULL;
588  FFIOContext b;
589  AVIOContext *pbc;
590  uint8_t *buf;
591  unsigned audio_element_id, codec_config_id, num_parameters;
592  int audio_element_type, ret;
593 
594  buf = av_malloc(len);
595  if (!buf)
596  return AVERROR(ENOMEM);
597 
598  ret = avio_read(pb, buf, len);
599  if (ret != len) {
600  if (ret >= 0)
602  goto fail;
603  }
604 
605  ffio_init_context(&b, buf, len, 0, NULL, NULL, NULL, NULL);
606  pbc = &b.pub;
607 
608  audio_element_id = ffio_read_leb(pbc);
609 
610  for (int i = 0; i < c->nb_audio_elements; i++)
611  if (c->audio_elements[i]->audio_element_id == audio_element_id) {
612  av_log(s, AV_LOG_ERROR, "Duplicate audio_element_id %d\n", audio_element_id);
614  goto fail;
615  }
616 
617  audio_element_type = avio_r8(pbc) >> 5;
618  codec_config_id = ffio_read_leb(pbc);
619 
620  codec_config = ff_iamf_get_codec_config(c, codec_config_id);
621  if (!codec_config) {
622  av_log(s, AV_LOG_ERROR, "Non existant codec config id %d referenced in an audio element\n", codec_config_id);
624  goto fail;
625  }
626 
627  if (codec_config->codec_id == AV_CODEC_ID_NONE) {
628  av_log(s, AV_LOG_DEBUG, "Unknown codec id referenced in an audio element. Ignoring\n");
629  ret = 0;
630  goto fail;
631  }
632 
633  tmp = av_realloc_array(c->audio_elements, c->nb_audio_elements + 1, sizeof(*c->audio_elements));
634  if (!tmp) {
635  ret = AVERROR(ENOMEM);
636  goto fail;
637  }
638  c->audio_elements = tmp;
639 
640  audio_element = av_mallocz(sizeof(*audio_element));
641  if (!audio_element) {
642  ret = AVERROR(ENOMEM);
643  goto fail;
644  }
645 
646  audio_element->nb_substreams = ffio_read_leb(pbc);
647  audio_element->codec_config_id = codec_config_id;
648  audio_element->audio_element_id = audio_element_id;
649  audio_element->substreams = av_calloc(audio_element->nb_substreams, sizeof(*audio_element->substreams));
650  if (!audio_element->substreams) {
651  ret = AVERROR(ENOMEM);
652  goto fail;
653  }
654 
655  element = audio_element->element = av_iamf_audio_element_alloc();
656  if (!element) {
657  ret = AVERROR(ENOMEM);
658  goto fail;
659  }
660  audio_element->celement = element;
661 
662  element->audio_element_type = audio_element_type;
663 
664  for (int i = 0; i < audio_element->nb_substreams; i++) {
665  IAMFSubStream *substream = &audio_element->substreams[i];
666 
667  substream->codecpar = avcodec_parameters_alloc();
668  if (!substream->codecpar) {
669  ret = AVERROR(ENOMEM);
670  goto fail;
671  }
672 
673  substream->audio_substream_id = ffio_read_leb(pbc);
674 
675  substream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
676  substream->codecpar->codec_id = codec_config->codec_id;
677  substream->codecpar->frame_size = codec_config->nb_samples;
678  substream->codecpar->sample_rate = codec_config->sample_rate;
679  substream->codecpar->seek_preroll = codec_config->seek_preroll;
680 
681  switch(substream->codecpar->codec_id) {
682  case AV_CODEC_ID_AAC:
683  case AV_CODEC_ID_FLAC:
684  case AV_CODEC_ID_OPUS:
686  if (!substream->codecpar->extradata) {
687  ret = AVERROR(ENOMEM);
688  goto fail;
689  }
690  memcpy(substream->codecpar->extradata, codec_config->extradata, codec_config->extradata_size);
691  memset(substream->codecpar->extradata + codec_config->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
692  substream->codecpar->extradata_size = codec_config->extradata_size;
693  break;
694  }
695  }
696 
697  num_parameters = ffio_read_leb(pbc);
698  if (num_parameters && audio_element_type != 0) {
699  av_log(s, AV_LOG_ERROR, "Audio Element parameter count %u is invalid"
700  " for Scene representations\n", num_parameters);
702  goto fail;
703  }
704 
705  for (int i = 0; i < num_parameters; i++) {
706  unsigned type;
707 
708  type = ffio_read_leb(pbc);
712  ret = param_parse(s, c, pbc, type, audio_element, &element->demixing_info);
714  ret = param_parse(s, c, pbc, type, audio_element, &element->recon_gain_info);
715  else {
716  unsigned param_definition_size = ffio_read_leb(pbc);
717  avio_skip(pbc, param_definition_size);
718  }
719  if (ret < 0)
720  goto fail;
721  }
722 
723  if (audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL) {
724  ret = scalable_channel_layout_config(s, pbc, audio_element, codec_config);
725  if (ret < 0)
726  goto fail;
727  } else if (audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE) {
728  ret = ambisonics_config(s, pbc, audio_element, codec_config);
729  if (ret < 0)
730  goto fail;
731  } else {
732  unsigned audio_element_config_size = ffio_read_leb(pbc);
733  avio_skip(pbc, audio_element_config_size);
734  }
735 
736  c->audio_elements[c->nb_audio_elements++] = audio_element;
737 
738  len -= avio_tell(pbc);
739  if (len)
740  av_log(s, AV_LOG_WARNING, "Underread in audio_element_obu. %d bytes left at the end\n", len);
741 
742  ret = 0;
743 fail:
744  av_free(buf);
745  if (ret < 0)
746  ff_iamf_free_audio_element(&audio_element);
747  return ret;
748 }
749 
750 static int label_string(AVIOContext *pb, char **label)
751 {
752  uint8_t buf[128];
753 
754  avio_get_str(pb, sizeof(buf), buf, sizeof(buf));
755 
756  if (pb->error)
757  return pb->error;
758  if (pb->eof_reached)
759  return AVERROR_INVALIDDATA;
760  *label = av_strdup(buf);
761  if (!*label)
762  return AVERROR(ENOMEM);
763 
764  return 0;
765 }
766 
767 static int mix_presentation_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
768 {
770  IAMFMixPresentation **tmp, *mix_presentation = NULL;
771  FFIOContext b;
772  AVIOContext *pbc;
773  uint8_t *buf;
774  unsigned nb_submixes, mix_presentation_id;
775  int ret;
776 
777  buf = av_malloc(len);
778  if (!buf)
779  return AVERROR(ENOMEM);
780 
781  ret = avio_read(pb, buf, len);
782  if (ret != len) {
783  if (ret >= 0)
785  goto fail;
786  }
787 
788  ffio_init_context(&b, buf, len, 0, NULL, NULL, NULL, NULL);
789  pbc = &b.pub;
790 
791  mix_presentation_id = ffio_read_leb(pbc);
792 
793  for (int i = 0; i < c->nb_mix_presentations; i++)
794  if (c->mix_presentations[i]->mix_presentation_id == mix_presentation_id) {
795  av_log(s, AV_LOG_ERROR, "Duplicate mix_presentation_id %d\n", mix_presentation_id);
797  goto fail;
798  }
799 
800  tmp = av_realloc_array(c->mix_presentations, c->nb_mix_presentations + 1, sizeof(*c->mix_presentations));
801  if (!tmp) {
802  ret = AVERROR(ENOMEM);
803  goto fail;
804  }
805  c->mix_presentations = tmp;
806 
807  mix_presentation = av_mallocz(sizeof(*mix_presentation));
808  if (!mix_presentation) {
809  ret = AVERROR(ENOMEM);
810  goto fail;
811  }
812 
813  mix_presentation->mix_presentation_id = mix_presentation_id;
814  mix = mix_presentation->mix = av_iamf_mix_presentation_alloc();
815  if (!mix) {
816  ret = AVERROR(ENOMEM);
817  goto fail;
818  }
819  mix_presentation->cmix = mix;
820 
821  mix_presentation->count_label = ffio_read_leb(pbc);
822  mix_presentation->language_label = av_calloc(mix_presentation->count_label,
823  sizeof(*mix_presentation->language_label));
824  if (!mix_presentation->language_label) {
825  mix_presentation->count_label = 0;
826  ret = AVERROR(ENOMEM);
827  goto fail;
828  }
829 
830  for (int i = 0; i < mix_presentation->count_label; i++) {
831  ret = label_string(pbc, &mix_presentation->language_label[i]);
832  if (ret < 0)
833  goto fail;
834  }
835 
836  for (int i = 0; i < mix_presentation->count_label; i++) {
837  char *annotation = NULL;
838  ret = label_string(pbc, &annotation);
839  if (ret < 0)
840  goto fail;
841  ret = av_dict_set(&mix->annotations, mix_presentation->language_label[i], annotation,
843  if (ret < 0)
844  goto fail;
845  }
846 
847  nb_submixes = ffio_read_leb(pbc);
848  for (int i = 0; i < nb_submixes; i++) {
849  AVIAMFSubmix *sub_mix;
850  unsigned nb_elements, nb_layouts;
851 
853  if (!sub_mix) {
854  ret = AVERROR(ENOMEM);
855  goto fail;
856  }
857 
858  nb_elements = ffio_read_leb(pbc);
859  for (int j = 0; j < nb_elements; j++) {
860  AVIAMFSubmixElement *submix_element;
861  IAMFAudioElement *audio_element = NULL;
862  unsigned int rendering_config_extension_size;
863 
864  submix_element = av_iamf_submix_add_element(sub_mix);
865  if (!submix_element) {
866  ret = AVERROR(ENOMEM);
867  goto fail;
868  }
869 
870  submix_element->audio_element_id = ffio_read_leb(pbc);
871 
872  for (int k = 0; k < c->nb_audio_elements; k++)
873  if (c->audio_elements[k]->audio_element_id == submix_element->audio_element_id) {
874  audio_element = c->audio_elements[k];
875  break;
876  }
877 
878  if (!audio_element) {
879  av_log(s, AV_LOG_ERROR, "Invalid Audio Element with id %u referenced by Mix Parameters %u\n",
880  submix_element->audio_element_id, mix_presentation_id);
882  goto fail;
883  }
884 
885  for (int k = 0; k < mix_presentation->count_label; k++) {
886  char *annotation = NULL;
887  ret = label_string(pbc, &annotation);
888  if (ret < 0)
889  goto fail;
890  ret = av_dict_set(&submix_element->annotations, mix_presentation->language_label[k], annotation,
892  if (ret < 0)
893  goto fail;
894  }
895 
896  submix_element->headphones_rendering_mode = avio_r8(pbc) >> 6;
897 
898  rendering_config_extension_size = ffio_read_leb(pbc);
899  avio_skip(pbc, rendering_config_extension_size);
900 
902  NULL,
903  &submix_element->element_mix_config);
904  if (ret < 0)
905  goto fail;
906  submix_element->default_mix_gain = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
907  }
908 
910  if (ret < 0)
911  goto fail;
912  sub_mix->default_mix_gain = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
913 
914  nb_layouts = ffio_read_leb(pbc);
915  for (int j = 0; j < nb_layouts; j++) {
916  AVIAMFSubmixLayout *submix_layout;
917  int info_type;
918  int byte = avio_r8(pbc);
919 
920  submix_layout = av_iamf_submix_add_layout(sub_mix);
921  if (!submix_layout) {
922  ret = AVERROR(ENOMEM);
923  goto fail;
924  }
925 
926  submix_layout->layout_type = byte >> 6;
929  av_log(s, AV_LOG_ERROR, "Invalid Layout type %u in a submix from Mix Presentation %u\n",
930  submix_layout->layout_type, mix_presentation_id);
932  goto fail;
933  }
934  if (submix_layout->layout_type == 2) {
935  int sound_system;
936  sound_system = (byte >> 2) & 0xF;
937  if (sound_system >= FF_ARRAY_ELEMS(ff_iamf_sound_system_map)) {
939  goto fail;
940  }
941  av_channel_layout_copy(&submix_layout->sound_system, &ff_iamf_sound_system_map[sound_system].layout);
942  }
943 
944  info_type = avio_r8(pbc);
945  submix_layout->integrated_loudness = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
946  submix_layout->digital_peak = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
947 
948  if (info_type & 1)
949  submix_layout->true_peak = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
950  if (info_type & 2) {
951  unsigned int num_anchored_loudness = avio_r8(pbc);
952 
953  for (int k = 0; k < num_anchored_loudness; k++) {
954  unsigned int anchor_element = avio_r8(pbc);
955  AVRational anchored_loudness = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
956  if (anchor_element == IAMF_ANCHOR_ELEMENT_DIALOGUE)
957  submix_layout->dialogue_anchored_loudness = anchored_loudness;
958  else if (anchor_element <= IAMF_ANCHOR_ELEMENT_ALBUM)
959  submix_layout->album_anchored_loudness = anchored_loudness;
960  else
961  av_log(s, AV_LOG_DEBUG, "Unknown anchor_element. Ignoring\n");
962  }
963  }
964 
965  if (info_type & 0xFC) {
966  unsigned int info_type_size = ffio_read_leb(pbc);
967  avio_skip(pbc, info_type_size);
968  }
969  }
970  }
971 
972  c->mix_presentations[c->nb_mix_presentations++] = mix_presentation;
973 
974  len -= avio_tell(pbc);
975  if (len)
976  av_log(s, AV_LOG_WARNING, "Underread in mix_presentation_obu. %d bytes left at the end\n", len);
977 
978  ret = 0;
979 fail:
980  av_free(buf);
981  if (ret < 0)
982  ff_iamf_free_mix_presentation(&mix_presentation);
983  return ret;
984 }
985 
986 int ff_iamf_parse_obu_header(const uint8_t *buf, int buf_size,
987  unsigned *obu_size, int *start_pos, enum IAMF_OBU_Type *type,
988  unsigned *skip_samples, unsigned *discard_padding)
989 {
990  GetBitContext gb;
991  int ret, extension_flag, trimming, start;
992  unsigned skip = 0, discard = 0;
993  unsigned size;
994 
995  ret = init_get_bits8(&gb, buf, FFMIN(buf_size, MAX_IAMF_OBU_HEADER_SIZE));
996  if (ret < 0)
997  return ret;
998 
999  *type = get_bits(&gb, 5);
1000  /*redundant =*/ get_bits1(&gb);
1001  trimming = get_bits1(&gb);
1002  extension_flag = get_bits1(&gb);
1003 
1004  *obu_size = get_leb(&gb);
1005  if (*obu_size > INT_MAX)
1006  return AVERROR_INVALIDDATA;
1007 
1008  start = get_bits_count(&gb) / 8;
1009 
1010  if (trimming) {
1011  discard = get_leb(&gb); // num_samples_to_trim_at_end
1012  skip = get_leb(&gb); // num_samples_to_trim_at_start
1013  }
1014 
1015  if (skip_samples)
1016  *skip_samples = skip;
1017  if (discard_padding)
1018  *discard_padding = discard;
1019 
1020  if (extension_flag) {
1021  unsigned int extension_bytes;
1022  extension_bytes = get_leb(&gb);
1023  if (extension_bytes > INT_MAX / 8)
1024  return AVERROR_INVALIDDATA;
1025  skip_bits_long(&gb, extension_bytes * 8);
1026  }
1027 
1028  if (get_bits_left(&gb) < 0)
1029  return AVERROR_INVALIDDATA;
1030 
1031  size = *obu_size + start;
1032  if (size > INT_MAX)
1033  return AVERROR_INVALIDDATA;
1034 
1035  *obu_size -= get_bits_count(&gb) / 8 - start;
1036  *start_pos = size - *obu_size;
1037 
1038  return size;
1039 }
1040 
1042  int max_size, void *log_ctx)
1043 {
1045  int ret;
1046 
1047  while (1) {
1048  unsigned obu_size;
1049  enum IAMF_OBU_Type type;
1050  int start_pos, len, size;
1051 
1052  if ((ret = ffio_ensure_seekback(pb, FFMIN(MAX_IAMF_OBU_HEADER_SIZE, max_size))) < 0)
1053  return ret;
1054  size = avio_read(pb, header, FFMIN(MAX_IAMF_OBU_HEADER_SIZE, max_size));
1055  if (size < 0)
1056  return size;
1057 
1058  len = ff_iamf_parse_obu_header(header, size, &obu_size, &start_pos, &type, NULL, NULL);
1059  if (len < 0 || obu_size > max_size) {
1060  av_log(log_ctx, AV_LOG_ERROR, "Failed to read obu header\n");
1061  avio_seek(pb, -size, SEEK_CUR);
1062  return len;
1063  }
1064 
1066  avio_seek(pb, -size, SEEK_CUR);
1067  break;
1068  }
1069 
1070  avio_seek(pb, -(size - start_pos), SEEK_CUR);
1071  switch (type) {
1073  ret = codec_config_obu(log_ctx, c, pb, obu_size);
1074  break;
1076  ret = audio_element_obu(log_ctx, c, pb, obu_size);
1077  break;
1079  ret = mix_presentation_obu(log_ctx, c, pb, obu_size);
1080  break;
1082  break;
1083  default: {
1084  int64_t offset = avio_skip(pb, obu_size);
1085  if (offset < 0)
1086  ret = offset;
1087  break;
1088  }
1089  }
1090  if (ret < 0) {
1091  av_log(log_ctx, AV_LOG_ERROR, "Failed to read obu type %d\n", type);
1092  return ret;
1093  }
1094  max_size -= obu_size + start_pos;
1095  if (max_size < 0)
1096  return AVERROR_INVALIDDATA;
1097  if (!max_size)
1098  break;
1099  }
1100 
1101  return 0;
1102 }
update_extradata
static int update_extradata(AVCodecParameters *codecpar)
Definition: iamf_parse.c:263
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:328
iamf.h
ff_iamf_free_mix_presentation
void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation)
Definition: iamf.c:85
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS
@ AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS
The layout follows the loudspeaker sound system convention of ITU-2051-3.
Definition: iamf.h:488
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
MP4DecConfigDescrTag
#define MP4DecConfigDescrTag
Definition: isom.h:369
ffio_init_context
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))
Definition: aviobuf.c:50
mix
static int mix(int c0, int c1)
Definition: 4xm.c:716
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
AVERROR
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
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:379
IAMF_OBU_IA_SEQUENCE_HEADER
@ IAMF_OBU_IA_SEQUENCE_HEADER
Definition: iamf.h:63
ff_mp4_obj_type
const AVCodecTag ff_mp4_obj_type[]
Definition: isom.c:34
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AVIAMFAudioElement::default_w
unsigned int default_w
Default weight value as defined in section 3.6 of IAMF.
Definition: iamf.h:384
IAMFAudioElement::nb_substreams
unsigned int nb_substreams
Definition: iamf.h:99
av_iamf_param_definition_alloc
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.
Definition: iamf.c:159
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:354
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:223
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
ff_iamf_sound_system_map
const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13]
Definition: iamf.c:48
put_bits64
static void put_bits64(PutBitContext *s, int n, uint64_t value)
Write up to 64 bits into a bitstream.
Definition: put_bits.h:334
AVCodecParameters::seek_preroll
int seek_preroll
Audio only.
Definition: codec_par.h:214
b
#define b
Definition: input.c:41
AVIOContext::error
int error
contains the error code or 0 if no error happened
Definition: avio.h:239
AVIAMFSubmixLayout::layout_type
enum AVIAMFSubmixLayoutType layout_type
Definition: iamf.h:504
AVIAMFParamDefinition
Parameters as defined in section 3.6.1 of IAMF.
Definition: iamf.h:184
AVIAMFSubmixElement::default_mix_gain
AVRational default_mix_gain
Default mix gain value to apply when there are no AVIAMFParamDefinition with element_mix_config's par...
Definition: iamf.h:460
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:452
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:308
iamf_parse.h
ambisonics_config
static int ambisonics_config(void *s, AVIOContext *pb, IAMFAudioElement *audio_element, const IAMFCodecConfig *codec_config)
Definition: iamf_parse.c:388
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
FFIOContext
Definition: avio_internal.h:28
flac_decoder_config
static int flac_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len)
Definition: iamf_parse.c:113
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
IAMFMixPresentation::cmix
const AVIAMFMixPresentation * cmix
Definition: iamf.h:108
MPEG4AudioConfig
Definition: mpeg4audio.h:29
AVIAMFSubmixLayout::digital_peak
AVRational digital_peak
The digital (sampled) peak value of the audio signal, as defined in ITU-1770-4.
Definition: iamf.h:522
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
mpeg4audio.h
AVIAMFSubmixLayout::integrated_loudness
AVRational integrated_loudness
The program integrated loudness information, as defined in ITU-1770-4.
Definition: iamf.h:517
av_iamf_mix_presentation_add_submix
AVIAMFSubmix * av_iamf_mix_presentation_add_submix(AVIAMFMixPresentation *mix_presentation)
Allocate a submix and add it to a given AVIAMFMixPresentation.
IAMFCodecConfig::extradata
uint8_t * extradata
Definition: iamf.h:74
MP4DecSpecificDescrTag
#define MP4DecSpecificDescrTag
Definition: isom.h:370
AOT_ESCAPE
@ AOT_ESCAPE
Y Escape Value.
Definition: mpeg4audio.h:100
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:329
IAMFParamDefinition
Definition: iamf.h:121
fail
#define fail()
Definition: checkasm.h:179
GetBitContext
Definition: get_bits.h:108
AVIAMFSubmixLayout
Submix layout as defined in section 3.7.6 of IAMF.
Definition: iamf.h:501
IAMF_ANCHOR_ELEMENT_ALBUM
@ IAMF_ANCHOR_ELEMENT_ALBUM
Definition: iamf.h:142
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:125
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
av_iamf_audio_element_alloc
AVIAMFAudioElement * av_iamf_audio_element_alloc(void)
Allocates a AVIAMFAudioElement, and initializes its fields with default values.
Definition: iamf.c:322
type
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
Definition: writing_filters.txt:86
IAMF_OBU_IA_PARAMETER_BLOCK
@ IAMF_OBU_IA_PARAMETER_BLOCK
Definition: iamf.h:41
AVIAMFAudioElement::audio_element_type
enum AVIAMFAudioElementType audio_element_type
Audio element type as defined in section 3.6 of IAMF.
Definition: iamf.h:379
opus_decoder_config
static int opus_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len)
Definition: iamf_parse.c:36
AVIAMFReconGain
Recon Gain Info Parameter Data as defined in section 3.8.3 of IAMF.
Definition: iamf.h:139
param_parse
static int param_parse(void *s, IAMFContext *c, AVIOContext *pb, unsigned int type, const IAMFAudioElement *audio_element, AVIAMFParamDefinition **out_param_definition)
Definition: iamf_parse.c:473
codec_config_obu
static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
Definition: iamf_parse.c:158
AV_DICT_DONT_STRDUP_VAL
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:79
IAMFAudioElement::element
AVIAMFAudioElement * element
element backs celement iff the AVIAMFAudioElement is owned by this structure.
Definition: iamf.h:95
AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN
@ AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN
Subblocks are of struct type AVIAMFReconGain.
Definition: iamf.h:172
AVIAMFSubmixElement::annotations
AVDictionary * annotations
A dictionary of strings describing the submix in different languages.
Definition: iamf.h:481
avassert.h
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:761
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
IAMFCodecConfig::sample_rate
int sample_rate
Definition: iamf.h:72
AVChannelLayout::u
union AVChannelLayout::@364 u
Details about which channels are present in this layout.
IAMF_OBU_IA_MIX_PRESENTATION
@ IAMF_OBU_IA_MIX_PRESENTATION
Definition: iamf.h:40
duration
int64_t duration
Definition: movenc.c:65
AVCodecParameters::frame_size
int frame_size
Audio only.
Definition: codec_par.h:195
av_iamf_submix_add_layout
AVIAMFSubmixLayout * av_iamf_submix_add_layout(AVIAMFSubmix *submix)
Allocate a submix layout and add it to a given AVIAMFSubmix.
avpriv_mpeg4audio_get_config2
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.
Definition: mpeg4audio.c:165
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
IAMFSubStream::audio_substream_id
unsigned int audio_substream_id
Definition: iamf.h:83
IAMFLayer::substream_count
unsigned int substream_count
Definition: iamf.h:78
AVIAMFSubmixLayout::dialogue_anchored_loudness
AVRational dialogue_anchored_loudness
The Dialogue loudness information, as defined in ITU-1770-4.
Definition: iamf.h:530
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_iamf_param_definition_get_subblock
static av_always_inline void * av_iamf_param_definition_get_subblock(const AVIAMFParamDefinition *par, unsigned int idx)
Get the subblock at the specified.
Definition: iamf.h:251
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVIAMFSubmixElement::headphones_rendering_mode
enum AVIAMFHeadphonesMode headphones_rendering_mode
A value that indicates whether the referenced channel-based Audio Element shall be rendered to stereo...
Definition: iamf.h:469
ffio_read_leb
unsigned int ffio_read_leb(AVIOContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
Definition: aviobuf.c:927
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
get_bits.h
AVIAMFLayer::ch_layout
AVChannelLayout ch_layout
Definition: iamf.h:288
IAMFAudioElement::nb_layers
unsigned int nb_layers
Definition: iamf.h:104
ff_iamfdec_read_descriptors
int ff_iamfdec_read_descriptors(IAMFContext *c, AVIOContext *pb, int max_size, void *log_ctx)
Definition: iamf_parse.c:1041
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:387
PutBitContext
Definition: put_bits.h:50
IAMFAudioElement::audio_element_id
unsigned int audio_element_id
Definition: iamf.h:96
AVIAMFDemixingInfo
Demixing Info Parameter Data as defined in section 3.8.2 of IAMF.
Definition: iamf.h:119
IAMFSoundSystemMap::layout
AVChannelLayout layout
Definition: iamf.h:163
AV_CHANNEL_ORDER_AMBISONIC
@ AV_CHANNEL_ORDER_AMBISONIC
The audio is represented as the decomposition of the sound field into spherical harmonics.
Definition: channel_layout.h:148
NULL
#define NULL
Definition: coverity.c:32
get_leb
static unsigned get_leb(GetBitContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
Definition: leb.h:35
isom.h
IAMF_OBU_IA_AUDIO_ELEMENT
@ IAMF_OBU_IA_AUDIO_ELEMENT
Definition: iamf.h:39
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVIAMFParamDefinition::duration
unsigned int duration
The accumulated duration of all blocks in this parameter definition, in units of 1 / parameter_rate.
Definition: iamf.h:222
ff_iamf_get_codec_config
static IAMFCodecConfig * ff_iamf_get_codec_config(const IAMFContext *c, unsigned int codec_config_id)
Definition: iamf.h:170
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
audio_element_obu
static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
Definition: iamf_parse.c:583
AVIAMFLayer
A layer defining a Channel Layout in the Audio Element.
Definition: iamf.h:285
IAMF_OBU_IA_CODEC_CONFIG
@ IAMF_OBU_IA_CODEC_CONFIG
Definition: iamf.h:38
IAMFSubStream
Definition: iamf.h:82
IAMFAudioElement::layers
IAMFLayer * layers
Definition: iamf.h:103
FLAC_STREAMINFO_SIZE
#define FLAC_STREAMINFO_SIZE
Definition: flac.h:32
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:81
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
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
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
ff_iamf_parse_obu_header
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)
Definition: iamf_parse.c:986
AVIAMFLayer::output_gain_flags
unsigned int output_gain_flags
Output gain channel flags as defined in section 3.6.2 of IAMF.
Definition: iamf.h:301
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AVIAMFSubmixElement::audio_element_id
unsigned int audio_element_id
The id of the Audio Element this submix element references.
Definition: iamf.h:443
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVIAMFSubmix
Submix layout as defined in section 3.7 of IAMF.
Definition: iamf.h:543
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:417
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:442
IAMFAudioElement
Definition: iamf.h:89
AVIAMFReconGain::subblock_duration
unsigned int subblock_duration
Duration for the given subblock, in units of 1 / parameter_rate.
Definition: iamf.h:147
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
IAMFCodecConfig::nb_samples
unsigned nb_samples
Definition: iamf.h:70
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: codec_id.h:340
AVIAMFDemixingInfo::subblock_duration
unsigned int subblock_duration
Duration for the given subblock, in units of 1 / parameter_rate.
Definition: iamf.h:127
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:146
IAMFCodecConfig
Definition: iamf.h:66
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
IAMFCodecConfig::extradata_size
int extradata_size
Definition: iamf.h:73
avio_get_str
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:866
size
int size
Definition: twinvq_data.h:10344
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
IAMFLayer::coupled_substream_count
unsigned int coupled_substream_count
Definition: iamf.h:79
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:500
av_iamf_mix_presentation_alloc
AVIAMFMixPresentation * av_iamf_mix_presentation_alloc(void)
Allocates a AVIAMFMixPresentation, and initializes its fields with default values.
Definition: iamf.c:520
IAMFContext
Definition: iamf.h:128
header
static const uint8_t header[24]
Definition: sdr2.c:68
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:603
IAMFAudioElement::substreams
IAMFSubStream * substreams
Definition: iamf.h:98
AVIAMFParamDefinition::constant_subblock_duration
unsigned int constant_subblock_duration
The duration of every subblock in the case where all subblocks, with the optional exception of the la...
Definition: iamf.h:229
av_iamf_submix_add_element
AVIAMFSubmixElement * av_iamf_submix_add_element(AVIAMFSubmix *submix)
Allocate a submix element and add it to a given AVIAMFSubmix.
AVIAMFAudioElement
Information on how to combine one or more audio streams, as defined in section 3.6 of IAMF.
Definition: iamf.h:347
ipcm_decoder_config
static int ipcm_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len)
Definition: iamf_parse.c:137
ffio_ensure_seekback
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:1023
offset
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
Definition: writing_filters.txt:86
AVIAMFMixGain
Mix Gain Parameter Data as defined in section 3.8.1 of IAMF.
Definition: iamf.h:68
leb.h
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:56
get_bits64
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:453
log.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
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:209
avio_internal.h
AVIAMFLayer::demixing_matrix
AVRational * demixing_matrix
Demixing matrix as defined in section 3.6.3 of IAMF.
Definition: iamf.h:331
IAMFCodecConfig::seek_preroll
int seek_preroll
Definition: iamf.h:71
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVIAMFMixPresentation
Information on how to render and mix one or more AVIAMFAudioElement to generate the final audio outpu...
Definition: iamf.h:600
aac_decoder_config
static int aac_decoder_config(IAMFCodecConfig *codec_config, AVIOContext *pb, int len, void *logctx)
Definition: iamf_parse.c:60
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
param_definition
static int param_definition(const IAMFContext *iamf, const IAMFParamDefinition *param_def, AVIOContext *dyn_bc, void *log_ctx)
Definition: iamf_writer.c:554
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:337
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
len
int len
Definition: vorbis_enc_data.h:426
IAMFMixPresentation::count_label
unsigned int count_label
Definition: iamf.h:117
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AVIAMFParamDefinition::nb_subblocks
unsigned int nb_subblocks
Number of subblocks in the array.
Definition: iamf.h:199
AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE
@ AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE
Definition: iamf.h:337
AV_WB8
#define AV_WB8(p, d)
Definition: intreadwrite.h:394
tag
uint32_t tag
Definition: movenc.c:1787
ret
ret
Definition: filter_design.txt:187
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
ff_iamf_free_audio_element
void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element)
Definition: iamf.c:70
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:746
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
left
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
Definition: snow.txt:386
IAMF_OBU_Type
IAMF_OBU_Type
Definition: iamf.h:37
label_string
static int label_string(AVIOContext *pb, char **label)
Definition: iamf_parse.c:750
IAMFMixPresentation
Definition: iamf.h:107
AV_CHANNEL_ORDER_CUSTOM
@ AV_CHANNEL_ORDER_CUSTOM
The channel order does not correspond to any other predefined order and is stored as an explicit map.
Definition: channel_layout.h:125
IAMFMixPresentation::language_label
char ** language_label
Definition: iamf.h:118
AVIAMFSubmix::default_mix_gain
AVRational default_mix_gain
Default mix gain value to apply when there are no AVIAMFParamDefinition with output_mix_config's para...
Definition: iamf.h:590
AVIAMFSubmixLayout::album_anchored_loudness
AVRational album_anchored_loudness
The Album loudness information, as defined in ITU-1770-4.
Definition: iamf.h:534
AVIAMFSubmixLayout::true_peak
AVRational true_peak
The true peak of the audio signal, as defined in ITU-1770-4.
Definition: iamf.h:526
mode
mode
Definition: ebur128.h:83
AVIAMFSubmixLayout::sound_system
AVChannelLayout sound_system
Channel layout matching one of Sound Systems A to J of ITU-2051-3, plus 7.1.2ch and 3....
Definition: iamf.h:512
IAMFCodecConfig::codec_id
enum AVCodecID codec_id
Definition: iamf.h:68
IAMFCodecConfig::codec_config_id
unsigned codec_config_id
Definition: iamf.h:67
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:612
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:133
AVIOContext::eof_reached
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:238
IAMF_ANCHOR_ELEMENT_DIALOGUE
@ IAMF_ANCHOR_ELEMENT_DIALOGUE
Definition: iamf.h:141
AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN
@ AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN
Subblocks are of struct type AVIAMFMixGain.
Definition: iamf.h:164
MAX_IAMF_OBU_HEADER_SIZE
#define MAX_IAMF_OBU_HEADER_SIZE
Definition: iamf.h:34
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:318
mix_presentation_obu
static int mix_presentation_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
Definition: iamf_parse.c:767
av_iamf_audio_element_add_layer
AVIAMFLayer * av_iamf_audio_element_add_layer(AVIAMFAudioElement *audio_element)
Allocate a layer and add it to a given AVIAMFAudioElement.
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:440
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
AV_CODEC_ID_PCM_S32LE
@ AV_CODEC_ID_PCM_S32LE
Definition: codec_id.h:336
AVIAMFAudioElement::demixing_info
AVIAMFParamDefinition * demixing_info
Demixing information used to reconstruct a scalable channel audio representation.
Definition: iamf.h:367
AVIAMFDemixingInfo::dmixp_mode
unsigned int dmixp_mode
Pre-defined combination of demixing parameters.
Definition: iamf.h:131
mem.h
AVIAMFSubmix::output_mix_config
AVIAMFParamDefinition * output_mix_config
Information required for post-processing the mixed audio signal to generate the audio signal for play...
Definition: iamf.h:582
AVIAMFLayer::ambisonics_mode
enum AVIAMFAmbisonicsMode ambisonics_mode
Ambisonics mode as defined in section 3.6.3 of IAMF.
Definition: iamf.h:319
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:378
AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL
@ AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL
The layout is binaural.
Definition: iamf.h:492
AVIAMFLayer::flags
unsigned int flags
A bitmask which may contain a combination of AV_IAMF_LAYER_FLAG_* flags.
Definition: iamf.h:293
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVIAMFLayer::output_gain
AVRational output_gain
Output gain as defined in section 3.6.2 of IAMF.
Definition: iamf.h:307
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
AVIAMFSubmixElement::element_mix_config
AVIAMFParamDefinition * element_mix_config
Information required required for applying any processing to the referenced and rendered Audio Elemen...
Definition: iamf.h:452
AV_CHAN_AMBISONIC_BASE
@ AV_CHAN_AMBISONIC_BASE
Range of channels between AV_CHAN_AMBISONIC_BASE and AV_CHAN_AMBISONIC_END represent Ambisonic compon...
Definition: channel_layout.h:101
AVIAMFParamDefinition::parameter_rate
unsigned int parameter_rate
Sample rate for the paremeter substream.
Definition: iamf.h:213
ff_iamf_scalable_ch_layouts
const AVChannelLayout ff_iamf_scalable_ch_layouts[10]
Definition: iamf.c:27
AVIAMFSubmixElement
Submix element as defined in section 3.7 of IAMF.
Definition: iamf.h:437
AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL
@ AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL
Definition: iamf.h:336
IAMFAudioElement::codec_config_id
unsigned int codec_config_id
Definition: iamf.h:101
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
IAMF_OBU_IA_TEMPORAL_DELIMITER
@ IAMF_OBU_IA_TEMPORAL_DELIMITER
Definition: iamf.h:42
AVIAMFAudioElement::recon_gain_info
AVIAMFParamDefinition * recon_gain_info
Recon gain information used to reconstruct a scalable channel audio representation.
Definition: iamf.h:374
IAMFMixPresentation::mix
AVIAMFMixPresentation * mix
mix backs cmix iff the AVIAMFMixPresentation is owned by this structure.
Definition: iamf.h:113
scalable_channel_layout_config
static int scalable_channel_layout_config(void *s, AVIOContext *pb, IAMFAudioElement *audio_element, const IAMFCodecConfig *codec_config)
Definition: iamf_parse.c:324
flac.h
AV_RB24
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
Definition: bytestream.h:97
IAMFSubStream::codecpar
AVCodecParameters * codecpar
Definition: iamf.h:86
put_bits.h
IAMFMixPresentation::mix_presentation_id
unsigned int mix_presentation_id
Definition: iamf.h:114
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:341
AVChannelCustom::id
enum AVChannel id
Definition: channel_layout.h:268
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
AV_IAMF_PARAMETER_DEFINITION_DEMIXING
@ AV_IAMF_PARAMETER_DEFINITION_DEMIXING
Subblocks are of struct type AVIAMFDemixingInfo.
Definition: iamf.h:168
MPEG4AudioConfig::sample_rate
int sample_rate
Definition: mpeg4audio.h:32