From: Marton Balint <cus@passwd.hu>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 001/279 v2] Add a new channel layout API
Date: Fri, 17 Dec 2021 00:27:00 +0100 (CET)
Message-ID: <87bcdbcf-1820-5929-50a7-f7491cc5ca13@passwd.hu> (raw)
In-Reply-To: <20211216132151.8216-2-jamrial@gmail.com>
On Thu, 16 Dec 2021, James Almer wrote:
> - Added a 16 byte fixed array to AVChannelCustom to give custom
> labels to channels in Custom order layouts. These labes will
> be used by the helpers when querying channels by name or
> describing the layout.
I don't think this is a good idea to use the labels directly in helpers
instead of the channel designation names. See more below.
It is also not great that if the user wants to label a channel, he has to
use a custom layout. So I'd rather remove the name field from
AVChannelCustom, I find it limited anyway.
[..]
> +enum AVChannel av_channel_from_string(const char *str)
> +{
> + int i;
> + char *endptr = (char *)str;
> + enum AVChannel id = AV_CHAN_NONE;
> + for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
> + if (channel_names[i].name && !strcmp(str, channel_names[i].name))
> + return i;
> + }
> + if (!strncmp(str, "USR", 3)) {
> + const char *p = str + 3;
> + id = strtol(p, &endptr, 0);
> + }
> + if (id > 0 && !*endptr)
id >= 0
[..]
> +int av_channel_layout_from_mask(AVChannelLayout *channel_layout,
> + uint64_t mask)
> +{
> + if (!mask)
> + return AVERROR(EINVAL);
> +
> + channel_layout->order = AV_CHANNEL_ORDER_NATIVE;
> + channel_layout->nb_channels = av_popcount64(mask);
> + channel_layout->u.mask = mask;
> +
> + return 0;
> +}
Probably a constructor for custom layout would also make sense:
int av_channel_layout_custom(AVChannelLayout *channel_layout, int nb_channels)
[...]
> +
> +int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
> +{
> + av_channel_layout_uninit(dst);
> + *dst = *src;
> + if (src->order == AV_CHANNEL_ORDER_CUSTOM) {
> + dst->u.map = av_malloc(src->nb_channels * sizeof(*dst->u.map));
av_malloc_array()
> +int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
> + AVBPrint *bp)
> +{
> + int i;
> +
> + av_bprint_clear(bp);
> +
> + switch (channel_layout->order) {
> + case AV_CHANNEL_ORDER_NATIVE:
> + for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
> + if (channel_layout->u.mask == channel_layout_map[i].layout.u.mask) {
> + av_bprintf(bp, "%s", channel_layout_map[i].name);
> + return 0;
> + }
> + // fall-through
> + case AV_CHANNEL_ORDER_CUSTOM:
> + for (i = 0; i < channel_layout->nb_channels; i++) {
> + const char *ch_name = NULL;
> + enum AVChannel ch = AV_CHAN_NONE;
> +
> + if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM &&
> + channel_layout->u.map[i].name[0])
> + ch_name = channel_layout->u.map[i].name;
> + if (channel_layout->order == AV_CHANNEL_ORDER_NATIVE || !ch_name) {
> + ch = av_channel_layout_channel_from_index(channel_layout, i);
> + ch_name = get_channel_name(ch);
> + }
You are mixing channel labels and channel designations, and it can be the
source of confusion. I guess the main problem is that the label of the
channel can be totally unrelated to the channel designation.
You could show it as some combination. E.g. FL@label. This way there
will be no confusion, that part before @ is the designation, part after
the @ is the channel label.
[..]
> +enum AVChannel
> +av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
> + const char *name)
> +{
> + int channel, ret;
> +
> + switch (channel_layout->order) {
> + case AV_CHANNEL_ORDER_CUSTOM:
> + for (int i = 0; i < channel_layout->nb_channels; i++) {
> + if (channel_layout->u.map[i].name[0] && !strcmp(name, channel_layout->u.map[i].name))
> + return channel_layout->u.map[i].id;
This is the reverse case, I also find it confusing that name can be a
label and a designation at the same time and it depends on the channel
layout type which one is it... Yet again, some syntax could help. E.g. a
string without @ is a designation, @label is a label without any filter
for channel designation, designation@label filters both.
[..]
> +int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout,
> + const char *name)
> +{
> + enum AVChannel ch;
> +
> + switch (channel_layout->order) {
> + case AV_CHANNEL_ORDER_CUSTOM:
> + for (int i = 0; i < channel_layout->nb_channels; i++) {
> + if (channel_layout->u.map[i].name[0] && !strcmp(name, channel_layout->u.map[i].name))
> + return i;
Same here.
[..]
> +int av_channel_layout_check(const AVChannelLayout *channel_layout)
av_channel_layout_valid would be more readable.
Thanks,
Marton
_______________________________________________
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:[~2021-12-16 23:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-16 13:21 [FFmpeg-devel] [PATCH 000/279 v2] New " James Almer
2021-12-16 13:21 ` [FFmpeg-devel] [PATCH 001/279 v2] Add a new " James Almer
2021-12-16 17:20 ` Paul B Mahol
2021-12-16 18:27 ` James Almer
2021-12-16 18:31 ` Paul B Mahol
2021-12-16 19:14 ` James Almer
2021-12-16 23:27 ` Marton Balint [this message]
2021-12-17 2:34 ` James Almer
2021-12-17 12:43 ` James Almer
2021-12-16 13:21 ` [FFmpeg-devel] [PATCH 002/279 v2] fate: add a channel_layout API test James Almer
2021-12-17 0:04 ` [FFmpeg-devel] [PATCH 000/279 v2] New channel layout API Marton Balint
2021-12-17 2:37 ` James Almer
2021-12-17 19:20 ` Marton Balint
2021-12-17 19:32 ` James Almer
2021-12-17 11:24 ` Michael Niedermayer
2021-12-17 18:04 ` Marton Balint
2021-12-18 13:36 ` Michael Niedermayer
2021-12-18 14:15 ` Michael Niedermayer
2021-12-19 11:35 ` Marton Balint
2021-12-19 12:51 ` Michael Niedermayer
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=87bcdbcf-1820-5929-50a7-f7491cc5ca13@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