examples: webrtc: Add handling of the LATENCY messages to the C examples
authorSebastian Dröge <sebastian@centricular.com>
Tue, 20 Dec 2022 11:03:15 +0000 (13:03 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 20 Dec 2022 11:03:15 +0000 (13:03 +0200)
Without this the configured latency on the pipeline will be wrong.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3609>

subprojects/gst-examples/webrtc/multiparty-sendrecv/gst/mp-webrtc-sendrecv.c
subprojects/gst-examples/webrtc/sendonly/webrtc-recvonly-h264.c
subprojects/gst-examples/webrtc/sendonly/webrtc-unidirectional-h264.c

index 81d56b5..a184e19 100644 (file)
@@ -122,6 +122,8 @@ get_string_from_json_object (JsonObject * object)
 static gboolean
 bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
 {
+  GstPipeline *pipeline = user_data;
+
   switch (GST_MESSAGE_TYPE (message)) {
     case GST_MESSAGE_ERROR:
     {
@@ -145,6 +147,9 @@ bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
       g_free (debug);
       break;
     }
+    case GST_MESSAGE_LATENCY:
+      gst_bin_recalculate_latency (GST_BIN (pipeline));
+      break;
     default:
       break;
   }
@@ -463,7 +468,7 @@ start_pipeline (void)
   }
 
   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
-  gst_bus_add_watch (bus, bus_watch_cb, NULL);
+  gst_bus_add_watch (bus, bus_watch_cb, pipeline);
   gst_object_unref (bus);
 
   gst_print ("Starting pipeline, not transmitting yet\n");
index bac3a3a..0533f08 100644 (file)
@@ -273,6 +273,8 @@ on_incoming_stream (GstElement * webrtc, GstPad * pad,
 static gboolean
 bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
 {
+  GstPipeline *pipeline = user_data;
+
   switch (GST_MESSAGE_TYPE (message)) {
     case GST_MESSAGE_ERROR:
     {
@@ -296,6 +298,9 @@ bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
       g_free (debug);
       break;
     }
+    case GST_MESSAGE_LATENCY:
+      gst_bin_recalculate_latency (GST_BIN (pipeline));
+      break;
     default:
       break;
   }
@@ -365,7 +370,7 @@ create_receiver_entry (SoupWebsocketConnection * connection)
       G_CALLBACK (on_ice_candidate_cb), (gpointer) receiver_entry);
 
   bus = gst_pipeline_get_bus (GST_PIPELINE (receiver_entry->pipeline));
-  gst_bus_add_watch (bus, bus_watch_cb, NULL);
+  gst_bus_add_watch (bus, bus_watch_cb, receiver_entry->pipeline);
   gst_object_unref (bus);
 
   if (gst_element_set_state (receiver_entry->pipeline, GST_STATE_PLAYING) ==
index ef52f41..4717b6a 100644 (file)
@@ -169,6 +169,8 @@ const gchar *html_source = " \n \
 static gboolean
 bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
 {
+  GstPipeline *pipeline = user_data;
+
   switch (GST_MESSAGE_TYPE (message)) {
     case GST_MESSAGE_ERROR:
     {
@@ -192,6 +194,9 @@ bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
       g_free (debug);
       break;
     }
+    case GST_MESSAGE_LATENCY:
+      gst_bin_recalculate_latency (GST_BIN (pipeline));
+      break;
     default:
       break;
   }
@@ -297,7 +302,7 @@ create_receiver_entry (SoupWebsocketConnection * connection)
       G_CALLBACK (on_ice_candidate_cb), (gpointer) receiver_entry);
 
   bus = gst_pipeline_get_bus (GST_PIPELINE (receiver_entry->pipeline));
-  gst_bus_add_watch (bus, bus_watch_cb, NULL);
+  gst_bus_add_watch (bus, bus_watch_cb, receiver_entry->pipeline);
   gst_object_unref (bus);
 
   if (gst_element_set_state (receiver_entry->pipeline, GST_STATE_PLAYING) ==