[FFmpeg-cvslog] vf_scale: avoid a pointless memcpy in no-op conversion.

Anton Khirnov git at videolan.org
Mon Apr 2 00:52:51 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Mar 29 07:02:27 2012 +0200| [416fd90ead0cdea962a1319a1b20b9272be4fb49] | committer: Anton Khirnov

vf_scale: avoid a pointless memcpy in no-op conversion.

I.e. just pass the buffer along when src parameters == dst parameters.

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

 libavfilter/vf_scale.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 46009a7..a4da088 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -213,11 +213,16 @@ static int config_props(AVFilterLink *outlink)
 
     if (scale->sws)
         sws_freeContext(scale->sws);
-    scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format,
-                                outlink->w, outlink->h, outlink->format,
-                                scale->flags, NULL, NULL, NULL);
-    if (!scale->sws)
-        return AVERROR(EINVAL);
+    if (inlink->w == outlink->w && inlink->h == outlink->h &&
+        inlink->format == outlink->format)
+        scale->sws = NULL;
+    else {
+        scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format,
+                                    outlink->w, outlink->h, outlink->format,
+                                    scale->flags, NULL, NULL, NULL);
+        if (!scale->sws)
+            return AVERROR(EINVAL);
+    }
 
 
     if (inlink->sample_aspect_ratio.num)
@@ -241,6 +246,11 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     AVFilterLink *outlink = link->dst->outputs[0];
     AVFilterBufferRef *outpicref;
 
+    if (!scale->sws) {
+        avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+        return;
+    }
+
     scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
     scale->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
 
@@ -267,6 +277,11 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
     AVFilterBufferRef *cur_pic = link->cur_buf;
     const uint8_t *data[4];
 
+    if (!scale->sws) {
+        avfilter_draw_slice(link->dst->outputs[0], y, h, slice_dir);
+        return;
+    }
+
     if (scale->slice_y == 0 && slice_dir == -1)
         scale->slice_y = link->dst->outputs[0]->h;
 



More information about the ffmpeg-cvslog mailing list