Browse code

avfilter/vf_lut2: add framesync options

Also stop leaking memory.

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2017/08/30 19:06:47
Showing 1 changed files
... ...
@@ -52,6 +52,7 @@ enum var_name {
52 52
 
53 53
 typedef struct LUT2Context {
54 54
     const AVClass *class;
55
+    FFFrameSync fs;
55 56
 
56 57
     char   *comp_expr_str[4];
57 58
 
... ...
@@ -66,7 +67,6 @@ typedef struct LUT2Context {
66 66
 
67 67
     void (*lut2)(struct LUT2Context *s, AVFrame *dst, AVFrame *srcx, AVFrame *srcy);
68 68
 
69
-    FFFrameSync fs;
70 69
 } LUT2Context;
71 70
 
72 71
 #define OFFSET(x) offsetof(LUT2Context, x)
... ...
@@ -85,6 +85,7 @@ static av_cold void uninit(AVFilterContext *ctx)
85 85
     LUT2Context *s = ctx->priv;
86 86
     int i;
87 87
 
88
+    ff_framesync2_uninit(&s->fs);
88 89
     av_frame_free(&s->prev_frame);
89 90
 
90 91
     for (i = 0; i < 4; i++) {
... ...
@@ -212,14 +213,14 @@ static int process_frame(FFFrameSync *fs)
212 212
     AVFilterContext *ctx = fs->parent;
213 213
     LUT2Context *s = fs->opaque;
214 214
     AVFilterLink *outlink = ctx->outputs[0];
215
-    AVFrame *out, *srcx, *srcy;
215
+    AVFrame *out, *srcx = NULL, *srcy = NULL;
216 216
     int ret;
217 217
 
218 218
     if ((ret = ff_framesync2_get_frame(&s->fs, 0, &srcx, 0)) < 0 ||
219 219
         (ret = ff_framesync2_get_frame(&s->fs, 1, &srcy, 0)) < 0)
220 220
         return ret;
221 221
 
222
-    if (ctx->is_disabled) {
222
+    if (ctx->is_disabled || !srcy) {
223 223
         out = av_frame_clone(srcx);
224 224
         if (!out)
225 225
             return AVERROR(ENOMEM);
... ...
@@ -332,7 +333,7 @@ static int lut2_config_output(AVFilterLink *outlink)
332 332
     in = s->fs.in;
333 333
     in[0].time_base = srcx->time_base;
334 334
     in[1].time_base = srcy->time_base;
335
-    in[0].sync   = 1;
335
+    in[0].sync   = 2;
336 336
     in[0].before = EXT_STOP;
337 337
     in[0].after  = EXT_INFINITY;
338 338
     in[1].sync   = 1;
... ...
@@ -378,11 +379,12 @@ static const AVFilterPad outputs[] = {
378 378
 
379 379
 #define lut2_options options
380 380
 
381
-AVFILTER_DEFINE_CLASS(lut2);
381
+FRAMESYNC_DEFINE_CLASS(lut2, LUT2Context, fs);
382 382
 
383 383
 AVFilter ff_vf_lut2 = {
384 384
     .name          = "lut2",
385 385
     .description   = NULL_IF_CONFIG_SMALL("Compute and apply a lookup table from two video inputs."),
386
+    .preinit       = lut2_framesync_preinit,
386 387
     .priv_size     = sizeof(LUT2Context),
387 388
     .priv_class    = &lut2_class,
388 389
     .uninit        = uninit,