GNOME Bugzilla – Bug 667949
Memory leak occurs while using videomixer2 element
Last modified: 2012-01-15 22:35:47 UTC
Dear Developers, Here is my code for generate 2 IplImages (in OpenCv) with using gstreamer elements. I've created this system: v4l2src -> videobox -> -> videomixer2 -> videoflip -> ffmpegcolorspace -> appsink v4l2src -> videobox -> But memory leakage detected. I changed videomixer2 with videomixer element, leakage problem fixed but fps of images decreased from 30 to 2-3. And i also tried to make 2 seperate systems: v4l2src -> videobox -> videoflip -> ffmpegcolorspace -> appsink there was also no memory leak in this systems, but they are not syncronised and getting close in 10 seconds, when both of them works. So, i definitely decide videmixer2 element has some problems. Actually memory leak is not happens everytime. If the image consists a lot of same pixels, then memory leak detected, but if the image consists complex intend: no leak detected. Here is my own code, you can try it : #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; }
There is no version 0.10.36, not of core/base (yet), and not of good. What version are you actually using? What's the output of: gst-inspect-0.10 videomixer2 | head -n 18 ?
I will not be able to reach my system for next week. But the system is: Machine: Beagleboard b7 Processor: omap3530 Operating System: Armstrong gstreamer version: 0.10.32 gstreamer good plugin version: the version at opkg (I think quite old) (If you suggest me to upgrade my gstreamer version pls note that how to.. Because when compiling source with "./configure - make - make install", i always get error)
It's not really useful to report bugs against such ancient versions before making sure they still happen with the latest release. I'm fairly certain these leaks are fixed in the current pre-releases (there were a bunch of leak fixes a while back). I can't tell how to upgrade GStreamer on your beagle board, ask the beagle board or opkg guys if there are newer packages available somewhere.