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 25CA942404 for ; Tue, 15 Mar 2022 20:49:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 48C1668B13B; Tue, 15 Mar 2022 22:49:25 +0200 (EET) Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1ADAB68B080 for ; Tue, 15 Mar 2022 22:49:19 +0200 (EET) Received: by mail-ot1-f50.google.com with SMTP id d15-20020a05683018ef00b005b2304fdeecso140655otf.1 for ; Tue, 15 Mar 2022 13:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=7+n2K7woGOGm9u7eVubJoDjhndBI8KT4QRsGewEfAkQ=; b=VQN6ZCPqli181gaPo9UW3jJCosbhX1jy7Sw1yXrsCPzeSJ5DC16z8EOdc9S2lwBc/D ZUVgZp2ChzZQ/C0tQbMLGWzheyoaj3jAS0II/8Q8+8z9I8qeGbHLq/DYWxDaTSRBild+ /EwYkJEcFspuVp6j5DcDbhLnlyRhtAtJAegjSLHnkklG4Jr9JfSvW0Y8d89vF419wjDB 35ynz6uyC2gN8Jd8RjBIrAiQZCj8WExhWhd1nlnVXjRiYybtChgYaV/ur9JtQQ5KVg9B EqFBGaSNnttcO9K9asq+cou5Ouv/zMLxwfk2J7rLqZHsCLx0XuGS1GxdOKZa+b0a28Ac hKzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=7+n2K7woGOGm9u7eVubJoDjhndBI8KT4QRsGewEfAkQ=; b=8HCtQB1T92bXLQI14DTxNE8D5J1YRjo2TBW4iVcE463osiY3UwGNiCFvVtXhjQvBtw bJhPuMMPLGb+m+U1pnhOklMRbo0AFd/pCVEMq/zr/Lv/bLLT/+RB62QuxCywouRlyihT NvVv54kUsPbIfNilU/fXwkJ8xRak8Ct+7bOJ6AZlNX8ZwCiVIHGhXb4orzuB2pqidTs+ JLa/pyFBoE8GU7Gi81pDsQQ/nf7EctntxE2XGBF2PmoCSKr34k1lD3xUUaQXoif/km2a D/ws6k0iHEu7PlxZvVGcuKz27l/tLS4VjtLfGnUdgt1kzU+ftqQOMmOYcQdMzVu4b37n lfAQ== X-Gm-Message-State: AOAM531KL6HgMdgkhKK7QpIQuiusiXjfkxLN2gIXyqDSYzzLonNoaIA0 oatogudrRqzXwDrO27GQn9vHsFQ7PUJu7g== X-Google-Smtp-Source: ABdhPJylaw8+7BMDki4Jlh9nK+0CdDDTw6t+zsKIW1yKVLM6Vcemw3FBrZpnUuqu2ClAUKeIfpAvCA== X-Received: by 2002:a9d:8:0:b0:5b2:236c:b6d5 with SMTP id 8-20020a9d0008000000b005b2236cb6d5mr13284074ota.355.1647377357149; Tue, 15 Mar 2022 13:49:17 -0700 (PDT) Received: from [192.168.0.13] ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id y15-20020a056870b00f00b000d75f1d9b81sm8368713oae.46.2022.03.15.13.49.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Mar 2022 13:49:16 -0700 (PDT) Message-ID: <54861f63-4268-fac4-54ea-e34b902b00d9@gmail.com> Date: Tue, 15 Mar 2022 17:49:15 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220315203013.14304-1-cus@passwd.hu> <20220315203013.14304-2-cus@passwd.hu> From: James Almer In-Reply-To: <20220315203013.14304-2-cus@passwd.hu> Subject: Re: [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 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 3/15/2022 5:30 PM, Marton Balint wrote: > 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) { It's not called for any other order, so this is not needed. Maybe add an av_assert0() instead. > 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); > } Should be ok. _______________________________________________ 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".