]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vsrc_buffer.c
get_buffers: Check that pix_fmt is not NONE.
[ffmpeg] / libavfilter / vsrc_buffer.c
index 3c0936a68cf61dbbe41f55a7c4c6e5c779ef0beb..743698eff952752f07469dc5ac00da12fc71cfaf 100644 (file)
@@ -26,6 +26,7 @@
 #include "avfilter.h"
 #include "internal.h"
 #include "avcodec.h"
+#include "buffersrc.h"
 #include "vsrc_buffer.h"
 #include "libavutil/imgutils.h"
 
@@ -38,6 +39,12 @@ typedef struct {
     char              sws_param[256];
 } BufferSourceContext;
 
+#define CHECK_PARAM_CHANGE(s, c, width, height, format)\
+    if (c->w != width || c->h != height || c->pix_fmt != format) {\
+        av_log(s, AV_LOG_ERROR, "Changing frame properties on the fly is not supported.\n");\
+        return AVERROR(EINVAL);\
+    }
+
 int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
                                         AVFilterBufferRef *picref, int flags)
 {
@@ -112,6 +119,25 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
     return 0;
 }
 
+int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
+{
+    BufferSourceContext *c = s->priv;
+
+    if (c->picref) {
+        av_log(s, AV_LOG_ERROR,
+               "Buffering several frames is not supported. "
+               "Please consume all available frames before adding a new one.\n"
+            );
+        return AVERROR(EINVAL);
+    }
+
+//     CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format);
+
+    c->picref = buf;
+
+    return 0;
+}
+
 #if CONFIG_AVCODEC
 #include "avcodec.h"
 
@@ -156,6 +182,14 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     return 0;
 }
 
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    BufferSourceContext *s = ctx->priv;
+    if (s->picref)
+        avfilter_unref_buffer(s->picref);
+    s->picref = NULL;
+}
+
 static int query_formats(AVFilterContext *ctx)
 {
     BufferSourceContext *c = ctx->priv;
@@ -199,7 +233,7 @@ static int request_frame(AVFilterLink *link)
 static int poll_frame(AVFilterLink *link)
 {
     BufferSourceContext *c = link->src->priv;
-    return !!(c->picref);
+    return !!c->picref;
 }
 
 AVFilter avfilter_vsrc_buffer = {
@@ -209,6 +243,7 @@ AVFilter avfilter_vsrc_buffer = {
     .query_formats = query_formats,
 
     .init      = init,
+    .uninit    = uninit,
 
     .inputs    = (const AVFilterPad[]) {{ .name = NULL }},
     .outputs   = (const AVFilterPad[]) {{ .name      = "default",