You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
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>
This commit is contained in:
@@ -240,8 +240,13 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (j >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
|
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);
|
for (j = 0; j < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); j++)
|
||||||
return AVERROR(EINVAL);
|
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));
|
avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
|
||||||
for (int i = 0; i < element->nb_layers; i++) {
|
for (int i = 0; i < element->nb_layers; i++) {
|
||||||
const AVIAMFLayer *layer = element->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++) {
|
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]))
|
if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout]))
|
||||||
break;
|
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));
|
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->output_gain_flags);
|
||||||
put_bits(&pb, 1, !!(layer->flags & AV_IAMF_LAYER_FLAG_RECON_GAIN));
|
put_bits(&pb, 1, !!(layer->flags & AV_IAMF_LAYER_FLAG_RECON_GAIN));
|
||||||
put_bits(&pb, 2, 0); // reserved
|
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, 2, 0);
|
||||||
put_bits(&pb, 16, rescale_rational(layer->output_gain, 1 << 8));
|
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);
|
flush_put_bits(&pb);
|
||||||
avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
|
avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user