[FFmpeg-cvslog] avformat/iamfdec: set disposition flags to output streams

James Almer git at videolan.org
Tue Feb 20 01:53:49 EET 2024


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Feb 18 18:04:14 2024 -0300| [80131321c48362e743a84aafd845871330bc4023] | committer: James Almer

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 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=80131321c48362e743a84aafd845871330bc4023
---

 libavformat/iamf.h       |  1 -
 libavformat/iamf_parse.c | 16 ++++++++++++++++
 libavformat/iamfdec.c    |  4 ++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/libavformat/iamf.h b/libavformat/iamf.h
index 0cb0902e86..ae1e46a99e 100644
--- a/libavformat/iamf.h
+++ b/libavformat/iamf.h
@@ -99,7 +99,6 @@ typedef struct IAMFAudioElement {
 
     unsigned int codec_config_id;
 
-    // mux
     IAMFLayer *layers;
     unsigned int nb_layers;
 } IAMFAudioElement;
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 50dfd1a6c2..50b53aa5e9 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -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)
diff --git a/libavformat/iamfdec.c b/libavformat/iamfdec.c
index de4d502f5a..d286a824ce 100644
--- a/libavformat/iamfdec.c
+++ b/libavformat/iamfdec.c
@@ -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);
         }



More information about the ffmpeg-cvslog mailing list