diff mbox series

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

Message ID 20200814093434.94564-1-george@nsup.org
State Accepted
Headers show
Series [FFmpeg-devel,1/4] lavfi/buffersink: remove redundant channel layouts. | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Nicolas George Aug. 14, 2020, 9:34 a.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/buffersink.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Paul B Mahol Aug. 19, 2020, 6:34 p.m. UTC | #1
On 8/14/20, Nicolas George <george@nsup.org> wrote:
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavfilter/buffersink.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>

How they are currently redundant?

Sorry, its not obvious to me from code.

> 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;
> +        if (c < nb_counts)
> +            av_log(ctx, AV_LOG_WARNING,
> +                   "Removing channel layout 0x%"PRIx64", redundant with %d
> channels\n",
> +                   buf->channel_layouts[l], buf->channel_counts[c]);
> +        else
> +            buf->channel_layouts[lc++] = buf->channel_layouts[l];
> +    }
> +    buf->channel_layouts_size = lc * sizeof(*buf->channel_layouts);
> +}
> +
>  int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx,
> AVFrame *frame)
>  {
>      return av_buffersink_get_frame_flags(ctx, frame, 0);
> @@ -253,6 +275,7 @@ static int asink_query_formats(AVFilterContext *ctx)
>
>      if (buf->channel_layouts_size || buf->channel_counts_size ||
>          buf->all_channel_counts) {
> +        cleanup_redundant_layouts(ctx);
>          for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
>              if ((ret = ff_add_channel_layout(&layouts,
> buf->channel_layouts[i])) < 0)
>                  return ret;
> --
> 2.28.0
>
> _______________________________________________
> 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".
diff mbox series

Patch

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;
+        if (c < nb_counts)
+            av_log(ctx, AV_LOG_WARNING,
+                   "Removing channel layout 0x%"PRIx64", redundant with %d channels\n",
+                   buf->channel_layouts[l], buf->channel_counts[c]);
+        else
+            buf->channel_layouts[lc++] = buf->channel_layouts[l];
+    }
+    buf->channel_layouts_size = lc * sizeof(*buf->channel_layouts);
+}
+
 int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
 {
     return av_buffersink_get_frame_flags(ctx, frame, 0);
@@ -253,6 +275,7 @@  static int asink_query_formats(AVFilterContext *ctx)
 
     if (buf->channel_layouts_size || buf->channel_counts_size ||
         buf->all_channel_counts) {
+        cleanup_redundant_layouts(ctx);
         for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
             if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0)
                 return ret;