lavfi: check all ff_start_frame/draw_slice/end_frame calls for errors
[ffmpeg.git] / libavfilter / fifo.c
index 40c3796..66de62c 100644 (file)
@@ -55,7 +55,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     FifoContext *fifo = ctx->priv;
     fifo->last = &fifo->root;
 
-    av_log(ctx, AV_LOG_INFO, "\n");
     return 0;
 }
 
@@ -73,13 +72,21 @@ static av_cold void uninit(AVFilterContext *ctx)
     avfilter_unref_buffer(fifo->buf_out);
 }
 
-static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
+static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
 {
     FifoContext *fifo = inlink->dst->priv;
 
+    inlink->cur_buf = NULL;
     fifo->last->next = av_mallocz(sizeof(Buf));
+    if (!fifo->last->next) {
+        avfilter_unref_buffer(buf);
+        return AVERROR(ENOMEM);
+    }
+
     fifo->last = fifo->last->next;
     fifo->last->buf = buf;
+
+    return 0;
 }
 
 static void queue_pop(FifoContext *s)
@@ -91,9 +98,15 @@ static void queue_pop(FifoContext *s)
     s->root.next = tmp;
 }
 
-static void end_frame(AVFilterLink *inlink) { }
+static int end_frame(AVFilterLink *inlink)
+{
+    return 0;
+}
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
 /**
  * Move data pointers and pts offset samples forward.
@@ -211,15 +224,13 @@ static int return_audio_frame(AVFilterContext *ctx)
         buf_out = s->buf_out;
         s->buf_out = NULL;
     }
-    ff_filter_samples(link, buf_out);
-
-    return 0;
+    return ff_filter_samples(link, buf_out);
 }
 
 static int request_frame(AVFilterLink *outlink)
 {
     FifoContext *fifo = outlink->src->priv;
-    int ret;
+    int ret = 0;
 
     if (!fifo->root.next) {
         if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0)
@@ -230,16 +241,18 @@ static int request_frame(AVFilterLink *outlink)
      * so we don't have to worry about dereferencing it ourselves. */
     switch (outlink->type) {
     case AVMEDIA_TYPE_VIDEO:
-        ff_start_frame(outlink, fifo->root.next->buf);
-        ff_draw_slice (outlink, 0, outlink->h, 1);
-        ff_end_frame  (outlink);
+        if ((ret = ff_start_frame(outlink, fifo->root.next->buf)) < 0 ||
+            (ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
+            (ret = ff_end_frame(outlink)) < 0)
+            return ret;
+
         queue_pop(fifo);
         break;
     case AVMEDIA_TYPE_AUDIO:
         if (outlink->request_samples) {
             return return_audio_frame(outlink->src);
         } else {
-            ff_filter_samples(outlink, fifo->root.next->buf);
+            ret = ff_filter_samples(outlink, fifo->root.next->buf);
             queue_pop(fifo);
         }
         break;
@@ -247,7 +260,7 @@ static int request_frame(AVFilterLink *outlink)
         return AVERROR(EINVAL);
     }
 
-    return 0;
+    return ret;
 }
 
 AVFilter avfilter_vf_fifo = {
@@ -259,18 +272,18 @@ AVFilter avfilter_vf_fifo = {
 
     .priv_size = sizeof(FifoContext),
 
-    .inputs    = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer= ff_null_get_video_buffer,
-                                    .start_frame     = add_to_queue,
-                                    .draw_slice      = draw_slice,
-                                    .end_frame       = end_frame,
-                                    .rej_perms       = AV_PERM_REUSE2, },
-                                  { .name = NULL}},
-    .outputs   = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = request_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= ff_null_get_video_buffer,
+                                          .start_frame     = add_to_queue,
+                                          .draw_slice      = draw_slice,
+                                          .end_frame       = end_frame,
+                                          .rej_perms       = AV_PERM_REUSE2, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = request_frame, },
+                                        { .name = NULL}},
 };
 
 AVFilter avfilter_af_afifo = {
@@ -282,14 +295,14 @@ AVFilter avfilter_af_afifo = {
 
     .priv_size = sizeof(FifoContext),
 
-    .inputs    = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_AUDIO,
-                                    .get_audio_buffer = ff_null_get_audio_buffer,
-                                    .filter_samples   = add_to_queue,
-                                    .rej_perms        = AV_PERM_REUSE2, },
-                                  { .name = NULL}},
-    .outputs   = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_AUDIO,
-                                    .request_frame    = request_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_AUDIO,
+                                          .get_audio_buffer = ff_null_get_audio_buffer,
+                                          .filter_samples   = add_to_queue,
+                                          .rej_perms        = AV_PERM_REUSE2, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_AUDIO,
+                                          .request_frame    = request_frame, },
+                                        { .name = NULL}},
 };