]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/buffersrc.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / buffersrc.c
index 2fa9e00dafe10b0a91291bd7dc74e65f1133accd..29c01285cd2ef98a5cb4c58fdf9ad78324aed0db 100644 (file)
@@ -51,7 +51,9 @@ typedef struct BufferSourceContext {
     int               w, h;
     enum AVPixelFormat  pix_fmt;
     AVRational        pixel_aspect;
+#if FF_API_SWS_PARAM_OPTION
     char              *sws_param;
+#endif
 
     AVBufferRef *hw_frames_ctx;
 
@@ -147,33 +149,6 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *fr
     return av_buffersrc_add_frame_flags(ctx, frame, 0);
 }
 
-static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
-                                           AVFrame *frame, int flags);
-
-int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
-{
-    AVFrame *copy = NULL;
-    int ret = 0;
-
-    if (frame && frame->channel_layout &&
-        av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
-        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
-        return AVERROR(EINVAL);
-    }
-
-    if (!(flags & AV_BUFFERSRC_FLAG_KEEP_REF) || !frame)
-        return av_buffersrc_add_frame_internal(ctx, frame, flags);
-
-    if (!(copy = av_frame_alloc()))
-        return AVERROR(ENOMEM);
-    ret = av_frame_ref(copy, frame);
-    if (ret >= 0)
-        ret = av_buffersrc_add_frame_internal(ctx, copy, flags);
-
-    av_frame_free(&copy);
-    return ret;
-}
-
 static int push_frame(AVFilterGraph *graph)
 {
     int ret;
@@ -188,13 +163,18 @@ static int push_frame(AVFilterGraph *graph)
     return 0;
 }
 
-static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
-                                           AVFrame *frame, int flags)
+int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
 {
     BufferSourceContext *s = ctx->priv;
     AVFrame *copy;
     int refcounted, ret;
 
+    if (frame && frame->channel_layout &&
+        av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
+        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
+        return AVERROR(EINVAL);
+    }
+
     s->nb_failed_requests = 0;
 
     if (!frame)
@@ -227,7 +207,7 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
     if (!(copy = av_frame_alloc()))
         return AVERROR(ENOMEM);
 
-    if (refcounted) {
+    if (refcounted && !(flags & AV_BUFFERSRC_FLAG_KEEP_REF)) {
         av_frame_move_ref(copy, frame);
     } else {
         ret = av_frame_ref(copy, frame);
@@ -238,10 +218,8 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
     }
 
     ret = ff_filter_frame(ctx->outputs[0], copy);
-    if (ret < 0) {
-        av_frame_free(&copy);
+    if (ret < 0)
         return ret;
-    }
 
     if ((flags & AV_BUFFERSRC_FLAG_PUSH)) {
         ret = push_frame(ctx->graph);
@@ -271,10 +249,16 @@ static av_cold int init_video(AVFilterContext *ctx)
         return AVERROR(EINVAL);
     }
 
-    av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n",
+    av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d\n",
            c->w, c->h, av_get_pix_fmt_name(c->pix_fmt),
            c->time_base.num, c->time_base.den, c->frame_rate.num, c->frame_rate.den,
-           c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""));
+           c->pixel_aspect.num, c->pixel_aspect.den);
+
+#if FF_API_SWS_PARAM_OPTION
+    if (c->sws_param)
+        av_log(ctx, AV_LOG_WARNING, "sws_param option is deprecated and ignored\n");
+#endif
+
     return 0;
 }
 
@@ -296,7 +280,9 @@ static const AVOption buffer_options[] = {
     { "pixel_aspect",  "sample aspect ratio",    OFFSET(pixel_aspect),     AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
     { "time_base",     NULL,                     OFFSET(time_base),        AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
     { "frame_rate",    NULL,                     OFFSET(frame_rate),       AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
+#if FF_API_SWS_PARAM_OPTION
     { "sws_param",     NULL,                     OFFSET(sws_param),        AV_OPT_TYPE_STRING,                    .flags = V },
+#endif
     { NULL },
 };
 
@@ -452,7 +438,7 @@ static const AVFilterPad avfilter_vsrc_buffer_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vsrc_buffer = {
+const AVFilter ff_vsrc_buffer = {
     .name      = "buffer",
     .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them accessible to the filterchain."),
     .priv_size = sizeof(BufferSourceContext),
@@ -476,7 +462,7 @@ static const AVFilterPad avfilter_asrc_abuffer_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_asrc_abuffer = {
+const AVFilter ff_asrc_abuffer = {
     .name          = "abuffer",
     .description   = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."),
     .priv_size     = sizeof(BufferSourceContext),