From patchwork Tue Mar 15 21:18:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34785 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3356330nkb; Tue, 15 Mar 2022 14:19:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPVQ0W8nxP23m0rHaqLkXg9oupUL3rolNjbKxs1wJfWeq01FBMEpKSwtQ6yqkoHt1q4Pim X-Received: by 2002:a17:907:7da6:b0:6db:2e12:b85f with SMTP id oz38-20020a1709077da600b006db2e12b85fmr23168156ejc.312.1647379160583; Tue, 15 Mar 2022 14:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647379160; cv=none; d=google.com; s=arc-20160816; b=zQ+CYurGTXhaUeXdorJXPotFhHb7Xx2XdLBf5hDVZ0JrsGxRIp7Qhw0YR6+EGbX/Mr gfj+5BLEJ6cuE/H/b6f047QCp4OH7l1pYm6KKWIzYGJXuNZymWtzjGk9mXOFRKJzEw6U X+e1h+EwiZ4mwBXmLAQbgWUt2mlH3KTxO4OpmJgp0HxwXOhPJ4f6MMgZEoS8KViiKBq0 C8yRg8TteotjNyvRivtH8iN3L+gpsjkx3PMs9q3o9y3Mz3Dha4gv/tr8+oFYFvDtjiTo nVTkvKGBu0RC4Hl4wp9d5Jugn2PDWHAfC0kNfVWoes1wT/MsDd/tMuu64D9kErWSiuyH POIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=vvst9EgM6Y2HmZVBuRJELN2DVBIaqbYXvyTV18RBAz8=; b=oYBCIiuPbYfFVgsZdyCX6JpFWWd3n4WLojHZ0plrEHRcd9cQEBQ/C46PFQYJEPNkgB UkhVR4iTZq/kod6aYQ3gyks+t4kp4R3lBrn3sVfyGpPHDVbqp7P0O+xRoUE9IhtgoYnv vd1DlEiY1h6BDC9/vmYQONeD/OqqFZ2GwTFRH8b3xDdfZCXVOfJ8wElDK3jt9rE76Gm0 nSdutWoCTUxp3W2imD6B4mr1uyQC3r6oKO0dQ1KXrASey6SVoPOAGZRIwp0t+PQLYJ9Q WFt6Gf66S8VpC4vHfm7TvprINTaJ4jzLStmo97DhU7XlyO6FM47bZ/LEPu/xe99+5d5Z Vvsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a17-20020aa7d751000000b00416c32c28bcsi122888eds.278.2022.03.15.14.19.20; Tue, 15 Mar 2022 14:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 41DA168B178; Tue, 15 Mar 2022 23:19:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5AD8268B0B4 for ; Tue, 15 Mar 2022 23:19:12 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B6D59E4DF2; Tue, 15 Mar 2022 22:19:12 +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 PxglZsWcdVvM; Tue, 15 Mar 2022 22:19:10 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 682A1E12AE; Tue, 15 Mar 2022 22:19:10 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 22:18:55 +0100 Message-Id: <20220315211858.26800-1-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <1382f5bd-673f-f429-0ce9-ce39c3f9b586@gmail.com> References: <1382f5bd-673f-f429-0ce9-ce39c3f9b586@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ThkIV4X4yaGp This reduces code duplication an allows printing AMBI%d channel names for custom layouts for non-standard or partial ambisonic layouts. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8cc4efe4cf..c60ccf368f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -737,14 +737,10 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, av_bprintf(bp, "%d channels (", channel_layout->nb_channels); for (i = 0; i < channel_layout->nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i); - const char *channel = get_channel_name(ch); if (i) av_bprintf(bp, "+"); - if (channel) - av_bprintf(bp, "%s", channel); - else - av_bprintf(bp, "USR%d", ch); + av_channel_name_bprint(bp, ch); if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM && channel_layout->u.map[i].name[0]) av_bprintf(bp, "@%s", channel_layout->u.map[i].name); From patchwork Tue Mar 15 21:18:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34786 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3356399nkb; Tue, 15 Mar 2022 14:19:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9M3QJ+W3zRqXjxx2ypF12JaU7OMrEtFF8A9aG/vNvg8Wwv0pMd5XDJgSdrXoFQeyYAUJA X-Received: by 2002:a17:907:7f1f:b0:6da:7d72:1352 with SMTP id qf31-20020a1709077f1f00b006da7d721352mr23894536ejc.225.1647379168469; Tue, 15 Mar 2022 14:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647379168; cv=none; d=google.com; s=arc-20160816; b=i4rBDFGxwzhNup2cUj8fgouB/qmdFQDbEj+cAQH8nDh1MtxHrkFuIGC8kK2du70mK6 8bBBKPGZb9sTWcaEbpLHLYRDn0OnMyZQ3lZiQ9dcHvJxZCXBAH/sAanRZajE0patwLw4 ueax1gZLbV64K9EzUrQQivA8T0Di/8An4hNs0G9LSMb3HkIy9e4d4/CV/aYQH0yy6CYC gsuf9/c5RxfPwaVvJm44ipM1RfZFUh9luN4bPjlJLmgWPFwOGCfD/0m+eQ4XAlVnpwTw d0iwCM3mpVYDKjQZamHFPfxJ+gb5q1jxsAPq4L6F2kbXgDhCnG6BvH3dp0bt1e0S13MC RxKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=k3mLR8Tm75SFpQRwQt5w71Mh4biDPNdJRqc0/6C4gto=; b=YRpYg9g58ITpEe6Ae6PFJoBuOxcU/o8JphyBDhPAEOxlfsco7Bw7lsR1pHRkjy7M/y tOFn1UrKHVQz2FS0f/whOvf+Azr7aBauYftpm3JTkZpVxNKMfLflE3KQMIU8XfYNsGtW hR3gCMMU7M24uUGD7OSuuOtKXG+/7JKpWB49WQ+a8lsiyomzLGaJ7/LiaVaCFsGTc2Y1 5YZCJ1BIJ/oqtak+nGk9HSPsGK1XCgTtyb8hG5+YbKu/jzlR7UeRfMWjoZO5RngLl1kj Kpwf2c4cZBZq7R8TkLZmemQBsEBwa8HHarajrYPZ7FncJahAKiuiQSqWU5f5MKYafCyT S7hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id be21-20020a0564021a3500b00416bf8f0261si132261edb.215.2022.03.15.14.19.28; Tue, 15 Mar 2022 14:19:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 468EF68B120; Tue, 15 Mar 2022 23:19:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E4E1468019F for ; Tue, 15 Mar 2022 23:19:14 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 53A9AE12AE; Tue, 15 Mar 2022 22:19:15 +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 AxXVj5WIKJLk; Tue, 15 Mar 2022 22:19:14 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id E1B44E5466; Tue, 15 Mar 2022 22:19:13 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 22:18:56 +0100 Message-Id: <20220315211858.26800-2-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220315211858.26800-1-cus@passwd.hu> References: <1382f5bd-673f-f429-0ce9-ce39c3f9b586@gmail.com> <20220315211858.26800-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/4] avutil/channel_layout: factorize ambisonic order detection 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wXtsq9hlavzi Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 42 +++++++++++++++++++++++++++----------- libavutil/channel_layout.h | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..0069c6257b 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,31 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) } /** - * If the custom layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * If the layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, return the order. + * Return a negative error code otherwise. */ -static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +static int ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; highest_ambi = -1; - if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) + if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; - else { + } else { const AVChannelCustom *map = channel_layout->u.map; + av_assert0(channel_layout->order == AV_CHANNEL_ORDER_CUSTOM); + for (i = 0; i < channel_layout->nb_channels; i++) { int is_ambi = CHAN_IS_AMBI(map[i].id); /* ambisonic following non-ambisonic */ if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) - return 0; + return AVERROR(EINVAL); /* non-default ordering */ if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) - return 0; + return AVERROR(EINVAL); if (CHAN_IS_AMBI(map[i].id)) highest_ambi = i; @@ -674,17 +676,33 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l } /* no ambisonic channels*/ if (highest_ambi < 0) - return 0; + return AVERROR(EINVAL); order = floor(sqrt(highest_ambi)); /* incomplete order - some harmonics are missing */ if ((order + 1) * (order + 1) != highest_ambi + 1) + return AVERROR(EINVAL); + + return order; +} + +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in bp. + * Return a negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ + int nb_ambi_channels; + int order = ambisonic_order(channel_layout); + if (order < 0) return 0; av_bprintf(bp, "ambisonic %d", order); /* extra channels present */ - if (highest_ambi < channel_layout->nb_channels - 1) { + nb_ambi_channels = (order + 1) * (order + 1); + if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; char buf[128]; @@ -696,12 +714,12 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l const AVChannelCustom *map = channel_layout->u.map; extra.order = AV_CHANNEL_ORDER_CUSTOM; - extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; + extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); if (!extra.u.map) return AVERROR(ENOMEM); - memcpy(extra.u.map, &map[highest_ambi + 1], + memcpy(extra.u.map, &map[nb_ambi_channels], sizeof(*extra.u.map) * extra.nb_channels); } diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 4dd6614de9..294e8b0773 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -27,6 +27,7 @@ #include "version.h" #include "attributes.h" +#include "avassert.h" /** * @file From patchwork Tue Mar 15 21:18:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34787 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3356481nkb; Tue, 15 Mar 2022 14:19:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0ygbB4IWiaPBXhMMJ6GufO0tlTcHd3NIFJCbRl5cHZDJJXiS0rZ9xZjCNssbxm3gdBsp3 X-Received: by 2002:a17:906:a1c2:b0:6d6:d54d:4fb1 with SMTP id bx2-20020a170906a1c200b006d6d54d4fb1mr25865055ejb.490.1647379178017; Tue, 15 Mar 2022 14:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647379178; cv=none; d=google.com; s=arc-20160816; b=gY/KD0iIDRc2dz1TbPDJVjoxx0akta11628DO6xv4tjH16th4oOHSCLGcTDvrN+bmh Fr0y7oTmgRyDzRLRNEeuT4avynufA/E9DwKAdL80qDGKfsq+5N8Me0leh23+bU4iKKBx lyG6KgPIF6hDjRVES8+bo8UDf5ZBK2PCAwvmFWCXiUA+WPSiheSWbRZdEzIJOLpbmW2O 7rAFbHTr+lIpAcvsHttQvI59tVyCQ+ySah4EF/Gx7Nr5XHSf9JxGrMgPaBAtaEAwPU1z Z7vR7a16DSL1F8VmvXSdsZIptrr20VjpgC8Nc/OlhUJysWNR+o9ud5NpLQvIg9HGjAWa xSLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=NZ9eO6MS9+kJzfhP2vcXK2F4vc53Py/fyCPXZuS95+U=; b=NnoHCmc6C4A5aaS3WRbJBeU7OpwG1UEUa79NrDqS8ThmDfTLD9eI5PVce/TMnx5oyk DmuEHWZNxxZUg9lErhXCtkeGri7rISjSXDI0cwNQgPZYVsYzNlFh2CYntzQD/aO8Zt7D k0f7LJ50xmJSCbevco1pTN7S2Vsd54QJP1MFJGh6usIUPLDgptNwmrPqsb1Rt2JuUfUq 84WWQtroLYBxXt2hvSrjBp0Cpd8324xSepD7u6rr1HJeDHnDF4nB5/JclnS7dRTeyUiZ ZYLjbCK9Y2tps4UjDM/8X6uC305YmWTb9UZbRglFy3u+pVuMaUP+ntScv6frd2R5dvie XPhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hs35-20020a1709073ea300b006cec3e62ab8si74441ejc.459.2022.03.15.14.19.37; Tue, 15 Mar 2022 14:19:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BAF068B19A; Tue, 15 Mar 2022 23:19:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E992C68B120 for ; Tue, 15 Mar 2022 23:19:15 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4D74CE5C27; Tue, 15 Mar 2022 22:19:16 +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 zYvMiZKERjvW; Tue, 15 Mar 2022 22:19:15 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id ECA5BE4F6F; Tue, 15 Mar 2022 22:19:14 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 22:18:57 +0100 Message-Id: <20220315211858.26800-3-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220315211858.26800-1-cus@passwd.hu> References: <1382f5bd-673f-f429-0ce9-ce39c3f9b586@gmail.com> <20220315211858.26800-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VRo3tkNs4A0V Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 0069c6257b..fb1f72737f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -704,29 +704,20 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l nb_ambi_channels = (order + 1) * (order + 1); if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; - char buf[128]; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { extra.order = AV_CHANNEL_ORDER_NATIVE; extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { - const AVChannelCustom *map = channel_layout->u.map; - extra.order = AV_CHANNEL_ORDER_CUSTOM; extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; - extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); - if (!extra.u.map) - return AVERROR(ENOMEM); - - memcpy(extra.u.map, &map[nb_ambi_channels], - sizeof(*extra.u.map) * extra.nb_channels); + extra.u.map = channel_layout->u.map + nb_ambi_channels; } - av_channel_layout_describe(&extra, buf, sizeof(buf)); - av_channel_layout_uninit(&extra); - - av_bprintf(bp, "+%s", buf); + av_bprint_chars(bp, '+', 1); + av_channel_layout_describe_bprint(&extra, bp); + /* Not calling uninit here on extra because we don't own the u.map pointer */ } return 0; From patchwork Tue Mar 15 21:18:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34784 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3356546nkb; Tue, 15 Mar 2022 14:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWc79VY4qqvjcmA1SFKWvk9Eo2yjdcMoUQrMDLZRUIAzabpnii5eS89PBaW8lHJkJR6DjD X-Received: by 2002:a50:da8b:0:b0:415:a122:d7ad with SMTP id q11-20020a50da8b000000b00415a122d7admr26975702edj.123.1647379186582; Tue, 15 Mar 2022 14:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647379186; cv=none; d=google.com; s=arc-20160816; b=Yb61j3TLal9GjAfqNB4rQ/PSOZSadMnE+2smivqVT7VsbAfa+mlz/G7sghDNVtHEW1 rF9ZXKccISv5Mw49lJJKiogde86XnR/bkk3vZWW9IzLIV1GbQM6EFLrQpG/qa/qQofBJ Z1HKNK8BtFKLRbXF2uqTiJ3hxLxME8+pf7UR5UOWAh6fPOMzbtXvAyZ9Po7pFr+xtRne eoUAX1dr0W5BT0URlYqT7K2yHcCAPLDE/zmtrxaIXEQvG0I5wkCSrLwnMwGX0aFzXKMg uFa47CJ6SEBcIyG4e1XTyLHBQiF7k66cqyAMUYgWosKVqmX6ghjnaA1JB5O1oXkq6Cby Ph5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=//xjXQ6QGuHMWmpxZYB9xPo7A6pmkDhXGhqmWgOvSzU=; b=oKRasFqsl3KE0tdVvb05DKtmzayCr+yPxaw5E+hfOg/yf2IOfSYRXS3qwKwpMV230D U6bYTetXt7zzGYjxh0IQTjDpTB9PDEGikXMxQtROoG7mKLMBIkDiz6uIOk2hsy/VLrwD n/2veN94EnLIBns0bNRg79fb64EetRQg35QQVbx9j1tzML5vGOUBhBTx+2nhm2tU+vHs n75D2AnFUd7BN8+vNtPsXnjY5zLKuoN640KpSkrEMy64NO6ZbafzFrIH45Dyk3m8VYic ZcDSCowSes8pRXcDmXif9DzGeOjhPeKa/VjWs4TQj93I1oq38S3ym7D8w2jLypGPhzvT tvsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g5-20020a170906520500b006d6dbea1f24si79582ejm.570.2022.03.15.14.19.46; Tue, 15 Mar 2022 14:19:46 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3606568B1AD; Tue, 15 Mar 2022 23:19:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5082E68B180 for ; Tue, 15 Mar 2022 23:19:17 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A98E1E4F6F; Tue, 15 Mar 2022 22:19:17 +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 f8ECmjBVpOdU; Tue, 15 Mar 2022 22:19:16 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B9C24E4FAF; Tue, 15 Mar 2022 22:19:15 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 22:18:58 +0100 Message-Id: <20220315211858.26800-4-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220315211858.26800-1-cus@passwd.hu> References: <1382f5bd-673f-f429-0ce9-ce39c3f9b586@gmail.com> <20220315211858.26800-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/4] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gOOSnnJecL92 bp->len cannot be used to detect if try_describe_ambisonic was successful because the bprint buffer might contain other data as well. Also describing an invalid ambisonic layout should not return 0 but AVERROR(EINVAL) instead, so change try_describe_ambisonic to actually return error on invalid ambisonics. This also allows us to fix the first issue. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fb1f72737f..1a141d4a6a 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -689,14 +689,14 @@ static int ambisonic_order(const AVChannelLayout *channel_layout) /** * If the custom layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * Return a negative error code otherwise. */ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) { int nb_ambi_channels; int order = ambisonic_order(channel_layout); if (order < 0) - return 0; + return order; av_bprintf(bp, "ambisonic %d", order); @@ -739,8 +739,8 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, case AV_CHANNEL_ORDER_CUSTOM: if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { int res = try_describe_ambisonic(bp, channel_layout); - if (res < 0 || bp->len) - return res; + if (res >= 0) + return 0; } if (channel_layout->nb_channels) av_bprintf(bp, "%d channels (", channel_layout->nb_channels);