webrtc: Use new libnice API to get the candidate relay address
authorPhilippe Normand <philn@igalia.com>
Wed, 11 May 2022 08:17:46 +0000 (09:17 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 26 May 2022 10:54:59 +0000 (10:54 +0000)
Corresponding libnice API added in:
https://gitlab.freedesktop.org/libnice/libnice/-/merge_requests/229 (0.1.19)
https://gitlab.freedesktop.org/libnice/libnice/-/merge_requests/232 (0.1.20)

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

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcice.c

index 9f2dc68..04adc8f 100644 (file)
@@ -886,10 +886,44 @@ static gchar *
 _get_server_url (GstWebRTCICE * ice, NiceCandidate * cand)
 {
   switch (cand->type) {
-    case NICE_CANDIDATE_TYPE_RELAYED:
+    case NICE_CANDIDATE_TYPE_RELAYED:{
+#if NICE_CHECK_VERSION(0, 1, 19)
+      NiceAddress addr;
+      gchar ipaddr[NICE_ADDRESS_STRING_LEN];
+      nice_candidate_relay_address (cand, &addr);
+      nice_address_to_string (&addr, ipaddr);
+      return g_strdup (ipaddr);
+#else
+      static gboolean warned = FALSE;
+      if (!warned) {
+        GST_WARNING
+            ("libnice version < 0.1.19 detected, relayed candidate server address might be wrong.");
+        warned = TRUE;
+      }
       return g_strdup (gst_uri_get_host (ice->turn_server));
-    case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
+#endif
+    }
+    case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:{
+#if NICE_CHECK_VERSION(0, 1, 20)
+      NiceAddress addr;
+      gchar ipaddr[NICE_ADDRESS_STRING_LEN];
+      if (nice_candidate_stun_server_address (cand, &addr)) {
+        nice_address_to_string (&addr, ipaddr);
+        return g_strdup (ipaddr);
+      } else {
+        return g_strdup (gst_uri_get_host (ice->stun_server));
+      }
+#else
+      static gboolean warned = FALSE;
+      if (!warned) {
+        GST_WARNING
+            ("libnice version < 0.1.20 detected, server-reflexive candidate server "
+            "address might be wrong.");
+        warned = TRUE;
+      }
+#endif
       return g_strdup (gst_uri_get_host (ice->stun_server));
+    }
     default:
       return g_strdup ("");
   }