diff options
author | Sanchayan Maity <sanchayan@asymptotic.io> | 2024-01-18 13:06:31 +0300 |
---|---|---|
committer | Sanchayan Maity <sanchayan@asymptotic.io> | 2024-01-18 13:13:19 +0300 |
commit | 95c007953c0874bc46152078775d673cf44cc255 (patch) | |
tree | 546cbec4219a9868e6eb2dddabd083a43cc2f9d9 | |
parent | 764143d97178b2c404460473cddfd8fe1e7a63ba (diff) |
We were setting audio and video caps by default even when the user
might have requested only video or audio. This would then result
in a `Could not reuse transceiver` error from the webrtcbin.
Fix this by allowing the user to specify audio or video caps as
None. This allows us to maintain the earlier behaviour for backward
compatibility while allowing the user to not request audio or video
as need be.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1433>
-rw-r--r-- | net/webrtchttp/src/whepsrc/imp.rs | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/net/webrtchttp/src/whepsrc/imp.rs b/net/webrtchttp/src/whepsrc/imp.rs index dd423a6f6..0a157babe 100644 --- a/net/webrtchttp/src/whepsrc/imp.rs +++ b/net/webrtchttp/src/whepsrc/imp.rs @@ -37,8 +37,8 @@ const DEFAULT_TIMEOUT: u32 = 15; #[derive(Debug, Clone)] struct Settings { - video_caps: gst::Caps, - audio_caps: gst::Caps, + video_caps: Option<gst::Caps>, + audio_caps: Option<gst::Caps>, turn_server: Option<String>, stun_server: Option<String>, whep_endpoint: Option<String>, @@ -51,8 +51,8 @@ struct Settings { #[allow(clippy::derivable_impls)] impl Default for Settings { fn default() -> Self { - Self { - video_caps: [ + let video_caps = Some( + [ "video/x-vp8", "video/x-h264", "video/x-vp9", @@ -62,10 +62,17 @@ impl Default for Settings { .into_iter() .map(gst::Structure::new_empty) .collect::<gst::Caps>(), - audio_caps: ["audio/x-opus"] + ); + let audio_caps = Some( + ["audio/x-opus"] .into_iter() .map(gst::Structure::new_empty) .collect::<gst::Caps>(), + ); + + Self { + video_caps, + audio_caps, stun_server: None, turn_server: None, whep_endpoint: None, @@ -264,15 +271,13 @@ impl ObjectImpl for WhepSrc { let mut settings = self.settings.lock().unwrap(); settings.video_caps = value .get::<Option<gst::Caps>>() - .expect("type checked upstream") - .unwrap_or_else(gst::Caps::new_empty); + .expect("type checked upstream"); } "audio-caps" => { let mut settings = self.settings.lock().unwrap(); settings.audio_caps = value .get::<Option<gst::Caps>>() - .expect("type checked upstream") - .unwrap_or_else(gst::Caps::new_empty); + .expect("type checked upstream"); } "stun-server" => { let mut settings = self.settings.lock().unwrap(); @@ -839,25 +844,31 @@ impl WhepSrc { settings.video_caps ); + if settings.audio_caps.is_none() && settings.video_caps.is_none() { + self.raise_error( + gst::ResourceError::Failed, + "One of audio-caps or video-caps must be set".to_string(), + ); + return; + } + /* * Since we will be recvonly we need to add a transceiver without which * WebRTC bin does not generate ICE candidates. */ - self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>( - "add-transceiver", - &[ - &WebRTCRTPTransceiverDirection::Recvonly, - &settings.audio_caps, - ], - ); + if let Some(audio_caps) = &settings.audio_caps { + self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>( + "add-transceiver", + &[&WebRTCRTPTransceiverDirection::Recvonly, &audio_caps], + ); + } - self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>( - "add-transceiver", - &[ - &WebRTCRTPTransceiverDirection::Recvonly, - &settings.video_caps, - ], - ); + if let Some(video_caps) = &settings.video_caps { + self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>( + "add-transceiver", + &[&WebRTCRTPTransceiverDirection::Recvonly, &video_caps], + ); + } drop(settings); |