History

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

James Almer committed 1 year ago

Commit cc9843d1 parent d255f901 file · +17 −4Browse files

Unified · Split

libavformat/iamf_writer.c+17−4
@@ -240,8 +240,13 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 239 unmodified lines
240240 break;
241241
242242 if (j >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
243− av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout in stream group #%d\n", i);
244− return AVERROR(EINVAL);
243+ for (j = 0; j < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); j++)
244+ if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[j]))
245+ break;
246+ if (j >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) {
247+ av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout in stream group #%d\n", i);
248+ return AVERROR(EINVAL);
249+ }
245250 }
246251 }
247252
@@ -539,13 +544,19 @@ static int scalable_channel_layout_config(const IAMFAudioElement *audio_element, · 291 unmodified lines
539544 avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
540545 for (int i = 0; i < element->nb_layers; i++) {
541546 const AVIAMFLayer *layer = element->layers[i];
542− int layout;
547+ int layout, expanded_layout = -1;
543548 for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) {
544549 if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout]))
545550 break;
546551 }
552+ if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts))
553+ for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); expanded_layout++) {
554+ if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout]))
555+ break;
556+ }
557+ av_assert0(expanded_layout > 0 || layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts));
547558 init_put_bits(&pb, header, sizeof(header));
548− put_bits(&pb, 4, layout);
559+ put_bits(&pb, 4, expanded_layout >= 0 ? 15 : layout);
549560 put_bits(&pb, 1, !!layer->output_gain_flags);
550561 put_bits(&pb, 1, !!(layer->flags & AV_IAMF_LAYER_FLAG_RECON_GAIN));
551562 put_bits(&pb, 2, 0); // reserved
@@ -556,6 +567,8 @@ static int scalable_channel_layout_config(const IAMFAudioElement *audio_element, · 4 unmodified lines
556567 put_bits(&pb, 2, 0);
557568 put_bits(&pb, 16, rescale_rational(layer->output_gain, 1 << 8));
558569 }
570+ if (expanded_layout >= 0)
571+ put_bits(&pb, 8, expanded_layout);
559572 flush_put_bits(&pb);
560573 avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
561574 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t