36 for (
int i = 0;
i <
s->nb_streams;
i++)
37 if (
s->streams[
i]->id ==
id + stream_id_offset)
47 unsigned skip_samples,
unsigned discard_padding,
48 int stream_id_offset,
int id_in_bitstream)
51 int ret, audio_substream_id;
53 if (id_in_bitstream) {
54 unsigned explicit_audio_substream_id;
58 audio_substream_id = explicit_audio_substream_id;
72 if (skip_samples || discard_padding) {
77 AV_WL32A(side_data + 4, discard_padding);
83 memcpy(side_data,
c->mix,
c->mix_size);
89 memcpy(side_data,
c->demix,
c->demix_size);
95 memcpy(side_data,
c->recon,
c->recon_size);
115 unsigned int duration, constant_subblock_duration;
116 unsigned int total_duration = 0;
117 unsigned int nb_subblocks;
118 unsigned int parameter_id;
119 size_t out_param_size;
139 av_log(
s,
AV_LOG_VERBOSE,
"Non existent parameter_id %d referenced in a parameter block. Ignoring\n",
162 if (constant_subblock_duration == 0)
165 if (constant_subblock_duration >
duration) {
170 nb_subblocks =
duration / constant_subblock_duration;
180 av_log(
s,
AV_LOG_ERROR,
"Invalid duration or subblock count in parameter_id %u\n", parameter_id);
198 for (
int i = 0;
i < nb_subblocks;
i++) {
200 unsigned int subblock_duration = constant_subblock_duration;
204 if (
duration - total_duration > subblock_duration) {
209 total_duration += subblock_duration;
210 }
else if (
i == nb_subblocks - 1)
211 subblock_duration =
duration -
i * constant_subblock_duration;
213 switch (param->
type) {
231 mix->subblock_duration = subblock_duration;
251 unsigned int bitcount = 7 + 5 * !!(recon_gain_flags & 0x80);
252 recon_gain_flags = (recon_gain_flags & 0x7F) | ((recon_gain_flags & 0xFF00) >> 1);
253 for (
int j = 0; j < bitcount; j++) {
254 if (recon_gain_flags & (1 << j))
263 av_unreachable(
"param_definition_type should have been checked in descriptor");
270 av_log(
s,
level,
"Underread in parameter_block_obu. %d bytes left at the end\n",
len);
279 switch (param->
type) {
283 c->mix_size = out_param_size;
287 c->demix = out_param;
288 c->demix_size = out_param_size;
292 c->recon = out_param;
293 c->recon_size = out_param_size;
296 av_unreachable(
"param_definition_type should have been checked in descriptor");
317 unsigned skip_samples, discard_padding;
330 &skip_samples, &discard_padding);
340 skip_samples, discard_padding, stream_id_offset,
simple assert() macros that are a bit more flexible than ISO C assert().
#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.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
unsigned int avio_rb16(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int avio_r8(AVIOContext *s)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
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))
unsigned int ffio_read_leb(AVIOContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
#define i(width, name, range_min, range_max)
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AVDISCARD_ALL
discard all
@ 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_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
#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.
static av_always_inline void * av_iamf_param_definition_get_subblock(const AVIAMFParamDefinition *par, unsigned int idx)
Get the subblock at the specified idx.
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 nb_subblocks amount of subblocks of the ...
@ 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_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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)
static int audio_frame_obu(AVFormatContext *s, const IAMFDemuxContext *c, AVIOContext *pb, AVPacket *pkt, int len, enum IAMF_OBU_Type type, unsigned skip_samples, unsigned discard_padding, int stream_id_offset, int id_in_bitstream)
static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c, AVIOContext *pbc, int len)
int ff_iamf_read_packet(AVFormatContext *s, IAMFDemuxContext *c, AVIOContext *pb, int max_size, int stream_id_offset, AVPacket *pkt)
static AVStream * find_stream_by_id(AVFormatContext *s, int id, int stream_id_offset)
void ff_iamf_read_deinit(IAMFDemuxContext *c)
static int param_definition(const IAMFContext *iamf, const IAMFParamDefinition *param_def, AVIOContext *dyn_bc, void *log_ctx)
static int mix(int c0, int c1)
static av_const int sign_extend(int val, unsigned bits)
Memory handling functions.
static const uint8_t header[24]
Information on how to combine one or more audio streams, as defined in section 3.6 of IAMF.
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.
Mix Gain Parameter Data as defined in section 3.8.1 of IAMF.
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...
This structure stores compressed data.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int index
stream index in AVFormatContext
unsigned int codec_config_id
const AVIAMFAudioElement * celement