This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 4bab8327f9ee57913259e2bb9c03a29c2c51869a
Author:     Kacper Michajłow <[email protected]>
AuthorDate: Sun Sep 27 16:02:49 2026 +0200
Commit:     Kacper Michajłow <[email protected]>
CommitDate: Tue Sep 29 22:15:33 2026 +0200

    swresample/rematrix: treat a single channel next to unused ones as mono
    
    A layout of one channel is mixed like mono, whatever the channel is.
    Unused channels carry no audio, so the same holds for a custom layout
    that has a single channel next to them. It was rejected for being
    asymmetric.
    
    Signed-off-by: Kacper Michajłow <[email protected]>
---
 libswresample/rematrix.c                       | 37 ++++++++++++++++++++------
 tests/fate/libswresample.mak                   |  8 ++++++
 tests/ref/fate/swr-rematrix-unused-mono-input  |  6 +++++
 tests/ref/fate/swr-rematrix-unused-mono-output |  2 ++
 4 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 582b2b38e3..fa976b7f7c 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -98,17 +98,38 @@ static int even(int64_t layout){
 
 static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void 
*s)
 {
-    int ret = 0;
+    int used = in->nb_channels, idx = 0;
 
-    if (av_channel_layout_index_from_channel(in, AV_CHAN_FRONT_CENTER) < 0 && 
in->nb_channels == 1) {
-        char buf[128];
-        av_channel_layout_describe(in, buf, sizeof(buf));
-        av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
+    if (in->order == AV_CHANNEL_ORDER_CUSTOM && in->nb_channels > 1) {
+        used = 0;
+        for (int i = 0; i < in->nb_channels; i++) {
+            if (in->u.map[i].id != AV_CHAN_UNUSED) {
+                idx = i;
+                used++;
+            }
+        }
+    }
+
+    if (used != 1 ||
+        av_channel_layout_channel_from_index(in, idx) == AV_CHAN_FRONT_CENTER)
+        return av_channel_layout_copy(out, in);
+
+    char buf[128];
+    av_channel_layout_describe(in, buf, sizeof(buf));
+    av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
+
+    if (in->nb_channels == 1) {
         *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
-    } else
-        ret = av_channel_layout_copy(out, in);
+        return 0;
+    }
 
-    return ret;
+    /* the channel keeps its place among the unused ones */
+    int ret = av_channel_layout_copy(out, in);
+    if (ret < 0)
+        return ret;
+    out->u.map[idx].id = AV_CHAN_FRONT_CENTER;
+
+    return 0;
 }
 
 static int sane_layout(const AVChannelLayout *ch_layout) {
diff --git a/tests/fate/libswresample.mak b/tests/fate/libswresample.mak
index 532d529b51..e918bd7b46 100644
--- a/tests/fate/libswresample.mak
+++ b/tests/fate/libswresample.mak
@@ -1150,6 +1150,14 @@ FATE_SWR_REMATRIX-$(CONFIG_SWRESAMPLE) += 
fate-swr-rematrix-unused-output
 fate-swr-rematrix-unused-output: libswresample/tests/rematrix$(EXESUF)
 fate-swr-rematrix-unused-output: CMD = run 
libswresample/tests/rematrix$(EXESUF) 5.1 FL+UNSD+FR+UNSD
 
+FATE_SWR_REMATRIX-$(CONFIG_SWRESAMPLE) += fate-swr-rematrix-unused-mono-input
+fate-swr-rematrix-unused-mono-input: libswresample/tests/rematrix$(EXESUF)
+fate-swr-rematrix-unused-mono-input: CMD = run 
libswresample/tests/rematrix$(EXESUF) BL+UNSD+UNSD 5.1
+
+FATE_SWR_REMATRIX-$(CONFIG_SWRESAMPLE) += fate-swr-rematrix-unused-mono-output
+fate-swr-rematrix-unused-mono-output: libswresample/tests/rematrix$(EXESUF)
+fate-swr-rematrix-unused-mono-output: CMD = run 
libswresample/tests/rematrix$(EXESUF) stereo UNSD+FR
+
 FATE_SWR += $(FATE_SWR_REMATRIX-yes)
 fate-swr-rematrix: $(FATE_SWR_REMATRIX-yes)
 
diff --git a/tests/ref/fate/swr-rematrix-unused-mono-input 
b/tests/ref/fate/swr-rematrix-unused-mono-input
new file mode 100644
index 0000000000..57ca24ebf0
--- /dev/null
+++ b/tests/ref/fate/swr-rematrix-unused-mono-input
@@ -0,0 +1,6 @@
+[FL] = { .BL = 0.000000, .UNSD1 = 0.000000, .UNSD2 = 0.000000, },
+[FR] = { .BL = 0.000000, .UNSD1 = 0.000000, .UNSD2 = 0.000000, },
+[FC] = { .BL = 1.000000, .UNSD1 = 0.000000, .UNSD2 = 0.000000, },
+[LFE] = { .BL = 0.000000, .UNSD1 = 0.000000, .UNSD2 = 0.000000, },
+[BL] = { .BL = 0.000000, .UNSD1 = 0.000000, .UNSD2 = 0.000000, },
+[BR] = { .BL = 0.000000, .UNSD1 = 0.000000, .UNSD2 = 0.000000, },
diff --git a/tests/ref/fate/swr-rematrix-unused-mono-output 
b/tests/ref/fate/swr-rematrix-unused-mono-output
new file mode 100644
index 0000000000..21a67e6d94
--- /dev/null
+++ b/tests/ref/fate/swr-rematrix-unused-mono-output
@@ -0,0 +1,2 @@
+[UNSD0] = { .FL = 0.000000, .FR = 0.000000, },
+[FR] = { .FL = 0.707107, .FR = 0.707107, },

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to