[FFmpeg-devel] [PATCH 001/281] Add a new channel layout API

Nicolas George george at nsup.org
Sun Jan 16 13:27:32 EET 2022


James Almer (12022-01-12):
> From: Anton Khirnov <anton at khirnov.net>
> 
> The new API is more extensible and allows for custom layouts.
> More accurate information is exported, eg for decoders that do not
> set a channel layout, lavc will not make one up for them.
> 
> Deprecate the old API working with just uint64_t bitmasks.
> 
> Expanded and completed by Vittorio Giovara <vittorio.giovara at gmail.com>
> and James Almer <jamrial at gmail.com>.
> Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
>  libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
>  libavutil/version.h        |   1 +
>  3 files changed, 1069 insertions(+), 103 deletions(-)

Thank you. I have no fundamental objection to the design of the API as
it is, but the user interface and documentation is still missing, that
needs to be addressed before the patch goes in.

(But IIRC, Marton had other requirements, so let us wait for him to
weigh in.)

> +/**
> + * Initialize a channel layout from a given string description.
> + * The input string can be represented by:
> + *  - the formal channel layout name (returned by av_channel_layout_describe())
> + *  - single or multiple channel names (returned by av_channel_name()
> + *    or concatenated with "+")
> + *  - a hexadecimal value of a channel layout (eg. "0x4")
> + *  - the number of channels with default layout (eg. "5c")
> + *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
> + *
> + * @param channel_layout input channel layout
> + * @param str string describing the channel layout
> + * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise
> + */
> +int av_channel_layout_from_string(AVChannelLayout *channel_layout,
> +                                  const char *str);

The documentation for the syntax needs to be in the user documentation,
with examples, not just in the API documentation.

> +/**
> + * This is the inverse function of @ref av_channel_name().
> + *
> + * @return the channel with the given name
> + *         AV_CHAN_NONE when name does not identify a known channel
> + */
> +enum AVChannel av_channel_from_string(const char *name);

> +/**
> + * Get a channel described by the given string.
> + *
> + * This function accepts channel names in the same format as
> + * @ref av_channel_from_string().
> + *
> + * @param channel_layout input channel layout
> + * @return a channel described by the given string, or a negative AVERROR value.
> + */
> +int av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
> +                                          const char *name);

This looks to be the preferred function for when the user will specify a
channel in a layout.

First, this fact should be stated clearly in the introduction of the
documentation. Otherwise, people will likely use other functions,
probably av_channel_layout_channel_from_index().

Second, the "name" argument cannot be just a name argument: the user
must be able to say "the third FC channel" or "the FC channel with name
'piano'". And probably both at once.

idx = av_channel_layout_channel_from_string(layout, "FC");
idx = av_channel_layout_channel_from_string(layout, "FC#2");
idx = av_channel_layout_channel_from_string(layout, "FC[piano]");
idx = av_channel_layout_channel_from_string(layout, "FC[piano]#2");

(I think it would be acceptable to limit the name, for example "names
with non-alphanumeric ASCII characters are not supported.)

And this need to go in the user documentation.

I am not sure if we also need a function to extract "all the FL channels
with name 'piano'".

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20220116/8c5c3676/attachment.sig>


More information about the ffmpeg-devel mailing list