Hi All,
I am writing a golang wrapper for an application that uses gstreamer.
I have the following functions defined in C.
The create_pipeline, start_pipeline and stop_pipeline are called from golang whenever it needs to send something over udpsink.
I see that over a period of time as pipeline is created and stopped, memory leaks with a saw pattern until there is out of memory. I dont see any memory leaks if there is one pipeline and it runs for a long time. which points me to creating and releasing pipeline.
Does calling gst_init() multiple times leak memory? I obviously cannot call gst_deinit() as it messes up the gstreamer completely.
I saw a similar post in this thread ->
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/539 but there are no solutions.
The code snippet is below. I can share the entire code if needed. I stripped it down for simplicity.
GMainLoop *gstreamer_send_main_loop = NULL;
// This function gets called as part of golang init() to create a main loop when it starts
void gstreamer_send_start_mainloop(void) {
if (gstreamer_send_main_loop != NULL) {
g_main_loop_unref(gstreamer_send_main_loop);
}
gstreamer_send_main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(gstreamer_send_main_loop);
}
GstElement *gstreamer_send_create_pipeline(char *pipeline) {
gst_init(NULL, NULL);
GError *error = NULL;
return gst_parse_launch(pipeline, &error);
}
static gboolean gstreamer_send_bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
//..... Just prints messages does not do any allocation
}
return TRUE;
}
void gstreamer_send_start_pipeline(GstElement *pipeline) {
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_add_watch(bus, gstreamer_send_bus_call, NULL);
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
}
void gstreamer_send_stop_pipeline(GstElement *pipeline) {
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
}