[FFmpeg-devel] [PATCH] lavfi/gradfun: fix direct writing in buffer.

Clément Bœsch ubitux at gmail.com
Sun Dec 2 04:19:14 CET 2012


---
This is an attempt to fix a few problems introduce recently:

 - first, the use of AV_PERM_PRESERVE looks inappropriate, so we can remove it.
 - then it seems assumed that gradfun can do filtering in-place (see the direct
   flag). Though, that direct flag isn't passed to the filtering functions, and
   the filter doesn't seem to assume/support dst=src, so we need to get a new
   temporary buffer (allocated with ff_get_video_buffer) all the time.
 - the out->video->w=outlink->w, out->video->h=outlink->h look uneeded since
   avfilter_copy_buffer_ref_props handle this (and the filter doesn't change
   the video size).

Please comment,

---
 libavfilter/vf_gradfun.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c
index 260a44b..85095be 100644
--- a/libavfilter/vf_gradfun.c
+++ b/libavfilter/vf_gradfun.c
@@ -187,22 +187,14 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
     GradFunContext *gf = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef *out;
-    int p, direct = 0;
+    int p;
 
-    if ((in->perms & AV_PERM_WRITE) && !(in->perms & AV_PERM_PRESERVE)) {
-        direct = 1;
-        out = in;
-    } else {
-        out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
-        if (!out) {
-            avfilter_unref_bufferp(&in);
-            return AVERROR(ENOMEM);
-        }
-
-        avfilter_copy_buffer_ref_props(out, in);
-        out->video->w = outlink->w;
-        out->video->h = outlink->h;
+    out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+    if (!out) {
+        avfilter_unref_bufferp(&in);
+        return AVERROR(ENOMEM);
     }
+    avfilter_copy_buffer_ref_props(out, in);
 
     for (p = 0; p < 4 && in->data[p]; p++) {
         int w = inlink->w;
@@ -220,9 +212,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
             av_image_copy_plane(out->data[p], out->linesize[p], in->data[p], in->linesize[p], w, h);
     }
 
-    if (!direct)
-        avfilter_unref_bufferp(&in);
-
+    avfilter_unref_bufferp(&in);
     return ff_filter_frame(outlink, out);
 }
 
-- 
1.8.0.1



More information about the ffmpeg-devel mailing list