From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2DABE42232 for ; Thu, 16 Dec 2021 23:27:11 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D76068AFB7; Fri, 17 Dec 2021 01:27:09 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE2D668AF90 for ; Fri, 17 Dec 2021 01:27:02 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 08976E6586 for ; Fri, 17 Dec 2021 00:27:02 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HnsppGgvqGVQ for ; Fri, 17 Dec 2021 00:27:00 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 6E550E62C4 for ; Fri, 17 Dec 2021 00:27:00 +0100 (CET) Date: Fri, 17 Dec 2021 00:27:00 +0100 (CET) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20211216132151.8216-2-jamrial@gmail.com> Message-ID: <87bcdbcf-1820-5929-50a7-f7491cc5ca13@passwd.hu> References: <20211216132151.8216-1-jamrial@gmail.com> <20211216132151.8216-2-jamrial@gmail.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 001/279 v2] Add a new channel layout API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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".