vsrc_buffer: make the source accept sws_param in init
authorStefano Sabatini <stefano.sabatini-lala@poste.it>
Wed, 18 May 2011 23:02:54 +0000 (01:02 +0200)
committerStefano Sabatini <stefano.sabatini-lala@poste.it>
Thu, 19 May 2011 21:15:33 +0000 (23:15 +0200)
Avoid the need of two distinct av_vsrc_add_video_buffer_ref*
functions. Simplify the interface.

doc/filters.texi
ffmpeg.c
libavfilter/avfilter.h
libavfilter/vsrc_buffer.c
libavfilter/vsrc_buffer.h

index 523e279..1407828 100644 (file)
@@ -1536,9 +1536,10 @@ This source is mainly intended for a programmatic use, in particular
 through the interface defined in @file{libavfilter/vsrc_buffer.h}.
 
 It accepts the following parameters:
-@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
+@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}:@var{scale_params}
 
-All the parameters need to be explicitely defined.
+All the parameters but @var{scale_params} need to be explicitely
+defined.
 
 Follows the list of the accepted parameters.
 
@@ -1559,6 +1560,11 @@ timestamps of the buffered frames.
 @item sample_aspect_ratio.num, sample_aspect_ratio.den
 Specify numerator and denominator of the sample aspect ratio assumed
 by the video frames.
+
+@item scale_params
+Specify the optional parameters to be used for the scale filter which
+is automatically inserted when an input change is detected in the
+input size or format.
 @end table
 
 For example:
index d4c7705..182f929 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1652,7 +1652,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
 
                     picref =
                         avfilter_get_video_buffer_ref_from_frame(&picture, AV_PERM_WRITE);
-                    av_vsrc_buffer_add_video_buffer_ref(ost->input_video_filter, picref, ""); //TODO user setable params
+                    av_vsrc_buffer_add_video_buffer_ref(ost->input_video_filter, picref);
                     picref->buf->data[0] = NULL;
                     avfilter_unref_buffer(picref);
                 }
index 171c9e4..a0ad358 100644 (file)
@@ -26,7 +26,7 @@
 #include "libavutil/samplefmt.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  2
-#define LIBAVFILTER_VERSION_MINOR  6
+#define LIBAVFILTER_VERSION_MINOR  7
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
index effc232..9815f94 100644 (file)
@@ -37,8 +37,7 @@ typedef struct {
     char              sws_param[256];
 } BufferSourceContext;
 
-int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref,
-                                         const char *sws_param)
+int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref)
 {
     BufferSourceContext *c = buffer_filter->priv;
     AVFilterLink *outlink = buffer_filter->outputs[0];
@@ -52,13 +51,10 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
         //return -1;
     }
 
-    if (!c->sws_param[0]) {
-        snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param);
-    }
-
     if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
         AVFilterContext *scale = buffer_filter->outputs[0]->dst;
         AVFilterLink *link;
+        char scale_param[1024];
 
         av_log(buffer_filter, AV_LOG_INFO,
                "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
@@ -72,7 +68,8 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
             if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0)
                 return ret;
 
-            if ((ret = avfilter_init_filter(scale, c->sws_param, NULL)) < 0) {
+            snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", c->w, c->h, c->sws_param);
+            if ((ret = avfilter_init_filter(scale, scale_param, NULL)) < 0) {
                 avfilter_free(scale);
                 return ret;
             }
@@ -85,8 +82,9 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
 
             scale->outputs[0]->format= c->pix_fmt;
         } else if (!strcmp(scale->filter->name, "scale")) {
-            snprintf(c->sws_param, 255, "%d:%d:%s", scale->outputs[0]->w, scale->outputs[0]->h, sws_param);
-            scale->filter->init(scale, c->sws_param, NULL);
+            snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s",
+                     scale->outputs[0]->w, scale->outputs[0]->h, c->sws_param);
+            scale->filter->init(scale, scale_param, NULL);
         }
 
         c->pix_fmt = scale->inputs[0]->format = picref->format;
@@ -108,24 +106,21 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
     return 0;
 }
 
-int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref)
-{
-    return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, "");
-}
-
 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
 {
     BufferSourceContext *c = ctx->priv;
     char pix_fmt_str[128];
     int n = 0;
+    *c->sws_param = 0;
 
     if (!args ||
-        (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str,
+        (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str,
                     &c->time_base.num, &c->time_base.den,
-                    &c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den)) != 7) {
-        av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args);
+                    &c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den, c->sws_param)) < 7) {
+        av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args);
         return AVERROR(EINVAL);
     }
+
     if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
         char *tail;
         c->pix_fmt = strtol(pix_fmt_str, &tail, 10);
@@ -135,10 +130,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
         }
     }
 
-    av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d\n",
+    av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n",
            c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
            c->time_base.num, c->time_base.den,
-           c->sample_aspect_ratio.num, c->sample_aspect_ratio.den);
+           c->sample_aspect_ratio.num, c->sample_aspect_ratio.den, c->sws_param);
     return 0;
 }
 
index eb9ec56..34fec0e 100644 (file)
@@ -31,7 +31,4 @@
 
 int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref);
 
-int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref,
-                                         const char *sws_param);
-
 #endif /* AVFILTER_VSRC_BUFFER_H */