From patchwork Tue Mar 15 20:30:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34780 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3327869nkb; Tue, 15 Mar 2022 13:30:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuNbv/Qf1SlSRvoEq8lGxsQ7aw3NgM0WnEhuDAHVz2saXEr4UcuWSUiVgYfaXvRs1TNUkY X-Received: by 2002:a17:906:5011:b0:6cf:82ff:f1bf with SMTP id s17-20020a170906501100b006cf82fff1bfmr24309715ejj.69.1647376232732; Tue, 15 Mar 2022 13:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647376232; cv=none; d=google.com; s=arc-20160816; b=bOd4Xf8h76s2W05hicDfLcqdJ+y2EMc9w9K1QZqTgxYXmiGNf84JBTVH5HMYt5+TR2 6kWarA8p71Eit3aMwRxLVLBHfXtjLPIzkQLgxZpUWq/ZNLGE3ifocHEBS+VA0bu840ZL VWFplVsNjCHffuQ/+pmlCiDsf6H9EbFhn5b+ShZA3tk9Sb91BWEg09AWuP482+ogl62O 905nmcIIn9f+tJ2JOv6OCZ+5+DGUHf0KgfXa9kNN7dRcBlRDqXJYy+/4/vIEi1RhLo0Z WtQlebvz2oPglUwo5OiQmNe67JkM/Gsx3CQ05oEdGo2zVDjok2z+ZKc4mTHJmKHkEfn5 8xmg== 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:message-id:date:to:from :delivered-to; bh=vvst9EgM6Y2HmZVBuRJELN2DVBIaqbYXvyTV18RBAz8=; b=H4i0GRcsQFMHSAIAuUispuvOuMjaiPMT2rkc5vd16VD+eWH9XQ7DwXurJ9ZzKL5xho ppAwnPFWTBuwFt//NF2nMEcoC9S8fipQP+43+zPBLx1EIiI1tA/Z3lXN3P2MrH5bSO99 4CTsLvyt6iMLLIsrkWEFBNd2fCF0HIOVPwNyrp9RRTmsU9QME/xlhMeVsNJpppABQMqk l1nyuVkh57iblfMt7GyeVEjls0Aj7w+bNibCYZ8Ve5/Wx1p2CgzsRvHYxGrzgwrZvG9b JWvYQ8ZUO98Y6ShNhuPHH13L43UeV5U4/pYWHxnGcoqTZCsUxFins6EAcBsFSRRraqUd tu4g== 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 n19-20020a17090625d300b006d16268ca7dsi10837578ejb.804.2022.03.15.13.30.32; Tue, 15 Mar 2022 13:30:32 -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 8BE1968B0BE; Tue, 15 Mar 2022 22:30:28 +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 8EC7268A441 for ; Tue, 15 Mar 2022 22:30:22 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B693CE5B6A; Tue, 15 Mar 2022 21:30:21 +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 bHnCHZp62DzN; Tue, 15 Mar 2022 21:30:19 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8DD01E134B; Tue, 15 Mar 2022 21:30:19 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 21:30:10 +0100 Message-Id: <20220315203013.14304-1-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: uS/7v9gvN+t6 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 20:30:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34779 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3327953nkb; Tue, 15 Mar 2022 13:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8DIZclU+X5kDx3JxzLIGEOuv6rASHC/FlSV9/kWAiAek8y98HwEU1pvgLS9S/7JAbNwNV X-Received: by 2002:a05:6402:1c02:b0:415:f555:38ba with SMTP id ck2-20020a0564021c0200b00415f55538bamr26757766edb.357.1647376241367; Tue, 15 Mar 2022 13:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647376241; cv=none; d=google.com; s=arc-20160816; b=pQW2OFhS/Wz9mFY4xF5a9rrqZi3IPK3DdBqdbTJlooLQXzcZRaDMCXut3r7etqaZN6 Rtg3LpkxUV37eOvyRXKjIGg6zSBS8baiOi9yeqdxqKzgKHk9bLSHKHS4eGp4LbzNGgLp px2k3pfSDLEM8aw7axJRhZMdfeVn+vdKAb3bcBCRBLkk/pC1MVfKIaGy59BR1s/QhyDJ Fkp+v/lYw+qPXsUg8HOkIix0bX6dyiS2cM19+ywZHDVZP1qEClEM2J+OuedaEZ3V9I9z IlyGAJBAqJIsux2daTV4EnuVbBInvRY7rt5iXq/0yA9Tn2HkbPYF2rJBpP9MVHffBTjB wJ0g== 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=w7nBufnz6Q55y/fhC26pGnAEjHJ+I6gwsKM/rsF+vK4=; b=gvhrNRO/t+PtMrSopFsY1ZBD8GwSk2OqBSRlOl7H8G6cRTB3QZzgb/7vWQgELSvmN0 frB5Q8GT7bunlcTs9i/OYKByYweDB6HtaEwNsbJ6k87IYzW5lgvz9tUZ22EHM59AH/4v 9R6h+sreMqp30icavwPEM1CUlW2Hzo+VbgUcGc5crc67OILrhLPwusjE/i+glwx96IGO tRCL6Iay+wPDxJtJAICEc8lxZi1lJt9osrnEIGtEPbANttGq5Y3NB0TS1HMHN1gSflqA ZHPP16dUa+h3CPAB978pUt3TvxKASmXwCtuMTnYQEPqNdhNSjSvPl/3shpoDqwhE43gl TvpA== 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 w8-20020a056402268800b0041660c6921bsi82163edd.98.2022.03.15.13.30.40; Tue, 15 Mar 2022 13:30:41 -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 954F968B080; Tue, 15 Mar 2022 22:30:31 +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 4638368B0BE for ; Tue, 15 Mar 2022 22:30:23 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A38B9E4F6F; Tue, 15 Mar 2022 21:30:23 +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 CIdYOvytdCBm; Tue, 15 Mar 2022 21:30:21 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6FCBFE4DF2; Tue, 15 Mar 2022 21:30:21 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 21:30:11 +0100 Message-Id: <20220315203013.14304-2-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220315203013.14304-1-cus@passwd.hu> References: <20220315203013.14304-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: NxvWGDUvHK2f Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 40 ++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..fb2335a334 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,29 @@ 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 if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { const AVChannelCustom *map = channel_layout->u.map; 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 +674,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 +712,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); } From patchwork Tue Mar 15 20:30:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34781 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3328064nkb; Tue, 15 Mar 2022 13:30:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvCoq7ARylN2q6sU+NU35ghJrgu7Gwq6YfJunSO3ih0AgSw+Bo7rjbYxWIALIWL7SO80T2 X-Received: by 2002:a05:6402:430c:b0:416:c695:7c23 with SMTP id m12-20020a056402430c00b00416c6957c23mr23044492edc.367.1647376250131; Tue, 15 Mar 2022 13:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647376250; cv=none; d=google.com; s=arc-20160816; b=um46V7KnfWZqC3anKihEyhOJRuzsiR7ja+CPx/mNkbToXUMmA0tG8hs/rRpOCyREEo pvDpgPIepzgcXDkAR9sMQwuuhjkDfNvoilAoFnaYk8yRfo6BwTBYk3hf73UkBU7N0vGV ArT9cPzMRrHeM2jHTUWuirLG3d/CPjRWOz4cemBIhHM6bnMo0JAUqB7B0L7qiqmRxwjF zVyWbDqSaMLseJUyuo8rksMVjAjnrzrrxbahN1+s4+EspUM5oQtTMlXKkYyEUsnXkivc cRPv/75QjjWrYSfjTlqvJJLCZYzU+yV2PLjpbL3HZmMiAY6pYrl0msJJOat164BX71Uu CCvw== 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=ZpZo0iNrypL25HZMMcAvKz7EArZkfC9JCzxD9OUVChM=; b=oMd7rFo28mzaevD0ehyP0BgxcHwodgO9uJk6Zz00CzLDXTvdT0U8UiPIzINR6DL00I cG7YteB3eI9dIC3EJf8tcGIGQ686Id3zDeRkKr83rOhDfna7uABZixStfloP2eTuL+zz aE/Dg1Zf0u+zgQ2k40iL+Cl0SDgJrkU5LOYWkRDLbXH/ZZv2z0dqnEJ+MsMbrzpDc44c bNBs2FygnZdL7ojE1jYOSZH2iECgdpD5nSW+RmsfSgIoDqafc4otADdDTA7gvHcc1mcs 8AWW79mBbNt777LWc+9aMyvFpPjvcfthb9l++fcpZsAE7gL06V9yw2oWItWkW9Om3tHv js8w== 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 c4-20020a170906924400b006df69626abfsi22426ejx.75.2022.03.15.13.30.49; Tue, 15 Mar 2022 13:30:50 -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 47DAA68B143; Tue, 15 Mar 2022 22:30:33 +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 A518568B0FB for ; Tue, 15 Mar 2022 22:30:23 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 08273E4DF2; Tue, 15 Mar 2022 21:30:24 +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 I4mP-lMsEjb5; Tue, 15 Mar 2022 21:30:22 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D11ECE5C3D; Tue, 15 Mar 2022 21:30:22 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 21:30:12 +0100 Message-Id: <20220315203013.14304-3-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220315203013.14304-1-cus@passwd.hu> References: <20220315203013.14304-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: gS9dN/Ylrm8h Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fb2335a334..8406089fe0 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -702,29 +702,19 @@ 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); } return 0; From patchwork Tue Mar 15 20:30:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 34782 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp3328186nkb; Tue, 15 Mar 2022 13:31:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw62K9K2HKYalSajMOE8M9bN5XUD30+3gvQ1i7xSBPFa4XFA6XG5vKF+Uis0ykUILMYU2nf X-Received: by 2002:a17:906:4fd0:b0:6db:2639:6640 with SMTP id i16-20020a1709064fd000b006db26396640mr23711804ejw.313.1647376260289; Tue, 15 Mar 2022 13:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647376260; cv=none; d=google.com; s=arc-20160816; b=mQLLqOh/RoD/KUQB6cdEl50kUZlczI+XdapMJNG4IFFihGTJTxdAmVs6nIojEWPdZp 5/l5izpwAI5EuDqXbfwEl28Ztv+RXT3pMiFxhod4JfsoFoY38Bj6SO1Zhz+z7LEkYHS+ iehm0ei548rDJ8AVvcki+9QoiKeQzv+Z0Xoc4tGtnDy6qB7tCUDqjsJ7yn81NUT3XkPj 27kcRPACSw192um5HYxuj3SNitvY/qjvD1rWzTNBLd4C6OmF2gEY+HRAE8zzlQPgl+Yj koXqDo6I+tUaT1qCYcapgoq/l21T13f854NdSgpkeeXXiEvcb+GDd1mRlqlQXiRZgyKQ 90SA== 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=NazXnc2y/B8VWsWNoguUZRZr3fczrO0zbJcDrgVGatA=; b=kAhgWssil5+GBhzXsHwjHTXxjiZMPLZhR5YFmWDl71lwnNvif/wyWEsCB7HjsxzSdA Gdi5/gpZKlZoAeqeWkSVeKuMhC/XOlxxctSMqZJLHchpB1xyUbFw5VhvqYIKcvqQgSru tH6mGESLyqbI78rM+GI8EQMozI/peCBIFQKNRRn1G0BY/t30PYdcgNAxmLWQEd30Wawb ONrUQOcQLej3qkLIV1WIj+6klaNznno+4X8fIbge1lTK54vgm5G1KKbvlXi+xMrBywPK vuCWn/U5oOzUBNGKxSWutg/0lUEH3GIR0QSTysB69JOBLaWnOmwAUuhhVDpWV1/6oAda jBdA== 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 l9-20020a056402254900b004167de7ce21si55767edb.363.2022.03.15.13.30.59; Tue, 15 Mar 2022 13:31:00 -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 3877A68012B; Tue, 15 Mar 2022 22:30:41 +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 5ED7268B168 for ; Tue, 15 Mar 2022 22:30:33 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BF8BFE4DF2; Tue, 15 Mar 2022 21:30:33 +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 7EyS8f3gjL05; Tue, 15 Mar 2022 21:30:32 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 24E10E134B; Tue, 15 Mar 2022 21:30:32 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Mar 2022 21:30:13 +0100 Message-Id: <20220315203013.14304-4-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220315203013.14304-1-cus@passwd.hu> References: <20220315203013.14304-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: 1UXUOd9FlpSc 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8406089fe0..be511dcf68 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -687,14 +687,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); @@ -736,7 +736,7 @@ 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) + if (res >= 0) return res; } if (channel_layout->nb_channels)