mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-29 06:50:59 +00:00
webrtchttp: Allow audio or video caps to be specified as None with WHEP
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>
This commit is contained in:
parent
764143d971
commit
95c007953c
1 changed files with 34 additions and 23 deletions
|
@ -37,8 +37,8 @@ const DEFAULT_TIMEOUT: u32 = 15;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Settings {
|
struct Settings {
|
||||||
video_caps: gst::Caps,
|
video_caps: Option<gst::Caps>,
|
||||||
audio_caps: gst::Caps,
|
audio_caps: Option<gst::Caps>,
|
||||||
turn_server: Option<String>,
|
turn_server: Option<String>,
|
||||||
stun_server: Option<String>,
|
stun_server: Option<String>,
|
||||||
whep_endpoint: Option<String>,
|
whep_endpoint: Option<String>,
|
||||||
|
@ -51,8 +51,8 @@ struct Settings {
|
||||||
#[allow(clippy::derivable_impls)]
|
#[allow(clippy::derivable_impls)]
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
let video_caps = Some(
|
||||||
video_caps: [
|
[
|
||||||
"video/x-vp8",
|
"video/x-vp8",
|
||||||
"video/x-h264",
|
"video/x-h264",
|
||||||
"video/x-vp9",
|
"video/x-vp9",
|
||||||
|
@ -62,10 +62,17 @@ impl Default for Settings {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(gst::Structure::new_empty)
|
.map(gst::Structure::new_empty)
|
||||||
.collect::<gst::Caps>(),
|
.collect::<gst::Caps>(),
|
||||||
audio_caps: ["audio/x-opus"]
|
);
|
||||||
|
let audio_caps = Some(
|
||||||
|
["audio/x-opus"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(gst::Structure::new_empty)
|
.map(gst::Structure::new_empty)
|
||||||
.collect::<gst::Caps>(),
|
.collect::<gst::Caps>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
video_caps,
|
||||||
|
audio_caps,
|
||||||
stun_server: None,
|
stun_server: None,
|
||||||
turn_server: None,
|
turn_server: None,
|
||||||
whep_endpoint: None,
|
whep_endpoint: None,
|
||||||
|
@ -264,15 +271,13 @@ impl ObjectImpl for WhepSrc {
|
||||||
let mut settings = self.settings.lock().unwrap();
|
let mut settings = self.settings.lock().unwrap();
|
||||||
settings.video_caps = value
|
settings.video_caps = value
|
||||||
.get::<Option<gst::Caps>>()
|
.get::<Option<gst::Caps>>()
|
||||||
.expect("type checked upstream")
|
.expect("type checked upstream");
|
||||||
.unwrap_or_else(gst::Caps::new_empty);
|
|
||||||
}
|
}
|
||||||
"audio-caps" => {
|
"audio-caps" => {
|
||||||
let mut settings = self.settings.lock().unwrap();
|
let mut settings = self.settings.lock().unwrap();
|
||||||
settings.audio_caps = value
|
settings.audio_caps = value
|
||||||
.get::<Option<gst::Caps>>()
|
.get::<Option<gst::Caps>>()
|
||||||
.expect("type checked upstream")
|
.expect("type checked upstream");
|
||||||
.unwrap_or_else(gst::Caps::new_empty);
|
|
||||||
}
|
}
|
||||||
"stun-server" => {
|
"stun-server" => {
|
||||||
let mut settings = self.settings.lock().unwrap();
|
let mut settings = self.settings.lock().unwrap();
|
||||||
|
@ -839,25 +844,31 @@ impl WhepSrc {
|
||||||
settings.video_caps
|
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
|
* Since we will be recvonly we need to add a transceiver without which
|
||||||
* WebRTC bin does not generate ICE candidates.
|
* WebRTC bin does not generate ICE candidates.
|
||||||
*/
|
*/
|
||||||
|
if let Some(audio_caps) = &settings.audio_caps {
|
||||||
self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>(
|
self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>(
|
||||||
"add-transceiver",
|
"add-transceiver",
|
||||||
&[
|
&[&WebRTCRTPTransceiverDirection::Recvonly, &audio_caps],
|
||||||
&WebRTCRTPTransceiverDirection::Recvonly,
|
|
||||||
&settings.audio_caps,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(video_caps) = &settings.video_caps {
|
||||||
self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>(
|
self.webrtcbin.emit_by_name::<WebRTCRTPTransceiver>(
|
||||||
"add-transceiver",
|
"add-transceiver",
|
||||||
&[
|
&[&WebRTCRTPTransceiverDirection::Recvonly, &video_caps],
|
||||||
&WebRTCRTPTransceiverDirection::Recvonly,
|
|
||||||
&settings.video_caps,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
drop(settings);
|
drop(settings);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue