appsink memory leak

umit sivrumit at yahoo.com
Mon Sep 16 08:36:02 UTC 2019


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/


More information about the gstreamer-devel mailing list