webrtcsrc: add turn-servers property

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1380>
This commit is contained in:
Maksym Khomenko 2023-11-03 23:24:54 +02:00 committed by GStreamer Marge Bot
parent 5371eb52ad
commit e5fd2c3568
2 changed files with 48 additions and 9 deletions

View file

@ -6513,17 +6513,28 @@
"writable": true
},
"stun-server": {
"blurb": "NULL",
"blurb": "The STUN server of the form stun://host:port",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "stun://stun.l.google.com:19302",
"mutable": "null",
"mutable": "ready",
"readable": true,
"type": "gchararray",
"writable": true
},
"turn-servers": {
"blurb": "The TURN servers of the form <\"turn(s)://username:password@host:port\", \"turn(s)://username1:password1@host1:port1\">",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"mutable": "ready",
"readable": true,
"type": "GstValueArray",
"writable": true
},
"video-codecs": {
"blurb": "Names of video codecs to be be used during the SDP negotiation. Valid values: [VP8, H264, VP9, H265]",
"conditionally-available": false,

View file

@ -34,6 +34,7 @@ const RTP_TWCC_URI: &str =
struct Settings {
stun_server: Option<String>,
turn_servers: gst::Array,
signaller: Signallable,
meta: Option<gst::Structure>,
video_codecs: Vec<Codec>,
@ -62,8 +63,21 @@ impl ObjectImpl for WebRTCSrc {
static PROPS: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
glib::ParamSpecString::builder("stun-server")
.nick("The STUN server to use")
.blurb("The STUN server of the form stun://host:port")
.flags(glib::ParamFlags::READWRITE)
.default_value(DEFAULT_STUN_SERVER)
.mutable_ready()
.build(),
gst::ParamSpecArray::builder("turn-servers")
.nick("List of TURN servers to use")
.blurb("The TURN servers of the form <\"turn(s)://username:password@host:port\", \"turn(s)://username1:password1@host1:port1\">")
.element_spec(&glib::ParamSpecString::builder("turn-server")
.nick("TURN Server")
.blurb("The TURN server of the form turn(s)://username:password@host:port.")
.build()
)
.mutable_ready()
.build(),
glib::ParamSpecObject::builder::<Signallable>("signaller")
.flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT_ONLY)
@ -114,29 +128,33 @@ impl ObjectImpl for WebRTCSrc {
"video-codecs" => {
self.settings.lock().unwrap().video_codecs = value
.get::<gst::ArrayRef>()
.expect("Type checked upstream")
.expect("type checked upstream")
.as_slice()
.iter()
.filter_map(|codec_name| {
Codecs::find(codec_name.get::<&str>().expect("Type checked upstream"))
Codecs::find(codec_name.get::<&str>().expect("type checked upstream"))
})
.collect::<Vec<Codec>>()
}
"audio-codecs" => {
self.settings.lock().unwrap().audio_codecs = value
.get::<gst::ArrayRef>()
.expect("Type checked upstream")
.expect("type checked upstream")
.as_slice()
.iter()
.filter_map(|codec_name| {
Codecs::find(codec_name.get::<&str>().expect("Type checked upstream"))
Codecs::find(codec_name.get::<&str>().expect("type checked upstream"))
})
.collect::<Vec<Codec>>()
}
"stun-server" => {
self.settings.lock().unwrap().stun_server = value
.get::<Option<String>>()
.expect("type checked upstream")
.expect("type checked upstream");
}
"turn-servers" => {
let mut settings = self.settings.lock().unwrap();
settings.turn_servers = value.get::<gst::Array>().expect("type checked upstream");
}
"meta" => {
self.settings.lock().unwrap().meta = value
@ -173,6 +191,7 @@ impl ObjectImpl for WebRTCSrc {
)
.to_value(),
"stun-server" => self.settings.lock().unwrap().stun_server.to_value(),
"turn-servers" => self.settings.lock().unwrap().turn_servers.to_value(),
"meta" => self.settings.lock().unwrap().meta.to_value(),
"enable-data-channel-navigation" => {
let settings = self.settings.lock().unwrap();
@ -233,6 +252,7 @@ impl Default for Settings {
Self {
stun_server: DEFAULT_STUN_SERVER.map(|v| v.to_string()),
turn_servers: Default::default(),
signaller: signaller.upcast(),
meta: Default::default(),
audio_codecs: Codecs::audio_codecs()
@ -475,10 +495,18 @@ impl WebRTCSrc {
.build()
.with_context(|| "Failed to make element webrtcbin".to_string())?;
if let Some(stun_server) = self.settings.lock().unwrap().stun_server.as_ref() {
{
let settings = self.settings.lock().unwrap();
if let Some(stun_server) = settings.stun_server.as_ref() {
webrtcbin.set_property("stun-server", stun_server);
}
for turn_server in settings.turn_servers.iter() {
webrtcbin.emit_by_name::<bool>("add-turn-server", &[&turn_server]);
}
}
let bin = gst::Bin::new();
bin.connect_pad_removed(glib::clone!(@weak self as this => move |_, pad|
this.state.lock().unwrap().flow_combiner.remove_pad(pad);