ffmpeg | branch: master | James Almer <jamr...@gmail.com> | Tue Jun 17 20:48:49 2025 -0300| [a3a7b8edc94cf41c79cc97ab44c706326a13303e] | committer: James Almer
avformat/iamf_writer: factor out getting loudspeaker_layout values Signed-off-by: James Almer <jamr...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a3a7b8edc94cf41c79cc97ab44c706326a13303e --- libavformat/iamf_writer.c | 65 ++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c index 86d09c3308..635d1989ef 100644 --- a/libavformat/iamf_writer.c +++ b/libavformat/iamf_writer.c @@ -577,6 +577,41 @@ static inline int rescale_rational(AVRational q, int b) return av_clip_int16(av_rescale(q.num, b, q.den)); } +static void get_loudspeaker_layout(const AVIAMFLayer *layer, + int *playout, int *pexpanded_layout) +{ + int layout, expanded_layout = -1; + + for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) { + if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout])) + break; + } + if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) { + for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) + if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) == + av_channel_layout_subset(&ff_iamf_scalable_ch_layouts[layout], UINT64_MAX)) + break; + } + if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) { + layout = 15; + for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) { + if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout])) + break; + } + if (expanded_layout >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) { + for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) + if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) == + av_channel_layout_subset(&ff_iamf_expanded_scalable_ch_layouts[expanded_layout], UINT64_MAX)) + break; + } + } + av_assert0((expanded_layout > 0 && expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) || + layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)); + + *playout = layout; + *pexpanded_layout = expanded_layout; +} + static int scalable_channel_layout_config(const IAMFAudioElement *audio_element, AVIOContext *dyn_bc) { @@ -591,33 +626,11 @@ static int scalable_channel_layout_config(const IAMFAudioElement *audio_element, avio_write(dyn_bc, header, put_bytes_count(&pb, 1)); for (int i = 0; i < element->nb_layers; i++) { const AVIAMFLayer *layer = element->layers[i]; - int layout, expanded_layout = -1; - for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) { - if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout])) - break; - } - if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) { - for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) - if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) == - av_channel_layout_subset(&ff_iamf_scalable_ch_layouts[layout], UINT64_MAX)) - break; - } - if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) { - for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) { - if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout])) - break; - } - if (expanded_layout >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) { - for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) - if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) == - av_channel_layout_subset(&ff_iamf_expanded_scalable_ch_layouts[expanded_layout], UINT64_MAX)) - break; - } - } - av_assert0((expanded_layout > 0 && expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) || - layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)); + int layout, expanded_layout; + + get_loudspeaker_layout(layer, &layout, &expanded_layout); init_put_bits(&pb, header, sizeof(header)); - put_bits(&pb, 4, expanded_layout >= 0 ? 15 : layout); + put_bits(&pb, 4, layout); put_bits(&pb, 1, !!layer->output_gain_flags); put_bits(&pb, 1, !!(layer->flags & AV_IAMF_LAYER_FLAG_RECON_GAIN)); put_bits(&pb, 2, 0); // reserved _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".