From b8b0c39a63ecc6c368d6bd60562d5b907c566cb8 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Mon, 26 Apr 2010 17:18:54 -0300 Subject: [PATCH] pyramidsegment: Allocate a new buffer for output Use a newly allocated buffer for output, and release the intermediary image used. Also add a TODO for performance improvement --- ext/opencv/pyramidsegment/gstpyramidsegment.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ext/opencv/pyramidsegment/gstpyramidsegment.c b/ext/opencv/pyramidsegment/gstpyramidsegment.c index 7e3e8fe091..f6a4793ef2 100644 --- a/ext/opencv/pyramidsegment/gstpyramidsegment.c +++ b/ext/opencv/pyramidsegment/gstpyramidsegment.c @@ -293,6 +293,7 @@ static GstFlowReturn gst_pyramidsegment_chain (GstPad * pad, GstBuffer * buf) { Gstpyramidsegment *filter; + GstBuffer *outbuf; filter = GST_PYRAMIDSEGMENT (GST_OBJECT_PARENT (pad)); @@ -302,10 +303,19 @@ gst_pyramidsegment_chain (GstPad * pad, GstBuffer * buf) cvPyrSegmentation (filter->cvImage, filter->cvSegmentedImage, filter->storage, &(filter->comp), filter->level, filter->threshold1, filter->threshold2); - gst_buffer_set_data (buf, (guint8 *) filter->cvSegmentedImage->imageData, - filter->cvSegmentedImage->imageSize); + /* TODO look if there is a way in opencv to reuse the image data and + * delete only the struct headers. Would avoid a memcpy here */ - return gst_pad_push (filter->srcpad, buf); + outbuf = gst_buffer_new_and_alloc (filter->cvSegmentedImage->imageSize); + gst_buffer_copy_metadata (outbuf, buf, GST_BUFFER_COPY_ALL); + memcpy (GST_BUFFER_DATA (outbuf), filter->cvSegmentedImage->imageData, + GST_BUFFER_SIZE (outbuf)); + + gst_buffer_unref (buf); + cvReleaseImage (&filter->cvSegmentedImage); + g_assert (filter->cvSegmentedImage == NULL); + + return gst_pad_push (filter->srcpad, outbuf); }