]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/buffersink.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / buffersink.c
index 5f2ed0e4b3896e493b7ef6e6c62b5f8e2d831d1b..c4147bf732492fd96c3604275650b43fa4a94c1d 100644 (file)
@@ -62,6 +62,29 @@ 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);
+    uint64_t counts = 0;
+    int i, lc, n;
+
+    for (i = 0; i < nb_counts; i++)
+        if (buf->channel_counts[i] < 64)
+            counts |= (uint64_t)1 << buf->channel_counts[i];
+    for (i = lc = 0; i < nb_layouts; i++) {
+        n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]);
+        if (n < 64 && (counts & ((uint64_t)1 << n)))
+            av_log(ctx, AV_LOG_WARNING,
+                   "Removing channel layout 0x%"PRIx64", redundant with %d channels\n",
+                   buf->channel_layouts[i], n);
+        else
+            buf->channel_layouts[lc++] = buf->channel_layouts[i];
+    }
+    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);
@@ -125,6 +148,7 @@ int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
     return get_frame_internal(ctx, frame, 0, nb_samples);
 }
 
+#if FF_API_BUFFERSINK_ALLOC
 AVBufferSinkParams *av_buffersink_params_alloc(void)
 {
     static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
@@ -144,6 +168,7 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void)
         return NULL;
     return params;
 }
+#endif
 
 static av_cold int common_init(AVFilterContext *ctx)
 {
@@ -251,6 +276,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;
@@ -309,7 +335,7 @@ static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
     { NULL }
 };
 
-AVFilter ff_vsink_buffer = {
+const AVFilter ff_vsink_buffer = {
     .name          = "buffersink",
     .description   = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
     .priv_size     = sizeof(BufferSinkContext),
@@ -329,7 +355,7 @@ static const AVFilterPad avfilter_asink_abuffer_inputs[] = {
     { NULL }
 };
 
-AVFilter ff_asink_abuffer = {
+const AVFilter ff_asink_abuffer = {
     .name          = "abuffersink",
     .description   = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
     .priv_class    = &abuffersink_class,