Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial-at-gmail.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 6/9] avformat/iamf_writer: factorize out getting loudspeaker_layout values
Date: Tue, 17 Jun 2025 22:39:01 -0300
Message-ID: <20250618013904.15638-6-jamrial@gmail.com> (raw)
In-Reply-To: <20250618013904.15638-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 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
-- 
2.50.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2025-06-18  1:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
2025-06-18  1:38 ` [FFmpeg-devel] [PATCH 2/9] avformat/iamf_parse: try to retype the channel layout for ambisonics_mode == 0 James Almer
2025-06-18  1:38 ` [FFmpeg-devel] [PATCH 3/9] tests/iamf: reorder muxed streams James Almer
2025-06-18  1:38 ` [FFmpeg-devel] [PATCH 4/9] tests/iamf: rename BACK to SIDE filterchain labels in the 5.1.4 iamf tests James Almer
2025-06-18  1:39 ` [FFmpeg-devel] [PATCH 5/9] avformat/iamf: fix setting channel layout for Scalable layers James Almer
2025-06-18  1:39 ` James Almer [this message]
2025-06-18  1:39 ` [FFmpeg-devel] [PATCH 7/9] avformat/iamf_writer: add extra constrains for Parameter Sets in Audio Elements James Almer
2025-06-18  1:39 ` [FFmpeg-devel] [PATCH 8/9] avformat/iamf_writer: reindent after previous commit James Almer
2025-06-18  1:39 ` [FFmpeg-devel] [PATCH 9/9] avformat/iamf_writer: use named constants in more places James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250618013904.15638-6-jamrial@gmail.com \
    --to=jamrial-at-gmail.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git