[FFmpeg-cvslog] lavfi: unref AVFilterLink.cur_buf in ff_end_frame().

Anton Khirnov git at videolan.org
Sat Jul 21 22:32:09 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Jul 14 17:09:43 2012 +0200| [07bad27810cdd7d3171cbd542119aa051646377c] | committer: Anton Khirnov

lavfi: unref AVFilterLink.cur_buf in ff_end_frame().

This reduces code duplication and prevents stale pointers from remaining
on the link.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07bad27810cdd7d3171cbd542119aa051646377c
---

 libavfilter/fifo.c          |    1 +
 libavfilter/split.c         |    2 --
 libavfilter/vf_crop.c       |    1 -
 libavfilter/vf_delogo.c     |    1 -
 libavfilter/vf_drawtext.c   |    1 -
 libavfilter/vf_fieldorder.c |    1 -
 libavfilter/vf_fps.c        |    1 +
 libavfilter/vf_frei0r.c     |    1 -
 libavfilter/vf_gradfun.c    |    1 -
 libavfilter/vf_hqdn3d.c     |    1 -
 libavfilter/vf_libopencv.c  |    1 -
 libavfilter/vf_overlay.c    |    1 -
 libavfilter/vf_pad.c        |    1 -
 libavfilter/vf_select.c     |    2 --
 libavfilter/vf_transpose.c  |    1 -
 libavfilter/vf_unsharp.c    |    1 -
 libavfilter/video.c         |    7 +++----
 17 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c
index e09e319..e1faf74 100644
--- a/libavfilter/fifo.c
+++ b/libavfilter/fifo.c
@@ -91,6 +91,7 @@ static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
 {
     add_to_queue(inlink, buf);
+    inlink->cur_buf = NULL;
 }
 
 static void queue_pop(FifoContext *s)
diff --git a/libavfilter/split.c b/libavfilter/split.c
index a3f6ef2..33cb226 100644
--- a/libavfilter/split.c
+++ b/libavfilter/split.c
@@ -89,8 +89,6 @@ static void end_frame(AVFilterLink *inlink)
 
     for (i = 0; i < ctx->nb_outputs; i++)
         ff_end_frame(ctx->outputs[i]);
-
-    avfilter_unref_buffer(inlink->cur_buf);
 }
 
 AVFilter avfilter_vf_split = {
diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index 6d124c1..6988fcf 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -317,7 +317,6 @@ static void end_frame(AVFilterLink *link)
     CropContext *crop = link->dst->priv;
 
     crop->var_values[VAR_N] += 1.0;
-    avfilter_unref_buffer(link->cur_buf);
     ff_end_frame(link->dst->outputs[0]);
 }
 
diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 2f9e1f9..f9c5ad7 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -260,7 +260,6 @@ static void end_frame(AVFilterLink *inlink)
 
     ff_draw_slice(outlink, 0, inlink->h, 1);
     ff_end_frame(outlink);
-    avfilter_unref_buffer(inpicref);
     avfilter_unref_buffer(outpicref);
 }
 
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index fd2ec8d..eac7245 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -868,7 +868,6 @@ static void end_frame(AVFilterLink *inlink)
 
     ff_draw_slice(outlink, 0, picref->video->h, 1);
     ff_end_frame(outlink);
-    avfilter_unref_buffer(inlink->cur_buf);
 }
 
 AVFilter avfilter_vf_drawtext = {
diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c
index b3cce19..05882d1 100644
--- a/libavfilter/vf_fieldorder.c
+++ b/libavfilter/vf_fieldorder.c
@@ -213,7 +213,6 @@ static void end_frame(AVFilterLink *inlink)
     }
 
     ff_end_frame(outlink);
-    avfilter_unref_buffer(inpicref);
     avfilter_unref_bufferp(&outlink->out_buf);
 }
 
diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index bcc6a69..f78e008 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -175,6 +175,7 @@ static void end_frame(AVFilterLink *inlink)
     int64_t delta;
     int i;
 
+    inlink->cur_buf = NULL;
     s->frames_in++;
     /* discard frames until we get the first timestamp */
     if (s->pts == AV_NOPTS_VALUE) {
diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c
index 93ec92a..87c9276 100644
--- a/libavfilter/vf_frei0r.c
+++ b/libavfilter/vf_frei0r.c
@@ -352,7 +352,6 @@ static void end_frame(AVFilterLink *inlink)
     frei0r->update(frei0r->instance, inpicref->pts * av_q2d(inlink->time_base) * 1000,
                    (const uint32_t *)inpicref->data[0],
                    (uint32_t *)outpicref->data[0]);
-    avfilter_unref_buffer(inpicref);
     ff_draw_slice(outlink, 0, outlink->h, 1);
     ff_end_frame(outlink);
     avfilter_unref_buffer(outpicref);
diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c
index 735bd50..b6583d7 100644
--- a/libavfilter/vf_gradfun.c
+++ b/libavfilter/vf_gradfun.c
@@ -225,7 +225,6 @@ static void end_frame(AVFilterLink *inlink)
 
     ff_draw_slice(outlink, 0, inlink->h, 1);
     ff_end_frame(outlink);
-    avfilter_unref_buffer(inpic);
     avfilter_unref_buffer(outpic);
 }
 
diff --git a/libavfilter/vf_hqdn3d.c b/libavfilter/vf_hqdn3d.c
index af69d41..79adaea 100644
--- a/libavfilter/vf_hqdn3d.c
+++ b/libavfilter/vf_hqdn3d.c
@@ -322,7 +322,6 @@ static void end_frame(AVFilterLink *inlink)
 
     ff_draw_slice(outlink, 0, inpic->video->h, 1);
     ff_end_frame(outlink);
-    avfilter_unref_buffer(inpic);
     avfilter_unref_buffer(outpic);
 }
 
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index ac892d9..f04d469 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -365,7 +365,6 @@ static void end_frame(AVFilterLink *inlink)
     ocv->end_frame_filter(ctx, &inimg, &outimg);
     fill_picref_from_iplimage(outpicref, &outimg, inlink->format);
 
-    avfilter_unref_buffer(inpicref);
     ff_draw_slice(outlink, 0, outlink->h, 1);
     ff_end_frame(outlink);
     avfilter_unref_buffer(outpicref);
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index b9d64b9..1230763 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -339,7 +339,6 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 static void end_frame(AVFilterLink *inlink)
 {
     ff_end_frame(inlink->dst->outputs[0]);
-    avfilter_unref_buffer(inlink->cur_buf);
 }
 
 static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index 037abd5..b0d5c5f 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -348,7 +348,6 @@ static void end_frame(AVFilterLink *link)
 {
     ff_end_frame(link->dst->outputs[0]);
     avfilter_unref_buffer(link->dst->outputs[0]->out_buf);
-    avfilter_unref_buffer(link->cur_buf);
 }
 
 static void draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice)
diff --git a/libavfilter/vf_select.c b/libavfilter/vf_select.c
index 719885e..91d48f0 100644
--- a/libavfilter/vf_select.c
+++ b/libavfilter/vf_select.c
@@ -258,14 +258,12 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 static void end_frame(AVFilterLink *inlink)
 {
     SelectContext *select = inlink->dst->priv;
-    AVFilterBufferRef *picref = inlink->cur_buf;
 
     if (select->select) {
         if (select->cache_frames)
             return;
         ff_end_frame(inlink->dst->outputs[0]);
     }
-    avfilter_unref_buffer(picref);
 }
 
 static int request_frame(AVFilterLink *outlink)
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index f78244e..e772e8b 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -192,7 +192,6 @@ static void end_frame(AVFilterLink *inlink)
         }
     }
 
-    avfilter_unref_buffer(inpic);
     ff_draw_slice(outlink, 0, outpic->video->h, 1);
     ff_end_frame(outlink);
     avfilter_unref_buffer(outpic);
diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index ddfbf2c..3d28759 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -225,7 +225,6 @@ static void end_frame(AVFilterLink *link)
     apply_unsharp(out->data[1], out->linesize[1], in->data[1], in->linesize[1], cw,      ch,      &unsharp->chroma);
     apply_unsharp(out->data[2], out->linesize[2], in->data[2], in->linesize[2], cw,      ch,      &unsharp->chroma);
 
-    avfilter_unref_buffer(in);
     ff_draw_slice(link->dst->outputs[0], 0, link->h, 1);
     ff_end_frame(link->dst->outputs[0]);
     avfilter_unref_buffer(out);
diff --git a/libavfilter/video.c b/libavfilter/video.c
index feaaeba..e507f97 100644
--- a/libavfilter/video.c
+++ b/libavfilter/video.c
@@ -162,7 +162,8 @@ AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, int w, int
 
 void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
-    ff_start_frame(link->dst->outputs[0], picref);
+    AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~0);
+    ff_start_frame(link->dst->outputs[0], buf_out);
 }
 
 static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
@@ -223,9 +224,6 @@ static void default_end_frame(AVFilterLink *inlink)
     if (inlink->dst->nb_outputs)
         outlink = inlink->dst->outputs[0];
 
-    avfilter_unref_buffer(inlink->cur_buf);
-    inlink->cur_buf = NULL;
-
     if (outlink) {
         if (outlink->out_buf) {
             avfilter_unref_buffer(outlink->out_buf);
@@ -250,6 +248,7 @@ void ff_end_frame(AVFilterLink *link)
         avfilter_unref_buffer(link->src_buf);
         link->src_buf = NULL;
     }
+    avfilter_unref_bufferp(&link->cur_buf);
 }
 
 void ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)



More information about the ffmpeg-cvslog mailing list