From 7a1b2d97d42c301cbda3e7fc065b08272d64ee30 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Thu, 23 Mar 2023 12:27:43 +0200 Subject: [PATCH] webrtcsink: Add ice-transport-policy option Can be used to force relay ICE candidates, ensuring TURN server is used. Proxy to the corresponding setting in webrtcbin, Part-of: --- docs/plugins/gst_plugins_cache.json | 12 ++++++++++++ net/webrtc/src/webrtcsink/imp.rs | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index b960a411..62211990 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -6134,6 +6134,18 @@ "type": "gboolean", "writable": true }, + "ice-transport-policy": { + "blurb": "The policy to apply for ICE transport", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "all (0)", + "mutable": "ready", + "readable": true, + "type": "GstWebRTCICETransportPolicy", + "writable": true + }, "max-bitrate": { "blurb": "Minimal bitrate to use (in bit/sec) when computing it through the congestion control algorithm", "conditionally-available": false, diff --git a/net/webrtc/src/webrtcsink/imp.rs b/net/webrtc/src/webrtcsink/imp.rs index f318060a..0f4e0162 100644 --- a/net/webrtc/src/webrtcsink/imp.rs +++ b/net/webrtc/src/webrtcsink/imp.rs @@ -7,7 +7,7 @@ use gst::subclass::prelude::*; use gst_rtp::prelude::*; use gst_utils::StreamProducer; use gst_video::subclass::prelude::*; -use gst_webrtc::WebRTCDataChannel; +use gst_webrtc::{WebRTCDataChannel, WebRTCICETransportPolicy}; use futures::prelude::*; @@ -51,6 +51,7 @@ const DEFAULT_CONGESTION_CONTROL: WebRTCSinkCongestionControl = const DEFAULT_DO_FEC: bool = true; const DEFAULT_DO_RETRANSMISSION: bool = true; const DEFAULT_ENABLE_DATA_CHANNEL_NAVIGATION: bool = false; +const DEFAULT_ICE_TRANSPORT_POLICY: WebRTCICETransportPolicy = WebRTCICETransportPolicy::All; const DEFAULT_START_BITRATE: u32 = 2048000; /* Start adding some FEC when the bitrate > 2Mbps as we found experimentally * that it is not worth it below that threshold */ @@ -76,6 +77,7 @@ struct Settings { do_retransmission: bool, enable_data_channel_navigation: bool, meta: Option, + ice_transport_policy: WebRTCICETransportPolicy, } /// Represents a codec we can offer @@ -294,6 +296,7 @@ impl Default for Settings { do_retransmission: DEFAULT_DO_RETRANSMISSION, enable_data_channel_navigation: DEFAULT_ENABLE_DATA_CHANNEL_NAVIGATION, meta: None, + ice_transport_policy: DEFAULT_ICE_TRANSPORT_POLICY, } } } @@ -1860,6 +1863,7 @@ impl WebRTCSink { })?; webrtcbin.set_property_from_str("bundle-policy", "max-bundle"); + webrtcbin.set_property("ice-transport-policy", settings.ice_transport_policy); if let Some(stun_server) = settings.stun_server.as_ref() { webrtcbin.set_property("stun-server", stun_server); @@ -3001,6 +3005,11 @@ impl ObjectImpl for WebRTCSink { .nick("Meta") .blurb("Free form metadata about the producer") .build(), + glib::ParamSpecEnum::builder_with_default("ice-transport-policy", DEFAULT_ICE_TRANSPORT_POLICY) + .nick("ICE Transport Policy") + .blurb("The policy to apply for ICE transport") + .mutable_ready() + .build(), ] }); @@ -3070,6 +3079,12 @@ impl ObjectImpl for WebRTCSink { .get::>() .expect("type checked upstream") } + "ice-transport-policy" => { + let mut settings = self.settings.lock().unwrap(); + settings.ice_transport_policy = value + .get::() + .expect("type checked upstream"); + } _ => unimplemented!(), } } @@ -3125,6 +3140,10 @@ impl ObjectImpl for WebRTCSink { let settings = self.settings.lock().unwrap(); settings.meta.to_value() } + "ice-transport-policy" => { + let settings = self.settings.lock().unwrap(); + settings.ice_transport_policy.to_value() + } _ => unimplemented!(), } }