From c39bc13fdb492c3fec1bbdaf031bc41e250eedcf Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 14 Aug 2026 16:11:08 -0300 Subject: [PATCH] swresample/tests/rematrix: print rows in layout order Otherwise, custom layouts will be printed as if they were in native order. Signed-off-by: James Almer --- libswresample/tests/rematrix.c | 36 ++++++++++------------- tests/ref/fate/swr-rematrix-unused-output | 2 +- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/libswresample/tests/rematrix.c b/libswresample/tests/rematrix.c index 9b5106cdfb..4d8b3d1114 100644 --- a/libswresample/tests/rematrix.c +++ b/libswresample/tests/rematrix.c @@ -41,16 +41,15 @@ static void print_matrix_row(const double *matrix, printf("[%s] = { ", out_name); for (int i = 0; i < 64; i++) { - int in = av_channel_layout_index_from_channel(in_layout, i); - if (in < 0) + enum AVChannel in_ch = av_channel_layout_channel_from_index(in_layout, i); + if (in_ch == AV_CHAN_NONE) continue; - av_channel_name(in_name, sizeof(in_name), i); - printf(".%s = %f, ", in_name, matrix[out * MATRIX_STRIDE + in]); - } - for (int in = 0; in < in_layout->nb_channels; in++) { - if (channel_is_unused(in_layout, in)) - printf(".UNSD%d = %f, ", in, - matrix[out * MATRIX_STRIDE + in]); + av_channel_name(in_name, sizeof(in_name), in_ch); + if (in_ch == AV_CHAN_UNUSED) + printf(".UNSD%d = %f, ", i, + matrix[out * MATRIX_STRIDE + i]); + else + printf(".%s = %f, ", in_name, matrix[out * MATRIX_STRIDE + i]); } printf("},\n"); } @@ -91,18 +90,15 @@ static int print_matrix(const AVChannelLayout *in_layout, } } - for (int i = 0; i < 64; i++) { - int out_i = av_channel_layout_index_from_channel(out_layout, i); - if (out_i < 0) + for (int i = 0; i < out_layout->nb_channels; i++) { + enum AVChannel out_ch = av_channel_layout_channel_from_index(out_layout, i); + if (out_ch == AV_CHAN_NONE) continue; - av_channel_name(out_name, sizeof(out_name), i); - print_matrix_row(matrix, in_layout, out_i, out_name); - } - for (int out = 0; out < out_layout->nb_channels; out++) { - if (channel_is_unused(out_layout, out)) { - snprintf(out_name, sizeof(out_name), "UNSD%d", out); - print_matrix_row(matrix, in_layout, out, out_name); - } + if (out_ch == AV_CHAN_UNUSED) + snprintf(out_name, sizeof(out_name), "UNSD%d", i); + else + av_channel_name(out_name, sizeof(out_name), out_ch); + print_matrix_row(matrix, in_layout, i, out_name); } return 0; diff --git a/tests/ref/fate/swr-rematrix-unused-output b/tests/ref/fate/swr-rematrix-unused-output index ab327fdd5f..36083e89ca 100644 --- a/tests/ref/fate/swr-rematrix-unused-output +++ b/tests/ref/fate/swr-rematrix-unused-output @@ -1,4 +1,4 @@ [FL] = { .FL = 1.000000, .FR = 0.000000, .FC = 0.707107, .LFE = 0.000000, .BL = 0.707107, .BR = 0.000000, }, -[FR] = { .FL = 0.000000, .FR = 1.000000, .FC = 0.707107, .LFE = 0.000000, .BL = 0.000000, .BR = 0.707107, }, [UNSD1] = { .FL = 0.000000, .FR = 0.000000, .FC = 0.000000, .LFE = 0.000000, .BL = 0.000000, .BR = 0.000000, }, +[FR] = { .FL = 0.000000, .FR = 1.000000, .FC = 0.707107, .LFE = 0.000000, .BL = 0.000000, .BR = 0.707107, }, [UNSD3] = { .FL = 0.000000, .FR = 0.000000, .FC = 0.000000, .LFE = 0.000000, .BL = 0.000000, .BR = 0.000000, },