From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 2/4] avutil/channel_layout: factorize ambisonic order detection
Date: Tue, 15 Mar 2022 17:49:15 -0300
Message-ID: <54861f63-4268-fac4-54ea-e34b902b00d9@gmail.com> (raw)
In-Reply-To: <20220315203013.14304-2-cus@passwd.hu>
On 3/15/2022 5:30 PM, Marton Balint wrote:
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> 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".
next prev parent reply other threads:[~2022-03-15 20:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 20:30 [FFmpeg-devel] [PATCH 1/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint Marton Balint
2022-03-15 20:30 ` [FFmpeg-devel] [PATCH 2/4] avutil/channel_layout: factorize ambisonic order detection Marton Balint
2022-03-15 20:49 ` James Almer [this message]
2022-03-15 20:30 ` [FFmpeg-devel] [PATCH 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout Marton Balint
2022-03-15 20:39 ` James Almer
2022-03-15 20:30 ` [FFmpeg-devel] [PATCH 4/4] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels Marton Balint
2022-03-15 20:42 ` James Almer
2022-03-15 20:44 ` [FFmpeg-devel] [PATCH 1/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint James Almer
2022-03-15 21:18 ` [FFmpeg-devel] [PATCH v2 " Marton Balint
2022-03-15 21:18 ` [FFmpeg-devel] [PATCH v2 2/4] avutil/channel_layout: factorize ambisonic order detection Marton Balint
2022-03-15 21:24 ` James Almer
2022-03-15 21:31 ` Marton Balint
2022-03-15 21:18 ` [FFmpeg-devel] [PATCH v2 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout Marton Balint
2022-03-15 21:26 ` James Almer
2022-03-15 22:28 ` Marton Balint
2022-03-15 21:18 ` [FFmpeg-devel] [PATCH v2 4/4] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels Marton Balint
2022-03-15 21:28 ` James Almer
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=54861f63-4268-fac4-54ea-e34b902b00d9@gmail.com \
--to=jamrial@gmail.com \
--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