[FFmpeg-cvslog] vsrc_buffer: make the source accept sws_param in init

Stefano Sabatini git at videolan.org
Thu May 19 23:33:09 CEST 2011


ffmpeg | branch: master | Stefano Sabatini <stefano.sabatini-lala at poste.it> | Thu May 19 01:02:54 2011 +0200| [50764e19a8edc018b6e5276f1b3e4215ba66217f] | committer: Stefano Sabatini

vsrc_buffer: make the source accept sws_param in init

Avoid the need of two distinct av_vsrc_add_video_buffer_ref*
functions. Simplify the interface.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=50764e19a8edc018b6e5276f1b3e4215ba66217f
---

 doc/filters.texi          |   10 ++++++++--
 ffmpeg.c                  |    2 +-
 libavfilter/avfilter.h    |    2 +-
 libavfilter/vsrc_buffer.c |   33 ++++++++++++++-------------------
 libavfilter/vsrc_buffer.h |    3 ---
 5 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 523e279..1407828 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -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:
- at var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
+ at 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.
+
+ at 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:
diff --git a/ffmpeg.c b/ffmpeg.c
index d4c7705..182f929 100644
--- 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);
                 }
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 171c9e4..a0ad358 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -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, \
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index effc232..9815f94 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -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;
 }
 
diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h
index eb9ec56..34fec0e 100644
--- a/libavfilter/vsrc_buffer.h
+++ b/libavfilter/vsrc_buffer.h
@@ -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 */



More information about the ffmpeg-cvslog mailing list