[FFmpeg-devel] [PATCH 4/4] lavfi/buffersink: remove redundant channel layouts.

Michael Niedermayer michael at niedermayer.cc
Fri Aug 21 09:08:54 EEST 2020


On Thu, Aug 20, 2020 at 04:50:05PM +0200, Nicolas George wrote:
> The channel_layouts and channel_counts options set what buffersink
> is supposed to accept. If channel_counts contains 2, then stereo is
> already accepted, there is no point in having it in channel_layouts
> too. This was not properly documented until now, so only print a
> warning.
> 
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
>  libavfilter/buffersink.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> 
> Added an explanation requested by Paul.
> 
> 
> diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
> index 76a46f6678..c58daf6124 100644
> --- a/libavfilter/buffersink.c
> +++ b/libavfilter/buffersink.c
> @@ -62,6 +62,28 @@ typedef struct BufferSinkContext {
>  
>  #define NB_ITEMS(list) (list ## _size / sizeof(*list))
>  
> +static void cleanup_redundant_layouts(AVFilterContext *ctx)
> +{
> +    BufferSinkContext *buf = ctx->priv;
> +    int nb_layouts = NB_ITEMS(buf->channel_layouts);
> +    int nb_counts = NB_ITEMS(buf->channel_counts);
> +    int l, lc, c, n;
> +
> +    for (l = lc = 0; l < nb_layouts; l++) {
> +        n = av_get_channel_layout_nb_channels(buf->channel_layouts[l]);
> +        for (c = 0; c < nb_counts; c++)
> +            if (n == buf->channel_counts[c])
> +                break;

this would be O(nb_layouts * nb_counts) but can be done in
O(nb_layouts + nb_counts) as in

for (c = 0; c < nb_counts; c++)
    has_channel_count[ buf->channel_counts[c] ] = 1;

for (l = lc = 0; l < nb_layouts; l++) {
    n = av_get_channel_layout_nb_channels(buf->channel_layouts[l]);
    if (has_channel_count[ n ])
        break;

not sure this is faster or how much it is in practice or how much that matters
but its asymptotically better and its simple

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200821/db4c27ca/attachment.sig>


More information about the ffmpeg-devel mailing list