From 094b2519013dd837f7796831f1483cc4e222439c Mon Sep 17 00:00:00 2001 From: Sam Van Den Berge Date: Tue, 18 Oct 2022 15:28:32 +0200 Subject: [PATCH] examples: webrtc: mp-sendrecv: add bus handler Without this bus handler, messages posted to the bus will keep a ref to their source elements, preventing them from being disposed. Part-of: --- .../gst/mp-webrtc-sendrecv.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/subprojects/gst-examples/webrtc/multiparty-sendrecv/gst/mp-webrtc-sendrecv.c b/subprojects/gst-examples/webrtc/multiparty-sendrecv/gst/mp-webrtc-sendrecv.c index ff45996abd..81d56b575c 100644 --- a/subprojects/gst-examples/webrtc/multiparty-sendrecv/gst/mp-webrtc-sendrecv.c +++ b/subprojects/gst-examples/webrtc/multiparty-sendrecv/gst/mp-webrtc-sendrecv.c @@ -119,6 +119,39 @@ get_string_from_json_object (JsonObject * object) return text; } +static gboolean +bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data) +{ + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_ERROR: + { + GError *error = NULL; + gchar *debug = NULL; + + gst_message_parse_error (message, &error, &debug); + g_error ("Error on bus: %s (debug: %s)", error->message, debug); + g_error_free (error); + g_free (debug); + break; + } + case GST_MESSAGE_WARNING: + { + GError *error = NULL; + gchar *debug = NULL; + + gst_message_parse_warning (message, &error, &debug); + g_warning ("Warning on bus: %s (debug: %s)", error->message, debug); + g_error_free (error); + g_free (debug); + break; + } + default: + break; + } + + return G_SOURCE_CONTINUE; +} + static void handle_media_stream (GstPad * pad, GstElement * pipe, const char *convert_name, const char *sink_name) @@ -413,6 +446,7 @@ start_pipeline (void) { GstStateChangeReturn ret; GError *error = NULL; + GstBus *bus = NULL; /* NOTE: webrtcbin currently does not support dynamic addition/removal of * streams, so we use a separate webrtcbin for each peer, but all of them are @@ -428,6 +462,10 @@ start_pipeline (void) goto err; } + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_watch (bus, bus_watch_cb, NULL); + gst_object_unref (bus); + gst_print ("Starting pipeline, not transmitting yet\n"); ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE)