From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avutil/channel_layout: print known layout names in custom layout
Date: Tue, 13 Feb 2024 14:39:38 -0300
Message-ID: <20240213173938.6645-1-jamrial@gmail.com> (raw)
In-Reply-To: <20240212211537.18468-3-cus@passwd.hu>
If a custom layout is equivalent to a native one, check if it matches one of the
known layout names and print that instead.
Signed-off-by: James Almer <jamrial@gmail.com>
---
Should be applied after the patch this one is a reply to.
libavutil/channel_layout.c | 68 +++++++++++++++++++++--------------
tests/ref/fate/channel_layout | 4 +--
2 files changed, 44 insertions(+), 28 deletions(-)
diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index 7f51c076dc..8b3bf2f4af 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -679,6 +679,29 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
return 0;
}
+static int64_t masked_description(const AVChannelLayout *channel_layout, int start_channel)
+{
+ uint64_t mask = 0;
+ for (int i = start_channel; i < channel_layout->nb_channels; i++) {
+ enum AVChannel ch = channel_layout->u.map[i].id;
+ if (ch >= 0 && ch < 63 && mask < (1ULL << ch))
+ mask |= (1ULL << ch);
+ else
+ return AVERROR(EINVAL);
+ }
+ return mask;
+}
+
+static int has_channel_names(const AVChannelLayout *channel_layout)
+{
+ if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
+ return 0;
+ for (int i = 0; i < channel_layout->nb_channels; i++)
+ if (channel_layout->u.map[i].name[0])
+ return 1;
+ return 0;
+}
+
/**
* If the layout is n-th order standard-order ambisonic, with optional
* extra non-diegetic channels at the end, return the order.
@@ -746,9 +769,17 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l
extra.nb_channels = av_popcount64(channel_layout->u.mask);
extra.u.mask = channel_layout->u.mask;
} else {
- extra.order = AV_CHANNEL_ORDER_CUSTOM;
- extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
- extra.u.map = channel_layout->u.map + nb_ambi_channels;
+ int64_t mask;
+ if (!has_channel_names(channel_layout) &&
+ (mask = masked_description(channel_layout, nb_ambi_channels)) > 0) {
+ extra.order = AV_CHANNEL_ORDER_NATIVE;
+ extra.nb_channels = av_popcount64(mask);
+ extra.u.mask = mask;
+ } else {
+ extra.order = AV_CHANNEL_ORDER_CUSTOM;
+ extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
+ extra.u.map = channel_layout->u.map + nb_ambi_channels;
+ }
}
av_bprint_chars(bp, '+', 1);
@@ -774,9 +805,17 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
// fall-through
case AV_CHANNEL_ORDER_CUSTOM:
if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
+ int64_t mask;
int res = try_describe_ambisonic(bp, channel_layout);
if (res >= 0)
return 0;
+ if (!has_channel_names(channel_layout) &&
+ (mask = masked_description(channel_layout, 0)) > 0) {
+ AVChannelLayout native = { .order = AV_CHANNEL_ORDER_NATIVE,
+ .nb_channels = av_popcount64(mask),
+ .u.mask = mask };
+ return av_channel_layout_describe_bprint(&native, bp);
+ }
}
if (channel_layout->nb_channels)
av_bprintf(bp, "%d channels (", channel_layout->nb_channels);
@@ -1037,29 +1076,6 @@ uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,
return ret;
}
-static int64_t masked_description(AVChannelLayout *channel_layout, int start_channel)
-{
- uint64_t mask = 0;
- for (int i = start_channel; i < channel_layout->nb_channels; i++) {
- enum AVChannel ch = channel_layout->u.map[i].id;
- if (ch >= 0 && ch < 63 && mask < (1ULL << ch))
- mask |= (1ULL << ch);
- else
- return AVERROR(EINVAL);
- }
- return mask;
-}
-
-static int has_channel_names(AVChannelLayout *channel_layout)
-{
- if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
- return 0;
- for (int i = 0; i < channel_layout->nb_channels; i++)
- if (channel_layout->u.map[i].name[0])
- return 1;
- return 0;
-}
-
int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
{
int allow_lossy = !(flags & AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS);
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
index 1d1f1cb082..466fa78d9e 100644
--- a/tests/ref/fate/channel_layout
+++ b/tests/ref/fate/channel_layout
@@ -195,7 +195,7 @@ With "FL@Boo": CUSTOM (1 channels (FL@Boo))
With "stereo": NATIVE (stereo)
~~ UNSPEC (2 channels)
== NATIVE (stereo)
- == CUSTOM (2 channels (FL+FR))
+ == CUSTOM (stereo)
!= AMBI
With "FR+FL": CUSTOM (2 channels (FR+FL))
~~ UNSPEC (2 channels)
@@ -205,7 +205,7 @@ With "FR+FL": CUSTOM (2 channels (FR+FL))
With "ambisonic 2+stereo": AMBI (ambisonic 2+stereo)
~~ UNSPEC (11 channels)
!= NATIVE
- == CUSTOM (ambisonic 2+2 channels (FL+FR))
+ == CUSTOM (ambisonic 2+stereo)
== AMBI (ambisonic 2+stereo)
With "2C": UNSPEC (2 channels)
== UNSPEC (2 channels)
--
2.43.1
_______________________________________________
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-13 17:40 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 ` [FFmpeg-devel] [PATCH 3/5] avutil/tests/channel_layout: add tests for av_channel_order_retype Marton Balint
2024-02-13 17:39 ` James Almer [this message]
2024-02-18 12:58 ` [FFmpeg-devel] [PATCH] avutil/channel_layout: print known layout names in custom layout 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=20240213173938.6645-1-jamrial@gmail.com \
--to=jamrial@gmail.com \
--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