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 <geo...@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.

Attachment: signature.asc
Description: PGP signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to