webrtc: handle an ice-lite remote offer
authorMatthew Waters <matthew@centricular.com>
Mon, 25 May 2020 03:10:20 +0000 (13:10 +1000)
committerMatthew Waters <matthew@centricular.com>
Thu, 28 May 2020 09:57:45 +0000 (19:57 +1000)
When the remote peer offers an ice-lite SDP, we need to configure our
ICE negotiation to be in controlling mode as the peer will not be.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1304>

ext/webrtc/gstwebrtcbin.c
ext/webrtc/webrtcsdp.c
ext/webrtc/webrtcsdp.h

index f51ebae..b505b75 100644 (file)
@@ -2756,9 +2756,6 @@ _create_offer_task (GstWebRTCBin * webrtc, const GstStructure * options)
 
   /* FIXME: pre-emptively setup receiving elements when needed */
 
-  /* XXX: only true for the initial offerer */
-  g_object_set (webrtc->priv->ice, "controller", TRUE, NULL);
-
   g_list_free (seen_transceivers);
 
   if (webrtc->priv->last_generated_answer)
@@ -4465,7 +4462,25 @@ _set_description_task (GstWebRTCBin * webrtc, struct set_description *sd)
     signalling_state_changed = TRUE;
   }
 
-  if (webrtc->signaling_state == GST_WEBRTC_SIGNALING_STATE_STABLE) {
+  {
+    gboolean ice_controller = FALSE;
+
+    /* we control ice negotiation if we send the initial offer */
+    ice_controller |=
+        new_signaling_state == GST_WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER
+        && webrtc->current_remote_description == NULL;
+    /* or, if the remote is an ice-lite peer */
+    ice_controller |= new_signaling_state == GST_WEBRTC_SIGNALING_STATE_STABLE
+        && webrtc->current_remote_description->type == GST_WEBRTC_SDP_TYPE_OFFER
+        && _message_has_attribute_key (webrtc->current_remote_description->sdp,
+        "ice-lite");
+
+    GST_DEBUG_OBJECT (webrtc, "we are in ice controlling mode: %s",
+        ice_controller ? "true" : "false");
+    g_object_set (webrtc->priv->ice, "controller", ice_controller, NULL);
+  }
+
+  if (new_signaling_state == GST_WEBRTC_SIGNALING_STATE_STABLE) {
     GList *tmp;
 
     /* media modifications */
index a93a106..6e7f4b3 100644 (file)
@@ -144,9 +144,8 @@ _check_sdp_crypto (SDPSource source, GstWebRTCSessionDescription * sdp,
   return TRUE;
 }
 
-#if 0
-static gboolean
-_session_has_attribute_key (const GstSDPMessage * msg, const gchar * key)
+gboolean
+_message_has_attribute_key (const GstSDPMessage * msg, const gchar * key)
 {
   int i;
   for (i = 0; i < gst_sdp_message_attributes_len (msg); i++) {
@@ -159,6 +158,7 @@ _session_has_attribute_key (const GstSDPMessage * msg, const gchar * key)
   return FALSE;
 }
 
+#if 0
 static gboolean
 _session_has_attribute_key_value (const GstSDPMessage * msg, const gchar * key,
     const gchar * value)
index c116df5..1501cbc 100644 (file)
@@ -91,6 +91,9 @@ gboolean                            _message_media_is_datachannel           (con
                                                                              guint media_id);
 G_GNUC_INTERNAL
 guint                               _message_get_datachannel_index          (const GstSDPMessage * msg);
+G_GNUC_INTERNAL
+gboolean                            _message_has_attribute_key              (const GstSDPMessage * msg,
+                                                                             const gchar * key);
 
 G_GNUC_INTERNAL
 gboolean                            _get_bundle_index                       (GstSDPMessage * sdp,