avformat/iamfdec: set disposition flags to output streams

if there's an audio layer with a single stream that can be rendered alone, mark it
as default. Otherwise, mark every stream as dependent.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2024-02-18 18:04:14 -03:00
parent c95c8a0158
commit 80131321c4
3 changed files with 20 additions and 1 deletions

View File

@ -99,7 +99,6 @@ typedef struct IAMFAudioElement {
unsigned int codec_config_id;
// mux
IAMFLayer *layers;
unsigned int nb_layers;
} IAMFAudioElement;

View File

@ -333,6 +333,11 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
if (nb_layers > 6)
return AVERROR_INVALIDDATA;
audio_element->layers = av_calloc(nb_layers, sizeof(*audio_element->layers));
if (!audio_element->layers)
return AVERROR(ENOMEM);
audio_element->nb_layers = nb_layers;
for (int i = 0; i < nb_layers; i++) {
AVIAMFLayer *layer;
int loudspeaker_layout, output_gain_is_present_flag;
@ -350,6 +355,8 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
substream_count = avio_r8(pb);
coupled_substream_count = avio_r8(pb);
audio_element->layers[i].substream_count = substream_count;
audio_element->layers[i].coupled_substream_count = coupled_substream_count;
if (output_gain_is_present_flag) {
layer->output_gain_flags = avio_r8(pb) >> 2; // get_bits(&gb, 6);
layer->output_gain = av_make_q(sign_extend(avio_rb16(pb), 16), 1 << 8);
@ -401,6 +408,13 @@ static int ambisonics_config(void *s, AVIOContext *pb,
if ((order + 1) * (order + 1) != output_channel_count)
return AVERROR_INVALIDDATA;
audio_element->layers = av_mallocz(sizeof(*audio_element->layers));
if (!audio_element->layers)
return AVERROR(ENOMEM);
audio_element->nb_layers = 1;
audio_element->layers->substream_count = substream_count;
layer = av_iamf_audio_element_add_layer(audio_element->element);
if (!layer)
return AVERROR(ENOMEM);
@ -430,6 +444,8 @@ static int ambisonics_config(void *s, AVIOContext *pb,
int nb_demixing_matrix = substream_count + coupled_substream_count;
int demixing_matrix_size = nb_demixing_matrix * output_channel_count;
audio_element->layers->coupled_substream_count = coupled_substream_count;
layer->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_AMBISONIC, .nb_channels = output_channel_count };
layer->demixing_matrix = av_malloc_array(demixing_matrix_size, sizeof(*layer->demixing_matrix));
if (!layer->demixing_matrix)

View File

@ -106,6 +106,10 @@ static int iamf_read_header(AVFormatContext *s)
if (ret < 0)
return ret;
if (!i && !j && audio_element->layers[0].substream_count == 1)
st->disposition |= AV_DISPOSITION_DEFAULT;
else
st->disposition |= AV_DISPOSITION_DEPENDENT;
st->id = substream->audio_substream_id;
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
}