[FFmpeg-devel] [PATCH 1/5] vsrc_buffer: allow to set the return value.

Nicolas George nicolas.george at normalesup.org
Thu Mar 8 14:49:14 CET 2012


The default return value is also changed
from AVERROR(EINVAL) to AVERROR(EAGAIN).

FIXME before pushing, add APIChanges entry and minor bump.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vsrc_buffer.c |   15 ++++++++++-----
 libavfilter/vsrc_buffer.h |    6 ++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index 743698e..dee06e5 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -36,6 +36,7 @@ typedef struct {
     enum PixelFormat  pix_fmt;
     AVRational        time_base;     ///< time_base to set in the output link
     AVRational        sample_aspect_ratio;
+    int               return_value;
     char              sws_param[256];
 } BufferSourceContext;
 
@@ -119,6 +120,12 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
     return 0;
 }
 
+void av_vsrc_buffer_set_return_value(AVFilterContext *buffer_src, int rv)
+{
+    BufferSourceContext *c = buffer_src->priv;
+    c->return_value = rv;
+}
+
 int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
 {
     BufferSourceContext *c = s->priv;
@@ -164,6 +171,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     int ret, n = 0;
     *c->sws_param = 0;
 
+    c->return_value = AVERROR(EAGAIN);
     if (!args ||
         (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,
@@ -215,11 +223,8 @@ static int request_frame(AVFilterLink *link)
 {
     BufferSourceContext *c = link->src->priv;
 
-    if (!c->picref) {
-        av_log(link->src, AV_LOG_WARNING,
-               "request_frame() called with no available frame!\n");
-        return AVERROR(EINVAL);
-    }
+    if (!c->picref)
+        return c->return_value;
 
     avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0));
     avfilter_draw_slice(link, 0, link->h, 1);
diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h
index b661d41..177e5a5 100644
--- a/libavfilter/vsrc_buffer.h
+++ b/libavfilter/vsrc_buffer.h
@@ -46,4 +46,10 @@
 int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src,
                                         AVFilterBufferRef *picref, int flags);
 
+/**
+ * Set the value returned when a frame is requested and none is available.
+ * The default is AVERROR(EAGAIN); AVERROR_EOF is a likely value.
+ */
+void av_vsrc_buffer_set_return_value(AVFilterContext *buffer_src, int rv);
+
 #endif /* AVFILTER_VSRC_BUFFER_H */
-- 
1.7.9.1



More information about the ffmpeg-devel mailing list