From 4d0642800191d368d7342545ce75df3af3e2aab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 9 Jul 2020 16:30:41 -0400 Subject: [PATCH] webrtc sendonly: Exit on bus errors Catch bus errors and cleanly error out Part-of: --- webrtc/sendonly/webrtc-recvonly-h264.c | 41 ++++++++++++++++++- webrtc/sendonly/webrtc-unidirectional-h264.c | 42 +++++++++++++++++++- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/webrtc/sendonly/webrtc-recvonly-h264.c b/webrtc/sendonly/webrtc-recvonly-h264.c index 1fc9a1dfa2..8df62f4fed 100644 --- a/webrtc/sendonly/webrtc-recvonly-h264.c +++ b/webrtc/sendonly/webrtc-recvonly-h264.c @@ -270,6 +270,38 @@ on_incoming_stream (GstElement * webrtc, GstPad * pad, gst_object_unref (sinkpad); } +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; +} ReceiverEntry * create_receiver_entry (SoupWebsocketConnection * connection) @@ -278,6 +310,7 @@ create_receiver_entry (SoupWebsocketConnection * connection) ReceiverEntry *receiver_entry; GstCaps *video_caps; GstWebRTCRTPTransceiver *trans = NULL; + GstBus *bus; receiver_entry = g_slice_alloc0 (sizeof (ReceiverEntry)); receiver_entry->connection = connection; @@ -331,7 +364,13 @@ create_receiver_entry (SoupWebsocketConnection * connection) g_signal_connect (receiver_entry->webrtcbin, "on-ice-candidate", G_CALLBACK (on_ice_candidate_cb), (gpointer) receiver_entry); - gst_element_set_state (receiver_entry->pipeline, GST_STATE_PLAYING); + bus = gst_pipeline_get_bus (GST_PIPELINE (receiver_entry->pipeline)); + gst_bus_add_watch (bus, bus_watch_cb, NULL); + gst_object_unref (bus); + + if (gst_element_set_state (receiver_entry->pipeline, GST_STATE_PLAYING) == + GST_STATE_CHANGE_FAILURE) + g_error ("Error starting pipeline"); return receiver_entry; diff --git a/webrtc/sendonly/webrtc-unidirectional-h264.c b/webrtc/sendonly/webrtc-unidirectional-h264.c index 4dba828fcb..4f919c5bf8 100644 --- a/webrtc/sendonly/webrtc-unidirectional-h264.c +++ b/webrtc/sendonly/webrtc-unidirectional-h264.c @@ -158,6 +158,39 @@ const gchar *html_source = " \n \ \n \ "; +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; +} + ReceiverEntry * create_receiver_entry (SoupWebsocketConnection * connection) { @@ -165,6 +198,7 @@ create_receiver_entry (SoupWebsocketConnection * connection) ReceiverEntry *receiver_entry; GstWebRTCRTPTransceiver *trans; GArray *transceivers; + GstBus *bus; receiver_entry = g_slice_alloc0 (sizeof (ReceiverEntry)); receiver_entry->connection = connection; @@ -205,7 +239,13 @@ create_receiver_entry (SoupWebsocketConnection * connection) g_signal_connect (receiver_entry->webrtcbin, "on-ice-candidate", G_CALLBACK (on_ice_candidate_cb), (gpointer) receiver_entry); - gst_element_set_state (receiver_entry->pipeline, GST_STATE_PLAYING); + bus = gst_pipeline_get_bus (GST_PIPELINE (receiver_entry->pipeline)); + gst_bus_add_watch (bus, bus_watch_cb, NULL); + gst_object_unref (bus); + + if (gst_element_set_state (receiver_entry->pipeline, GST_STATE_PLAYING) == + GST_STATE_CHANGE_FAILURE) + g_error ("Could not start pipeline"); return receiver_entry;