webrtc sendonly: Exit on bus errors

Catch bus errors and cleanly error out

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-examples/-/merge_requests/18>
This commit is contained in:
Olivier Crête 2020-07-09 16:30:41 -04:00
parent 43f8275ca9
commit 4d06428001
2 changed files with 81 additions and 2 deletions

View file

@ -270,6 +270,38 @@ on_incoming_stream (GstElement * webrtc, GstPad * pad,
gst_object_unref (sinkpad); 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 * ReceiverEntry *
create_receiver_entry (SoupWebsocketConnection * connection) create_receiver_entry (SoupWebsocketConnection * connection)
@ -278,6 +310,7 @@ create_receiver_entry (SoupWebsocketConnection * connection)
ReceiverEntry *receiver_entry; ReceiverEntry *receiver_entry;
GstCaps *video_caps; GstCaps *video_caps;
GstWebRTCRTPTransceiver *trans = NULL; GstWebRTCRTPTransceiver *trans = NULL;
GstBus *bus;
receiver_entry = g_slice_alloc0 (sizeof (ReceiverEntry)); receiver_entry = g_slice_alloc0 (sizeof (ReceiverEntry));
receiver_entry->connection = connection; receiver_entry->connection = connection;
@ -331,7 +364,13 @@ create_receiver_entry (SoupWebsocketConnection * connection)
g_signal_connect (receiver_entry->webrtcbin, "on-ice-candidate", g_signal_connect (receiver_entry->webrtcbin, "on-ice-candidate",
G_CALLBACK (on_ice_candidate_cb), (gpointer) receiver_entry); 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; return receiver_entry;

View file

@ -158,6 +158,39 @@ const gchar *html_source = " \n \
</html> \n \ </html> \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 * ReceiverEntry *
create_receiver_entry (SoupWebsocketConnection * connection) create_receiver_entry (SoupWebsocketConnection * connection)
{ {
@ -165,6 +198,7 @@ create_receiver_entry (SoupWebsocketConnection * connection)
ReceiverEntry *receiver_entry; ReceiverEntry *receiver_entry;
GstWebRTCRTPTransceiver *trans; GstWebRTCRTPTransceiver *trans;
GArray *transceivers; GArray *transceivers;
GstBus *bus;
receiver_entry = g_slice_alloc0 (sizeof (ReceiverEntry)); receiver_entry = g_slice_alloc0 (sizeof (ReceiverEntry));
receiver_entry->connection = connection; receiver_entry->connection = connection;
@ -205,7 +239,13 @@ create_receiver_entry (SoupWebsocketConnection * connection)
g_signal_connect (receiver_entry->webrtcbin, "on-ice-candidate", g_signal_connect (receiver_entry->webrtcbin, "on-ice-candidate",
G_CALLBACK (on_ice_candidate_cb), (gpointer) receiver_entry); 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; return receiver_entry;