lavfi: add error handling to end_frame().
[ffmpeg.git] / libavfilter / vf_hqdn3d.c
index 0a26dd0..9e01606 100644 (file)
@@ -28,6 +28,7 @@
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "formats.h"
+#include "internal.h"
 #include "video.h"
 
 typedef struct {
@@ -196,7 +197,7 @@ static void PrecalcCoefs(int *Ct, double Dist25)
 #define PARAM2_DEFAULT 3.0
 #define PARAM3_DEFAULT 6.0
 
-static int init(AVFilterContext *ctx, const char *args, void *opaque)
+static int init(AVFilterContext *ctx, const char *args)
 {
     HQDN3DContext *hqdn3d = ctx->priv;
     double LumSpac, LumTmp, ChromSpac, ChromTmp;
@@ -237,7 +238,7 @@ static int init(AVFilterContext *ctx, const char *args, void *opaque)
         }
     }
 
-    av_log(ctx, AV_LOG_INFO, "ls:%lf cs:%lf lt:%lf ct:%lf\n",
+    av_log(ctx, AV_LOG_VERBOSE, "ls:%lf cs:%lf lt:%lf ct:%lf\n",
            LumSpac, ChromSpac, LumTmp, ChromTmp);
     if (LumSpac < 0 || ChromSpac < 0 || isnan(ChromTmp)) {
         av_log(ctx, AV_LOG_ERROR,
@@ -289,9 +290,12 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     HQDN3DContext *hqdn3d = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -299,6 +303,7 @@ static void end_frame(AVFilterLink *inlink)
     AVFilterBufferRef *outpic = outlink->out_buf;
     int cw = inpic->video->w >> hqdn3d->hsub;
     int ch = inpic->video->h >> hqdn3d->vsub;
+    int ret;
 
     deNoise(inpic->data[0], outpic->data[0],
             hqdn3d->Line, &hqdn3d->Frame[0], inpic->video->w, inpic->video->h,
@@ -319,10 +324,10 @@ static void end_frame(AVFilterLink *inlink)
             hqdn3d->Coefs[2],
             hqdn3d->Coefs[3]);
 
-    ff_draw_slice(outlink, 0, inpic->video->h, 1);
-    ff_end_frame(outlink);
-    avfilter_unref_buffer(inpic);
-    avfilter_unref_buffer(outpic);
+    if ((ret = ff_draw_slice(outlink, 0, inpic->video->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_hqdn3d = {
@@ -334,14 +339,14 @@ AVFilter avfilter_vf_hqdn3d = {
     .uninit        = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .draw_slice       = null_draw_slice,
-                                    .config_props     = config_input,
-                                    .end_frame        = end_frame },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .draw_slice       = null_draw_slice,
+                                          .config_props     = config_input,
+                                          .end_frame        = end_frame },
+                                        { .name = NULL}},
 
-    .outputs   = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO },
+                                        { .name = NULL}},
 };