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

James Almer jamrial at gmail.com
Mon Jan 17 15:32:54 EET 2022



On 1/16/2022 8:27 AM, Nicolas George wrote:
> 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.

I'll look into it.

> 
>> +/**
>> + * 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().

And they can if they want to. It has a very specific purpose and it 
fulfills it.

> 
> 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");

Please, stop asking for this. It's an incredibly niche usecase you want 
for libavfilter, so you can and should implement it there. The API is 
there and you can use it, you don't need to overdesign these general 
purpose helpers to create these bizarre scenarios just to remove one or 
two filters from your chain.

You have the opaque field in both the layout and each channel. You can 
store a pointer there to anything you want at any point in your chain, 
like an internal and refcounted lavfi struct that stores all this 
information filters in the chain can parse and use.

This is a layout of speaker positions. If you want metadata, use metadata.

> 
> (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,
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list