From 90d65cb446dbdaa681351a4dc0a65e77ac5fa330 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 23 Sep 2010 18:18:54 +0200 Subject: [PATCH] basetransform: avoid useless memcpy Because of the awkward refcounting in prepare_output_buffer, we might end up with writable buffers that point to the same data. Check for those cases so that we avoid a useless memcpy and keep valgrind quiet. Fixes #628176 --- libs/gst/base/gstbasetransform.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 8460be0..07f87f3 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -2181,10 +2181,17 @@ no_qos: GST_DEBUG_OBJECT (trans, "doing inplace transform"); if (inbuf != *outbuf) { - /* different buffers, copy the input to the output first, we then do an - * in-place transform on the output buffer. */ - memcpy (GST_BUFFER_DATA (*outbuf), GST_BUFFER_DATA (inbuf), - GST_BUFFER_SIZE (inbuf)); + guint8 *indata, *outdata; + + /* Different buffer. The data can still be the same when we are dealing + * with subbuffers of the same buffer. Note that because of the FIXME in + * prepare_output_buffer() we have decreased the refcounts of inbuf and + * outbuf to keep them writable */ + indata = GST_BUFFER_DATA (inbuf); + outdata = GST_BUFFER_DATA (*outbuf); + + if (indata != outdata) + memcpy (outdata, indata, GST_BUFFER_SIZE (inbuf)); } ret = bclass->transform_ip (trans, *outbuf); } else { -- 2.7.4