70 memcpy(codec_config->
extradata, buf,
sizeof(buf));
156 if (j < iamf->nb_codec_configs) {
198 av_log(log_ctx,
AV_LOG_ERROR,
"parameter_rate needed but not set for parameter_id %u\n",
240 if (iamf_audio_element->
nb_layers != 1) {
241 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid amount of layers for SCENE_BASED audio element. Must be 1\n");
246 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid channel layout for SCENE_BASED audio element\n");
255 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid amount of channels in a stream for MONO mode ambisonics\n");
263 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid amount of layers for CHANNEL_BASED audio element. Must be >= 1\n");
267 for (
int j,
i = 0;
i < iamf_audio_element->
nb_layers;
i++) {
284 av_log(log_ctx,
AV_LOG_ERROR,
"Unsupported channel layout in Audio Element id %"PRId64
302 av_bprintf(&bp,
"\" can't follow channel layout \"");
304 av_bprintf(&bp,
"\" in Scalable Audio Element id %"PRId64, stg->
id);
319 codec_config =
av_mallocz(
sizeof(*codec_config));
329 audio_element =
av_mallocz(
sizeof(*audio_element));
345 if (!audio_element->
layers) {
350 for (
int i = 0, j = 0;
i < iamf_audio_element->
nb_layers;
i++) {
357 for (; nb_channels > 0 && j < stg->
nb_streams; j++) {
367 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid channel count across substreams in layer %u from stream group %u\n",
378 av_log(log_ctx,
AV_LOG_ERROR,
"Duplicate id %u in streams %u and %u from stream group %u\n",
452 mix_presentation =
av_mallocz(
sizeof(*mix_presentation));
453 if (!mix_presentation)
466 "Mix Presentation ID %"PRId64
"\n",
i, stg->
id);
483 av_log(log_ctx,
AV_LOG_ERROR,
"element_mix_config is not present for element %u in submix %u from "
484 "Mix Presentation ID %"PRId64
"\n", j,
i, stg->
id);
518 uint8_t *dyn_buf =
NULL;
597 int *playout,
int *pexpanded_layout)
599 int layout, expanded_layout = -1;
628 *pexpanded_layout = expanded_layout;
645 int layout, expanded_layout;
660 if (expanded_layout >= 0)
719 switch (param->
type) {
751 uint8_t *dyn_buf =
NULL;
775 param_definition_types = 0;
777 int layout = 0, expanded_layout = 0;
784 av_log(log_ctx,
AV_LOG_ERROR,
"expanded_loudspeaker_layout present when using more than one layer in "
785 "Stream Group #%u\n",
807 av_log(log_ctx,
AV_LOG_ERROR,
"demixing_info needed but not set in Stream Group #%u\n",
839 av_log(log_ctx,
AV_LOG_ERROR,
"recon_gain_info needed but not set in Stream Group #%u\n",
884 uint8_t *dyn_buf =
NULL;
900 for (
int i = 0;
i <
mix->nb_submixes;
i++) {
919 av_log(log_ctx,
AV_LOG_ERROR,
"Inconsistent amount of labels in submix %d from Mix Presentation id #%u\n",
980 info_type |= (dialogue || album) << 1;
987 avio_w8(dyn_bc, dialogue + album);
1054 uint8_t *dyn_buf =
NULL;
1064 av_log(log_ctx,
AV_LOG_ERROR,
"Non-existent Parameter Definition with ID %u referenced by a packet\n",
1071 "with ID %u in a packet\n",
1098 switch (param->
type) {
1112 mix->control_point_relative_time.den)));
1131 if (!audio_element) {
1136 for (
int j = 0; j < audio_element->
nb_layers; j++) {
1140 unsigned int recon_gain_flags = 0;
1144 recon_gain_flags |= (1 << k) * !!recon->
recon_gain[j][k];
1146 recon_gain_flags |= (2 << k) * !!recon->
recon_gain[j][k];
1147 if (recon_gain_flags >> 8)
1148 recon_gain_flags |= (1 << k);
1151 for (k = 0; k < 12; k++) {
1160 av_unreachable(
"param_definition_type should have been checked above");
1208 unsigned int audio_substream_id)
1210 for (
int i = 0;
i <
c->nb_audio_elements;
i++) {
1215 return audio_element;
1230 const uint8_t *side_data;
1231 uint8_t *dyn_buf =
NULL;
1232 unsigned int skip_samples = 0, discard_padding = 0;
1233 size_t side_data_size;
1234 int dyn_size,
type = audio_substream_id <= 17 ?
1246 size_t new_extradata_size;
1249 &new_extradata_size);
1260 memcpy(codec_config->
extradata, new_extradata, new_extradata_size);
1270 if (side_data && side_data_size >= 10) {
1271 skip_samples =
AV_RL32(side_data);
1272 discard_padding =
AV_RL32(side_data + 4);
1277 skip_samples =
pkt->dts < 0
1280 discard_padding =
av_rescale(discard_padding, 48000,
pkt->time_base.den);
1290 put_bits(&pbc, 1, skip_samples || discard_padding);
1295 if (skip_samples || discard_padding) {
1300 if (audio_substream_id > 17)
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_wl32(AVIOContext *s, unsigned int val)
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
void avio_w8(AVIOContext *s, int b)
void avio_wb32(AVIOContext *s, unsigned int val)
void avio_wb16(AVIOContext *s, unsigned int val)
void avio_wb24(AVIOContext *s, unsigned int val)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
void ffio_write_leb(AVIOContext *s, unsigned val)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static void skip_bits(GetBitContext *s, int n)
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
@ AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
@ AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
@ AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
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...
@ AV_CHANNEL_ORDER_CUSTOM
The channel order does not correspond to any other predefined order and is stored as an explicit map.
@ AV_CHANNEL_ORDER_AMBISONIC
The audio is represented as the decomposition of the sound field into spherical harmonics.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_IAMF_LAYER_FLAG_RECON_GAIN
Recon gain information for the layer is present in AVIAMFReconGain.
@ AV_IAMF_AMBISONICS_MODE_MONO
@ AV_IAMF_AMBISONICS_MODE_PROJECTION
@ AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE
@ AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL
@ AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL
The layout is binaural.
@ AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS
The layout follows the loudspeaker sound system convention of ITU-2051-3.
static av_always_inline void * av_iamf_param_definition_get_subblock(const AVIAMFParamDefinition *par, unsigned int idx)
Get the subblock at the specified idx.
@ AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN
Subblocks are of struct type AVIAMFReconGain.
@ AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN
Subblocks are of struct type AVIAMFMixGain.
@ AV_IAMF_PARAMETER_DEFINITION_DEMIXING
Subblocks are of struct type AVIAMFDemixingInfo.
@ AV_IAMF_ANIMATION_TYPE_BEZIER
@ AV_IAMF_ANIMATION_TYPE_LINEAR
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static IAMFAudioElement * get_audio_element(const IAMFContext *c, unsigned int audio_substream_id)
static int iamf_write_codec_config(const IAMFContext *iamf, const IAMFCodecConfig *codec_config, AVIOContext *pb)
int ff_iamf_write_descriptors(const IAMFContext *iamf, AVIOContext *pb, void *log_ctx)
int ff_iamf_write_audio_frame(const IAMFContext *iamf, AVIOContext *pb, unsigned audio_substream_id, const AVPacket *pkt)
int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, void *log_ctx)
static int ambisonics_config(const IAMFAudioElement *audio_element, AVIOContext *dyn_bc)
static int iamf_write_audio_element(const IAMFContext *iamf, const IAMFAudioElement *audio_element, AVIOContext *pb, void *log_ctx)
static int add_param_definition(IAMFContext *iamf, AVIAMFParamDefinition *param, const IAMFAudioElement *audio_element, void *log_ctx)
static int populate_audio_roll_distance(IAMFCodecConfig *codec_config)
static int param_definition(const IAMFContext *iamf, const IAMFParamDefinition *param_def, AVIOContext *dyn_bc, void *log_ctx)
static int write_parameter_block(const IAMFContext *iamf, AVIOContext *pb, const AVIAMFParamDefinition *param, void *log_ctx)
static int iamf_write_mixing_presentation(const IAMFContext *iamf, const IAMFMixPresentation *mix_presentation, AVIOContext *pb, void *log_ctx)
static int rescale_rational(AVRational q, int b)
int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void *log_ctx)
static void get_loudspeaker_layout(const AVIAMFLayer *layer, int *playout, int *pexpanded_layout)
static int scalable_channel_layout_config(const IAMFAudioElement *audio_element, AVIOContext *dyn_bc)
int ff_iamf_write_parameter_blocks(const IAMFContext *iamf, AVIOContext *pb, const AVPacket *pkt, void *log_ctx)
static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg, IAMFCodecConfig *codec_config, void *log_ctx)
static int update_extradata(IAMFCodecConfig *codec_config)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int mix(int c0, int c1)
Immersive Audio Model and Formats API header.
#define MKTAG(a, b, c, d)
#define MKBETAG(a, b, c, d)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bytes_count(const PutBitContext *s, int round_up)
static int put_bits_left(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void put_bits63(PutBitContext *s, int n, uint64_t value)
Write up to 63 bits into a bitstream.
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
static const uint8_t header[24]
#define FF_ARRAY_ELEMS(a)
enum AVChannelOrder order
Channel order used in this layout.
union AVChannelLayout::@162063043056170047076125117143030261346263330336 u
Details about which channels are present in this layout.
int nb_channels
Number of channels in this layout.
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
int extradata_size
Size of the extradata content in bytes.
int frame_size
Audio frame size, if known.
AVChannelLayout ch_layout
The channel layout and number of channels.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
Information on how to combine one or more audio streams, as defined in section 3.6 of IAMF.
enum AVIAMFAudioElementType audio_element_type
Audio element type as defined in section 3.6 of IAMF.
AVIAMFParamDefinition * recon_gain_info
Recon gain information used to reconstruct a scalable channel audio representation.
unsigned int default_w
Default weight value as defined in section 3.6 of IAMF.
AVIAMFParamDefinition * demixing_info
Demixing information used to reconstruct a scalable channel audio representation.
unsigned int nb_layers
Number of layers, or channel groups, in the Audio Element.
Demixing Info Parameter Data as defined in section 3.8.2 of IAMF.
unsigned int dmixp_mode
Pre-defined combination of demixing parameters.
unsigned int subblock_duration
Duration for the given subblock, in units of 1 / parameter_rate.
A layer defining a Channel Layout in the Audio Element.
unsigned int flags
A bitmask which may contain a combination of AV_IAMF_LAYER_FLAG_* flags.
unsigned int output_gain_flags
Output gain channel flags as defined in section 3.6.2 of IAMF.
enum AVIAMFAmbisonicsMode ambisonics_mode
Ambisonics mode as defined in section 3.6.3 of IAMF.
unsigned int nb_demixing_matrix
The length of the Demixing matrix array.
AVRational * demixing_matrix
Demixing matrix as defined in section 3.6.3 of IAMF.
AVChannelLayout ch_layout
AVRational output_gain
Output gain as defined in section 3.6.2 of IAMF.
Mix Gain Parameter Data as defined in section 3.8.1 of IAMF.
Information on how to render and mix one or more AVIAMFAudioElement to generate the final audio outpu...
unsigned int nb_submixes
Number of submixes in the presentation.
AVIAMFSubmix ** submixes
Array of submixes.
Parameters as defined in section 3.6.1 of IAMF.
unsigned int parameter_rate
Sample rate for the parameter substream.
unsigned int duration
The accumulated duration of all blocks in this parameter definition, in units of 1 / parameter_rate.
unsigned int constant_subblock_duration
The duration of every subblock in the case where all subblocks, with the optional exception of the la...
unsigned int parameter_id
Identifier for the parameter substream.
enum AVIAMFParamDefinitionType type
Parameters type.
unsigned int nb_subblocks
Number of subblocks in the array.
Recon Gain Info Parameter Data as defined in section 3.8.3 of IAMF.
unsigned int subblock_duration
Duration for the given subblock, in units of 1 / parameter_rate.
uint8_t recon_gain[6][12]
Array of gain values to be applied to each channel for each layer defined in the Audio Element refere...
Submix element as defined in section 3.7 of IAMF.
AVIAMFParamDefinition * element_mix_config
Information required required for applying any processing to the referenced and rendered Audio Elemen...
unsigned int audio_element_id
The id of the Audio Element this submix element references.
AVDictionary * annotations
A dictionary of strings describing the submix in different languages.
enum AVIAMFHeadphonesMode headphones_rendering_mode
A value that indicates whether the referenced channel-based Audio Element shall be rendered to stereo...
AVRational default_mix_gain
Default mix gain value to apply when there are no AVIAMFParamDefinition with element_mix_config's par...
Submix layout as defined in section 3.7.6 of IAMF.
AVRational true_peak
The true peak of the audio signal, as defined in ITU-1770-4.
AVRational digital_peak
The digital (sampled) peak value of the audio signal, as defined in ITU-1770-4.
enum AVIAMFSubmixLayoutType layout_type
AVRational dialogue_anchored_loudness
The Dialogue loudness information, as defined in ITU-1770-4.
AVRational album_anchored_loudness
The Album loudness information, as defined in ITU-1770-4.
AVRational integrated_loudness
The program integrated loudness information, 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....
Submix layout as defined in section 3.7 of IAMF.
AVRational default_mix_gain
Default mix gain value to apply when there are no AVIAMFParamDefinition with output_mix_config's para...
unsigned int nb_elements
Number of elements in the submix.
AVIAMFSubmixElement ** elements
Array of submix elements.
AVIAMFSubmixLayout ** layouts
Array of submix layouts.
AVIAMFParamDefinition * output_mix_config
Information required for post-processing the mixed audio signal to generate the audio signal for play...
unsigned int nb_layouts
Number of layouts in the submix.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
union AVStreamGroup::@166361102046003066253145020066347265153020354020 params
Group type-specific parameters.
enum AVStreamGroupParamsType type
Group type.
struct AVIAMFMixPresentation * iamf_mix_presentation
unsigned int nb_streams
Number of elements in AVStreamGroup.streams.
unsigned int index
Group index in AVFormatContext.
struct AVIAMFAudioElement * iamf_audio_element
int64_t id
Group type-specific group ID.
AVStream ** streams
A list of streams in the group.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int id
Format-specific stream ID.
unsigned int codec_config_id
unsigned int audio_element_id
const AVIAMFAudioElement * celement
unsigned int nb_substreams
IAMFSubStream * substreams
IAMFParamDefinition ** param_definitions
IAMFMixPresentation ** mix_presentations
IAMFAudioElement ** audio_elements
IAMFCodecConfig ** codec_configs
unsigned int substream_count
unsigned int coupled_substream_count
const AVIAMFMixPresentation * cmix
unsigned int mix_presentation_id
AVIAMFParamDefinition * param
unsigned int audio_substream_id