lavfi: check all ff_start_frame/draw_slice/end_frame calls for errors
[ffmpeg.git] / libavfilter / buffersrc.c
index ca9390a..2aa7d7d 100644 (file)
@@ -27,7 +27,8 @@
 #include "avfilter.h"
 #include "buffersrc.h"
 #include "formats.h"
-#include "vsrc_buffer.h"
+#include "internal.h"
+#include "video.h"
 
 #include "libavutil/audioconvert.h"
 #include "libavutil/fifo.h"
@@ -68,25 +69,6 @@ typedef struct {
         return AVERROR(EINVAL);\
     }
 
-#if FF_API_VSRC_BUFFER_ADD_FRAME
-int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
-                             int64_t pts, AVRational pixel_aspect)
-{
-    int64_t orig_pts = frame->pts;
-    AVRational orig_sar = frame->sample_aspect_ratio;
-    int ret;
-
-    frame->pts = pts;
-    frame->sample_aspect_ratio = pixel_aspect;
-    if ((ret = av_buffersrc_write_frame(buffer_filter, frame)) < 0)
-        return ret;
-    frame->pts = orig_pts;
-    frame->sample_aspect_ratio = orig_sar;
-
-    return 0;
-}
-#endif
-
 int av_buffersrc_write_frame(AVFilterContext *buffer_filter, AVFrame *frame)
 {
     BufferSourceContext *c = buffer_filter->priv;
@@ -108,8 +90,8 @@ int av_buffersrc_write_frame(AVFilterContext *buffer_filter, AVFrame *frame)
     case AVMEDIA_TYPE_VIDEO:
         CHECK_VIDEO_PARAM_CHANGE(buffer_filter, c, frame->width, frame->height,
                                  frame->format);
-        buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE,
-                                        c->w, c->h);
+        buf = ff_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE,
+                                  c->w, c->h);
         av_image_copy(buf->data, buf->linesize, frame->data, frame->linesize,
                       c->pix_fmt, c->w, c->h);
         break;
@@ -171,7 +153,7 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
     return 0;
 }
 
-static av_cold int init_video(AVFilterContext *ctx, const char *args, void *opaque)
+static av_cold int init_video(AVFilterContext *ctx, const char *args)
 {
     BufferSourceContext *c = ctx->priv;
     char pix_fmt_str[128];
@@ -196,7 +178,7 @@ static av_cold int init_video(AVFilterContext *ctx, const char *args, void *opaq
     if (!(c->fifo = av_fifo_alloc(sizeof(AVFilterBufferRef*))))
         return AVERROR(ENOMEM);
 
-    av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name);
+    av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name);
     return 0;
 }
 
@@ -217,7 +199,7 @@ static const AVClass abuffer_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-static av_cold int init_audio(AVFilterContext *ctx, const char *args, void *opaque)
+static av_cold int init_audio(AVFilterContext *ctx, const char *args)
 {
     BufferSourceContext *s = ctx->priv;
     int ret = 0;
@@ -284,14 +266,14 @@ static int query_formats(AVFilterContext *ctx)
 
     switch (ctx->outputs[0]->type) {
     case AVMEDIA_TYPE_VIDEO:
-        avfilter_add_format(&formats, c->pix_fmt);
-        avfilter_set_common_formats(ctx, formats);
+        ff_add_format(&formats, c->pix_fmt);
+        ff_set_common_formats(ctx, formats);
         break;
     case AVMEDIA_TYPE_AUDIO:
-        avfilter_add_format(&formats,           c->sample_fmt);
-        avfilter_set_common_formats(ctx, formats);
+        ff_add_format(&formats,           c->sample_fmt);
+        ff_set_common_formats(ctx, formats);
 
-        avfilter_add_format(&samplerates,       c->sample_rate);
+        ff_add_format(&samplerates,       c->sample_rate);
         ff_set_common_samplerates(ctx, samplerates);
 
         ff_add_channel_layout(&channel_layouts, c->channel_layout);
@@ -330,6 +312,7 @@ static int request_frame(AVFilterLink *link)
 {
     BufferSourceContext *c = link->src->priv;
     AVFilterBufferRef *buf;
+    int ret = 0;
 
     if (!av_fifo_size(c->fifo)) {
         if (c->eof)
@@ -340,20 +323,22 @@ static int request_frame(AVFilterLink *link)
 
     switch (link->type) {
     case AVMEDIA_TYPE_VIDEO:
-        avfilter_start_frame(link, avfilter_ref_buffer(buf, ~0));
-        avfilter_draw_slice(link, 0, link->h, 1);
-        avfilter_end_frame(link);
+        if ((ret = ff_start_frame(link, avfilter_ref_buffer(buf, ~0))) < 0 ||
+            (ret = ff_draw_slice(link, 0, link->h, 1)) < 0 ||
+            (ret = ff_end_frame(link)) < 0)
+            goto fail;
         break;
     case AVMEDIA_TYPE_AUDIO:
-        ff_filter_samples(link, avfilter_ref_buffer(buf, ~0));
+        ret = ff_filter_samples(link, avfilter_ref_buffer(buf, ~0));
         break;
     default:
         return AVERROR(EINVAL);
     }
 
+fail:
     avfilter_unref_buffer(buf);
 
-    return 0;
+    return ret;
 }
 
 static int poll_frame(AVFilterLink *link)
@@ -374,13 +359,13 @@ AVFilter avfilter_vsrc_buffer = {
     .init      = init_video,
     .uninit    = uninit,
 
-    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = request_frame,
-                                    .poll_frame      = poll_frame,
-                                    .config_props    = config_props, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = request_frame,
+                                          .poll_frame      = poll_frame,
+                                          .config_props    = config_props, },
+                                        { .name = NULL}},
 };
 
 AVFilter avfilter_asrc_abuffer = {
@@ -392,11 +377,11 @@ AVFilter avfilter_asrc_abuffer = {
     .init      = init_audio,
     .uninit    = uninit,
 
-    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_AUDIO,
-                                    .request_frame   = request_frame,
-                                    .poll_frame      = poll_frame,
-                                    .config_props    = config_props, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_AUDIO,
+                                          .request_frame   = request_frame,
+                                          .poll_frame      = poll_frame,
+                                          .config_props    = config_props, },
+                                        { .name = NULL}},
 };