memory leak while using appsink element..

juhsis juhsis at yahoo.com
Fri Dec 30 04:07:06 PST 2011


I change my code, as you said. In some cases memory leakage problem is solved
but in some cases it is not.
When i set complex images, full with randomly '0' - '255' as image data
there is no leakage.
When i set all image's data '0' at one of two cameras , there is no leakage.
When i set all image's data '0' at both cameras, there is huge leakage.
When i set all image's data '255' at one of two cameras, there is huge
leakage.
When i set all image's data '255' at both cameras, there is huge leakage.

What causes to my program to get this type of problem? btw it is a very
interesting problem. May be the most interesting one.. 

Here is my edited code: 

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
#include <opencv/cvaux.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <gst/app/gstappsink.h>
#include <gst/app/gstappbuffer.h>
#define SCAL1 2
#define SHOWIN 1

unsigned char *ptr;
IplImage* frameL;
IplImage* frameR;
GstElement *pipeline;
static void on_new_buffer_from_source (GstElement * elt, void * data)
{
	guint size;
	GstBuffer *buffer;
	int sizeovertwo;
	
	buffer = gst_app_sink_pull_buffer (GST_APP_SINK (elt));
	//printf("%p\n",buffer);
	size = GST_BUFFER_SIZE (buffer);
	sizeovertwo = size/2;
	ptr = (unsigned char *)GST_BUFFER_DATA (buffer);
	
	for(unsigned int r = 0; r < sizeovertwo; r++)
		frameL->imageData[r]=ptr[r];
	for(unsigned int r = 0; r < sizeovertwo; r++)
		frameR->imageData[r]=ptr[r+sizeovertwo];
#if SHOWIN
	ptr = NULL;
        int cmd = cvvWaitKeyEx( 0, 1 );
	gst_buffer_unref(buffer);
	system("free -mb");
        cvvShowImage( "source left", frameL );
        cvvShowImage( "source right", frameR );
#endif

}

int main( int argc, char** argv )
{
	GstElement *ffmpegcolor = NULL;
	gst_init (&argc, &argv);
	GstElement *source,*source2,*mix;
	GstElement *vb,*vb2;
	GstElement *sink;
	GstElement *vf;
	GstPad *sink_0,*sink_1;
	GstPad *src_0,*src_1;
	GstCaps *caps,*caps2;
	gboolean link_ok=true;
	gboolean link_ok2=true;
	gboolean link_ok3=true;

	caps = gst_caps_new_full (
		gst_structure_new ("video/x-raw-yuv",
			 "width", G_TYPE_INT, 640/SCAL1,
			 "height", G_TYPE_INT, 480/SCAL1,
			 "framerate", GST_TYPE_FRACTION, 20, 1,
			 NULL),
		NULL);
	caps2 = gst_caps_new_full (
		gst_structure_new ("video/x-raw-gray",
			 "width", G_TYPE_INT, 480/SCAL1,
			 "height", G_TYPE_INT, 1280/SCAL1,
			 "framerate", GST_TYPE_FRACTION, 20, 1,
			 NULL),
		NULL);
	pipeline = gst_pipeline_new ("my-pipeline");
	source = gst_element_factory_make("v4l2src", "source");
	source2 = gst_element_factory_make("v4l2src", "source2");
 	g_object_set(G_OBJECT(source), "device", "/dev/video0", NULL);
 	g_object_set(G_OBJECT(source2), "device", "/dev/video1", NULL);
	mix = gst_element_factory_make("videomixer2", "mix");
	vb = gst_element_factory_make("videobox", "vb");
	vb2 = gst_element_factory_make("videobox", "vb2");
	vf = gst_element_factory_make("videoflip", "vf");
 	g_object_set(G_OBJECT(vb2), "left",(gint)-640/SCAL1, NULL);
 	g_object_set(G_OBJECT(vf), "method",1, NULL);
	ffmpegcolor = gst_element_factory_make ("ffmpegcolorspace", NULL);
	sink = gst_element_factory_make("appsink", "sink");
	gst_app_sink_set_drop((GstAppSink *)sink,true);
 	g_object_set(G_OBJECT(sink), "max-buffers",(guint)1, NULL);
 	gst_bin_add_many(GST_BIN
(pipeline),source,source2,vb,vb2,mix,ffmpegcolor,vf,sink, NULL);
	
	link_ok = gst_element_link_filtered (source, vb, caps);
	link_ok2 = gst_element_link_filtered (source2, vb2, caps);

	sink_0 = gst_element_get_request_pad (mix, "sink_0");
	sink_1 = gst_element_get_request_pad (mix, "sink_1");
	src_0 = gst_element_get_static_pad (vb, "src");
	src_1 = gst_element_get_static_pad (vb2, "src");
  	gst_pad_link (src_0,sink_1);
  	gst_pad_link (src_1,sink_0);
	gst_object_unref(sink_0);
	gst_object_unref(sink_1);
	gst_object_unref(src_0);
	gst_object_unref(src_1);
	

	gst_element_link_many(mix, vf, ffmpegcolor, NULL);
	link_ok3 = gst_element_link_filtered (ffmpegcolor,sink, caps2);

	gst_caps_unref (caps);
	gst_caps_unref (caps2);

	if (!link_ok) {
		g_warning ("Failed to link element1 and element2 --1--!");
	}
	if (!link_ok2) {
		g_warning ("Failed to link element1 and element2 --2--!");
	}
	if (!link_ok3) {
		g_warning ("Failed to link element1 and element2 --2--!");
	}
	g_object_set (G_OBJECT (sink), "emit-signals", TRUE, "sync", FALSE, NULL);
	g_signal_connect (sink, "new-buffer", G_CALLBACK
(on_new_buffer_from_source), NULL);
	frameR = cvCreateImage(cvSize(480/SCAL1, 640/SCAL1), IPL_DEPTH_8U, 1);
	frameL = cvCreateImage(cvSize(480/SCAL1, 640/SCAL1), IPL_DEPTH_8U, 1);
	gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
	g_print ("Let's run!\n");
	
#if SHOWIN
        cvNamedWindow("source left", 1);
        cvNamedWindow("source right", 1);
#endif
    while(true){

    }


    return 0;
}

--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/memory-leak-while-using-appsink-element-tp4229045p4245620.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list