From: Marton Balint <cus@passwd.hu>
To: ffmpeg-devel@ffmpeg.org
Cc: Marton Balint <cus@passwd.hu>
Subject: [FFmpeg-devel] [PATCH 3/5] avutil/tests/channel_layout: add tests for av_channel_order_retype
Date: Mon, 12 Feb 2024 22:15:35 +0100
Message-ID: <20240212211537.18468-3-cus@passwd.hu> (raw)
In-Reply-To: <20240212211537.18468-1-cus@passwd.hu>
Signed-off-by: Marton Balint <cus@passwd.hu>
---
libavutil/tests/channel_layout.c | 63 ++++++++++++++++++++++++++++++++
tests/ref/fate/channel_layout | 27 ++++++++++++++
2 files changed, 90 insertions(+)
diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c
index c537e7e710..d83839700c 100644
--- a/libavutil/tests/channel_layout.c
+++ b/libavutil/tests/channel_layout.c
@@ -24,6 +24,7 @@
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/error.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
@@ -112,6 +113,53 @@ static void channel_layout_from_string(AVChannelLayout *layout,
av_bprintf(bp, "fail");
}
+static const char* channel_order_names[AV_CHANNEL_ORDER_NB] = {"UNSPEC", "NATIVE", "CUSTOM", "AMBI"};
+
+static void describe_type(AVBPrint *bp, AVChannelLayout *layout)
+{
+ if (layout->order >= 0 && layout->order < AV_CHANNEL_ORDER_NB) {
+ av_bprintf(bp, "%-6s (", channel_order_names[layout->order]);
+ av_channel_layout_describe_bprint(layout, bp);
+ av_bprintf(bp, ")");
+ } else {
+ av_bprintf(bp, "???");
+ }
+}
+
+static const char *channel_layout_retype(AVChannelLayout *layout, AVBPrint *bp, const char *channel_layout)
+{
+ av_channel_layout_uninit(layout);
+ av_bprint_clear(bp);
+ if (!av_channel_layout_from_string(layout, channel_layout) &&
+ av_channel_layout_check(layout)) {
+ describe_type(bp, layout);
+ for (int i = 0; i < AV_CHANNEL_ORDER_NB; i++) {
+ int ret;
+ AVChannelLayout copy = {0};
+ av_bprintf(bp, "\n ");
+ if (av_channel_layout_copy(©, layout) < 0)
+ return "nomem";
+ ret = av_channel_layout_retype(©, i, 0);
+ if (ret < 0 && (copy.order != layout->order || av_channel_layout_compare(©, layout)))
+ av_bprintf(bp, "failed to keep existing layout on failure ");
+ if (ret >= 0 && copy.order != i)
+ av_bprintf(bp, "returned success but did not change order ");
+ if (ret == AVERROR(ENOSYS)) {
+ av_bprintf(bp, " != %s", channel_order_names[i]);
+ } else if (ret < 0) {
+ av_bprintf(bp, "FAIL");
+ } else {
+ av_bprintf(bp, " %s ", ret ? "~~" : "==");
+ describe_type(bp, ©);
+ }
+ av_channel_layout_uninit(©);
+ }
+ } else {
+ av_bprintf(bp, "fail");
+ }
+ return bp->str;
+}
+
#define CHANNEL_NAME(x) \
channel_name(&bp, (x));
@@ -437,5 +485,20 @@ int main(void)
av_channel_layout_uninit(&layout2);
av_bprint_finalize(&bp, NULL);
+ printf("\nTesting av_channel_layout_retype\n");
+ {
+ const char* layouts[] = {
+ "FL@Boo",
+ "stereo",
+ "FR+FL",
+ "ambisonic 2+stereo",
+ "2C",
+ NULL
+ };
+ for (int i = 0; layouts[i]; i++) {
+ printf("With \"%s\": %s\n", layouts[i], channel_layout_retype(&layout, &bp, layouts[i]));
+ }
+ }
+
return 0;
}
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
index ab9bee947b..1d1f1cb082 100644
--- a/tests/ref/fate/channel_layout
+++ b/tests/ref/fate/channel_layout
@@ -185,3 +185,30 @@ On "ambisonic 2+stereo" layout with 11: -1
Testing av_channel_layout_subset
On "ambisonic 2+stereo" layout with AV_CH_LAYOUT_STEREO: 0x3
On "ambisonic 2+stereo" layout with AV_CH_LAYOUT_QUAD: 0x3
+
+Testing av_channel_layout_retype
+With "FL@Boo": CUSTOM (1 channels (FL@Boo))
+ ~~ UNSPEC (1 channels)
+ ~~ NATIVE (1 channels (FL))
+ == CUSTOM (1 channels (FL@Boo))
+ != AMBI
+With "stereo": NATIVE (stereo)
+ ~~ UNSPEC (2 channels)
+ == NATIVE (stereo)
+ == CUSTOM (2 channels (FL+FR))
+ != AMBI
+With "FR+FL": CUSTOM (2 channels (FR+FL))
+ ~~ UNSPEC (2 channels)
+ != NATIVE
+ == CUSTOM (2 channels (FR+FL))
+ != AMBI
+With "ambisonic 2+stereo": AMBI (ambisonic 2+stereo)
+ ~~ UNSPEC (11 channels)
+ != NATIVE
+ == CUSTOM (ambisonic 2+2 channels (FL+FR))
+ == AMBI (ambisonic 2+stereo)
+With "2C": UNSPEC (2 channels)
+ == UNSPEC (2 channels)
+ != NATIVE
+ == CUSTOM (2 channels (USR768+USR768))
+ != AMBI
--
2.35.3
_______________________________________________
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".
next prev parent reply other threads:[~2024-02-12 21:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 21:15 [FFmpeg-devel] [PATCH 1/5] avutil/channel_layout: change AV_CHAN_SILENCE to AV_CHAN_UNUSED in the docs Marton Balint
2024-02-12 21:15 ` [FFmpeg-devel] [PATCH 2/5] avutil/channel_layout: add AV_CHANNEL_ORDER_NB Marton Balint
2024-02-13 17:25 ` James Almer
2024-02-13 20:27 ` Marton Balint
2024-02-15 14:51 ` Anton Khirnov
2024-02-16 22:42 ` Marton Balint
2024-02-16 22:44 ` James Almer
2024-02-17 23:15 ` Marton Balint
2024-02-12 21:15 ` Marton Balint [this message]
2024-02-13 17:39 ` [FFmpeg-devel] [PATCH] avutil/channel_layout: print known layout names in custom layout James Almer
2024-02-18 12:58 ` James Almer
2024-02-12 21:15 ` [FFmpeg-devel] [PATCH 4/5] avformat/mov: factorize reading the main part of the chnl atom to mov_chan Marton Balint
2024-02-12 21:15 ` [FFmpeg-devel] [PATCH 5/5] avformat/mov: rework ff_mov_read_chnl Marton Balint
2024-02-15 14:52 ` Anton Khirnov
2024-02-15 21:12 ` Marton Balint
2024-02-12 22:09 ` [FFmpeg-devel] [PATCH 1/5] avutil/channel_layout: change AV_CHAN_SILENCE to AV_CHAN_UNUSED in the docs 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=20240212211537.18468-3-cus@passwd.hu \
--to=cus@passwd.hu \
--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