diff options
author | James Almer <jamrial@gmail.com> | 2024-12-10 10:56:14 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-12-13 16:36:10 -0300 |
commit | cc9843dc33bc1ced3e03e28d145ff7a9ce8d27c7 (patch) | |
tree | f8b35071846575f0b2e8a7e075bc77e19be61026 | |
parent | d255f902428665d545cf325a0cb6740193b276eb (diff) | |
download | ffmpeg-cc9843dc33bc1ced3e03e28d145ff7a9ce8d27c7.tar.gz |
avformat/iamf_writer: add support for expanded channel layouts
Defined in Immersive Audio Model and Formats 1.1.0, sections 3.6.2 and 3.7.3
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | libavformat/iamf_writer.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c index 7703729e07..f15dabcb3e 100644 --- a/libavformat/iamf_writer.c +++ b/libavformat/iamf_writer.c @@ -240,8 +240,13 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void break; if (j >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) { - av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout in stream group #%d\n", i); - return AVERROR(EINVAL); + for (j = 0; j < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); j++) + if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[j])) + break; + if (j >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) { + av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout in stream group #%d\n", i); + return AVERROR(EINVAL); + } } } @@ -539,13 +544,19 @@ 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; + 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 (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); expanded_layout++) { + if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout])) + break; + } + av_assert0(expanded_layout > 0 || layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)); init_put_bits(&pb, header, sizeof(header)); - put_bits(&pb, 4, layout); + put_bits(&pb, 4, expanded_layout >= 0 ? 15 : 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 @@ -556,6 +567,8 @@ static int scalable_channel_layout_config(const IAMFAudioElement *audio_element, put_bits(&pb, 2, 0); put_bits(&pb, 16, rescale_rational(layer->output_gain, 1 << 8)); } + if (expanded_layout >= 0) + put_bits(&pb, 8, expanded_layout); flush_put_bits(&pb); avio_write(dyn_bc, header, put_bytes_count(&pb, 1)); } |