Hi,
To start, I know there are lots of issues reported for appsink memory leaks and I checked many of them but could not solve the issue. I suspect there is either significant leak in appsink library code or proper way to deallocate are not documented/shown in example codes. I have a simple application to test memory leaks for a pipeline having appsink element, I start/stop delete/recreate pipeline according to input from user(via std::cin). Below is the main thread: GMainLoop *loop = nullptr; thread t; thread testSinkThread; while(true) { char c; cin >> c; if(c == 'r') { string pipelineStr = "udpsrc port=50002 caps=\"application/x-rtp,encoding-name=H264,clock-rate=90000\" do-timestamp=false" " ! rtpjitterbuffer latency=0 ! rtph264depay" " ! avdec_h264 max-threads=4" " ! videoconvert ! video/x-raw,format=RGB" " ! queue ! appsink name=appsink sync=false drop=true max-buffers=1 enable-last-sample=false"; gstPipeline = gst_parse_launch(pipelineStr.c_str(), nullptr); g_assert(gstPipeline); loop = g_main_loop_new(nullptr, false); gst_bus_add_watch( GST_ELEMENT_BUS(gstPipeline), (GstBusFunc)bus_message, loop ); t = thread([loop](){ gst_element_set_state(gstPipeline, GST_STATE_PLAYING); g_main_loop_run (loop); }); running = true; testSinkThread = thread([](){ decodedLoop(); }); } else if(c == 'q') { gst_element_send_event(gstPipeline, gst_event_new_eos()); t.join(); //quit= true; running = false; testSinkThread.join(); gst_element_set_state (gstPipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT(gstPipeline)); g_main_loop_unref(loop); } } and below is the appsink consumer thread: void decodedLoop() { GstAppSink* appsink = (GstAppSink*) gst_bin_get_by_name(GST_BIN(gstPipeline),"appsink"); g_assert(appsink); while(running) { GstSample *sample = gst_app_sink_try_pull_sample(appsink, 500000000); if(sample == nullptr) { cout << "could not pull sample" << endl; continue; } GstBuffer *buffer = gst_sample_get_buffer(sample); if(!buffer) { cout << "could not get buffer" << endl; return; } GstMapInfo mapInfo; gst_buffer_map(buffer, &mapInfo, GST_MAP_READ); cout << "size: " << mapInfo.size << endl; gst_buffer_unmap(buffer,&mapInfo); gst_object_unref(buffer); gst_sample_unref(sample); } gst_object_unref(appsink); } this is bus watcher method: static gboolean bus_message (GstBus * bus, GstMessage * message, gpointer* user_data) { GMainLoop* loop = (GMainLoop*)user_data; switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR: { g_main_loop_quit (loop); return false; } case GST_MESSAGE_EOS: g_main_loop_quit (loop); return false; default: break; } return TRUE; } Each time user inputs 'r' to create/start and 'q' to stop/delete pipeline, memory increases in mbytes(7mb for my test input stream) I removed appsink from pipeline and tested via fakesink too and do not see any memory increase then. Is there anything wrong with the above code? Thanks, Umit -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi Umit San,
Please check by commenting "gst_object_unref(buffer)" in the below code : void decodedLoop() { GstAppSink* appsink = (GstAppSink*) gst_bin_get_by_name(GST_BIN(gstPipeline),"appsink"); g_assert(appsink); while(running) { GstSample *sample = gst_app_sink_try_pull_sample(appsink, 500000000); if(sample == nullptr) { cout << "could not pull sample" << endl; continue; } GstBuffer *buffer = gst_sample_get_buffer(sample); if(!buffer) { cout << "could not get buffer" << endl; return; } GstMapInfo mapInfo; gst_buffer_map(buffer, &mapInfo, GST_MAP_READ); cout << "size: " << mapInfo.size << endl; gst_buffer_unmap(buffer,&mapInfo); // gst_object_unref(buffer);---> This unref is not needed gst_sample_unref(sample); } gst_object_unref(appsink); } -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hello Maddy,
Thanks for your reply. I had added that line to check if it would help. I know that it is unnecessary as the unmap line just above that line should deallocate resources. I removed the line as you suggested and executed a test run with trace options: GST_TRACERS="leaks" & GST_DEBUG="GST_TRACER:7" Here is trace the output after 1 run(via break in 'q' input): GST_TRACER :0:: object-alive, type-name=(string)GstAppSink, address=(gpointer)0000024A13FA7BA0, description=(string)<appsinkname>, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstBuffer, address=(gpointer)0000024A146A95A0, description=(string)buffer: 0000024A146A95A0, pts 0:00:00.820323653, dts 99:99:99.999999999, dur 0:00:00.039987204, *size 3686400*, offset none, offset_end none, flags 0x0, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstBuffer, address=(gpointer)0000024A146A9120, description=(string)buffer: 0000024A146A9120, pts 99:99:99.999999999, dts 99:99:99.999999999, dur 99:99:99.999999999,* size 3686400*, offset none, offset_end none, flags 0x0, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstCaps, address=(gpointer)0000024A1461EC90, description=(string)video/x-raw, width=(int)1280, height=(int)960, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)3126/125, format=(string)RGB, ref-count=(uint)2, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstMemory, address=(gpointer)0000024A156EC040, description=(string)0000024A156EC040, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstMemory, address=(gpointer)0000024A1518A040, description=(string)0000024A1518A040, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstPad, address=(gpointer)0000024A145F4E30, description=(string)<appsinkname:sink>, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstSample, address=(gpointer)0000024A145169A0, description=(string)0000024A145169A0, ref-count=(uint)1, trace=(string); GST_TRACER :0:: object-alive, type-name=(string)GstVideoBufferPool, address=(gpointer)0000024A146BEE50, description=(string)<videobufferpool1>, ref-count=(uint)1, trace=(string); As seen above, app leaks 2 frames of decoded data. Btw I am testing in windows environment and version *1.16*, which is the latest. It seems I'm missing something simple but can't figure it out. Thanks, Umit -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |