webrtc: add features for specific signallers

When swapping between several development branches, compilation times can be
frustrating. This commit proposes adding features to control which signaller
to include when building the webrtc plugin. By default, all signallers are
included, just like before.

Compiling the `webrtc-precise-sync` examples with `--no-default-features`
reduces compilation to 267 crates instead of 429 when all signallers are
compiled in.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1539>
This commit is contained in:
François Laignel 2024-04-12 19:10:42 +02:00
parent 83d70d3471
commit 168af88eda
7 changed files with 352 additions and 282 deletions

View file

@ -22,6 +22,7 @@ gst-base.workspace = true
uuid = { version = "1", features = ["v4"] }
anyhow = "1"
chrono = "0.4"
thiserror = "1"
futures = "0.3"
tokio = { version = "1", features = ["fs", "macros", "rt-multi-thread", "time"] }
@ -33,33 +34,31 @@ serde_json = "1"
fastrand = "2.0"
gst_plugin_webrtc_protocol = { path="protocol", package = "gst-plugin-webrtc-signalling-protocol" }
human_bytes = "0.4"
once_cell.workspace = true
rand = "0.8"
url = "2"
aws-config = "1.0"
aws-types = "1.0"
aws-credential-types = "1.0"
aws-sigv4 = "1.0"
aws-smithy-http = { version = "0.60", features = [ "rt-tokio" ] }
aws-smithy-types = "1.0"
aws-sdk-kinesisvideo = "1.0"
aws-sdk-kinesisvideosignaling = "1.0"
http = "1.0"
chrono = "0.4"
data-encoding = "2.3.3"
url-escape = "0.1.1"
regex = "1"
aws-config = { version = "1.0", optional = true }
aws-types = { version = "1.0", optional = true }
aws-credential-types = { version = "1.0", optional = true }
aws-sigv4 = { version = "1.0", optional = true }
aws-smithy-http = { version = "0.60", features = [ "rt-tokio" ], optional = true }
aws-smithy-types = { version = "1.0", optional = true }
aws-sdk-kinesisvideo = { version = "1.0", optional = true }
aws-sdk-kinesisvideosignaling = { version = "1.0", optional = true }
http = { version = "1.0", optional = true }
data-encoding = {version = "2.3.3", optional = true }
url-escape = { version = "0.1.1", optional = true }
reqwest = { version = "0.11", features = ["default-tls"] }
reqwest = { version = "0.11", features = ["default-tls"], optional = true }
parse_link_header = {version = "0.3", features = ["url"]}
async-recursion = "1.0.0"
async-recursion = { version = "1.0.0", optional = true }
livekit-protocol = { version = "0.3" }
livekit-api = { version = "0.3", default-features = false, features = ["signal-client", "access-token", "native-tls"] }
livekit-protocol = { version = "0.3", optional = true }
livekit-api = { version = "0.3", default-features = false, features = ["signal-client", "access-token", "native-tls"], optional = true }
warp = "0.3"
crossbeam-channel = "0.5"
rand = "0.8"
once_cell.workspace = true
warp = {version = "0.3", optional = true }
crossbeam-channel = { version = "0.5", optional = true }
[dev-dependencies]
gst-plugin-rtp = { path = "../rtp" }
@ -67,6 +66,7 @@ tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-log = "0.2"
clap = { version = "4", features = ["derive"] }
regex = "1"
[lib]
name = "gstrswebrtc"
@ -77,12 +77,19 @@ path = "src/lib.rs"
gst-plugin-version-helper.workspace = true
[features]
default = ["v1_22"]
default = ["v1_22", "aws", "janus", "livekit", "whip"]
static = []
capi = []
v1_22 = ["gst/v1_22", "gst-app/v1_22", "gst-video/v1_22", "gst-webrtc/v1_22", "gst-sdp/v1_22", "gst-rtp/v1_22"]
doc = []
aws = ["dep:aws-config", "dep:aws-types", "dep:aws-credential-types", "dep:aws-sigv4",
"dep:aws-smithy-http", "dep:aws-smithy-types", "dep:aws-sdk-kinesisvideo",
"dep:aws-sdk-kinesisvideosignaling", "dep:data-encoding", "dep:http", "dep:url-escape"]
janus = ["dep:http"]
livekit = ["dep:livekit-protocol", "dep:livekit-api"]
whip = ["dep:async-recursion", "dep:crossbeam-channel", "dep:reqwest", "dep:warp"]
[package.metadata.capi]
min_version = "0.9.21"

View file

@ -14,13 +14,17 @@ use gst::glib;
use once_cell::sync::Lazy;
use tokio::runtime;
#[cfg(feature = "aws")]
mod aws_kvs_signaller;
#[cfg(feature = "janus")]
mod janusvr_signaller;
#[cfg(feature = "livekit")]
mod livekit_signaller;
pub mod signaller;
pub mod utils;
pub mod webrtcsink;
pub mod webrtcsrc;
#[cfg(feature = "whip")]
mod whip_signaller;
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {

View file

@ -104,7 +104,9 @@ use crate::RUNTIME;
use futures::future;
use futures::prelude::*;
use gst::ErrorMessage;
#[cfg(feature = "whip")]
use reqwest::header::HeaderMap;
#[cfg(feature = "whip")]
use reqwest::redirect::Policy;
use std::sync::Mutex;
use std::time::Duration;
@ -237,6 +239,7 @@ where
res
}
#[cfg(feature = "whip")]
pub fn parse_redirect_location(
headermap: &HeaderMap,
old_url: &reqwest::Url,
@ -277,11 +280,13 @@ pub fn parse_redirect_location(
}
}
#[cfg(feature = "whip")]
pub fn build_reqwest_client(pol: Policy) -> reqwest::Client {
let client_builder = reqwest::Client::builder();
client_builder.redirect(pol).build().unwrap()
}
#[cfg(feature = "whip")]
pub fn set_ice_servers(
webrtcbin: &gst::Element,
headermap: &HeaderMap,

View file

@ -23,11 +23,7 @@ use super::homegrown_cc::CongestionController;
use super::{
WebRTCSinkCongestionControl, WebRTCSinkError, WebRTCSinkMitigationMode, WebRTCSinkPad,
};
use crate::aws_kvs_signaller::AwsKvsSignaller;
use crate::janusvr_signaller::{JanusVRSignallerStr, JanusVRSignallerU64};
use crate::livekit_signaller::LiveKitSignaller;
use crate::signaller::{prelude::*, Signallable, Signaller, WebRTCSignallerRole};
use crate::whip_signaller::WhipClientSignaller;
use crate::{utils, RUNTIME};
use std::collections::{BTreeMap, HashSet};
@ -4521,13 +4517,20 @@ impl ObjectSubclass for WebRTCSink {
type ParentType = super::BaseWebRTCSink;
}
#[cfg(feature = "aws")]
pub(super) mod aws {
use super::*;
use crate::aws_kvs_signaller::AwsKvsSignaller;
#[derive(Default)]
pub struct AwsKvsWebRTCSink {}
impl ObjectImpl for AwsKvsWebRTCSink {
fn constructed(&self) {
let element = self.obj();
let ws = element.upcast_ref::<super::BaseWebRTCSink>().imp();
let ws = element
.upcast_ref::<crate::webrtcsink::BaseWebRTCSink>()
.imp();
let _ = ws.set_signaller(AwsKvsSignaller::default().upcast());
}
@ -4557,9 +4560,15 @@ impl BaseWebRTCSinkImpl for AwsKvsWebRTCSink {}
#[glib::object_subclass]
impl ObjectSubclass for AwsKvsWebRTCSink {
const NAME: &'static str = "GstAwsKvsWebRTCSink";
type Type = super::AwsKvsWebRTCSink;
type ParentType = super::BaseWebRTCSink;
type Type = crate::webrtcsink::AwsKvsWebRTCSink;
type ParentType = crate::webrtcsink::BaseWebRTCSink;
}
}
#[cfg(feature = "whip")]
pub(super) mod whip {
use super::*;
use crate::whip_signaller::WhipClientSignaller;
#[derive(Default)]
pub struct WhipWebRTCSink {}
@ -4567,7 +4576,9 @@ pub struct WhipWebRTCSink {}
impl ObjectImpl for WhipWebRTCSink {
fn constructed(&self) {
let element = self.obj();
let ws = element.upcast_ref::<super::BaseWebRTCSink>().imp();
let ws = element
.upcast_ref::<crate::webrtcsink::BaseWebRTCSink>()
.imp();
let _ = ws.set_signaller(WhipClientSignaller::default().upcast());
}
@ -4597,9 +4608,15 @@ impl BaseWebRTCSinkImpl for WhipWebRTCSink {}
#[glib::object_subclass]
impl ObjectSubclass for WhipWebRTCSink {
const NAME: &'static str = "GstWhipWebRTCSink";
type Type = super::WhipWebRTCSink;
type ParentType = super::BaseWebRTCSink;
type Type = crate::webrtcsink::WhipWebRTCSink;
type ParentType = crate::webrtcsink::BaseWebRTCSink;
}
}
#[cfg(feature = "livekit")]
pub(super) mod livekit {
use super::*;
use crate::livekit_signaller::LiveKitSignaller;
#[derive(Default)]
pub struct LiveKitWebRTCSink {}
@ -4607,7 +4624,9 @@ pub struct LiveKitWebRTCSink {}
impl ObjectImpl for LiveKitWebRTCSink {
fn constructed(&self) {
let element = self.obj();
let ws = element.upcast_ref::<super::BaseWebRTCSink>().imp();
let ws = element
.upcast_ref::<crate::webrtcsink::BaseWebRTCSink>()
.imp();
let _ = ws.set_signaller(LiveKitSignaller::new_producer().upcast());
}
@ -4637,9 +4656,15 @@ impl BaseWebRTCSinkImpl for LiveKitWebRTCSink {}
#[glib::object_subclass]
impl ObjectSubclass for LiveKitWebRTCSink {
const NAME: &'static str = "GstLiveKitWebRTCSink";
type Type = super::LiveKitWebRTCSink;
type ParentType = super::BaseWebRTCSink;
type Type = crate::webrtcsink::LiveKitWebRTCSink;
type ParentType = crate::webrtcsink::BaseWebRTCSink;
}
}
#[cfg(feature = "janus")]
pub(super) mod janus {
use super::*;
use crate::janusvr_signaller::{JanusVRSignallerStr, JanusVRSignallerU64};
#[derive(Debug, Clone, Default)]
struct JanusSettings {
@ -4647,7 +4672,7 @@ struct JanusSettings {
}
#[derive(Default, glib::Properties)]
#[properties(wrapper_type = super::JanusVRWebRTCSink)]
#[properties(wrapper_type = crate::webrtcsink::JanusVRWebRTCSink)]
pub struct JanusVRWebRTCSink {
/**
* GstJanusVRWebRTCSink:use-string-ids:
@ -4668,7 +4693,9 @@ impl ObjectImpl for JanusVRWebRTCSink {
fn constructed(&self) {
let settings = self.settings.lock().unwrap();
let element = self.obj();
let ws = element.upcast_ref::<super::BaseWebRTCSink>().imp();
let ws = element
.upcast_ref::<crate::webrtcsink::BaseWebRTCSink>()
.imp();
if settings.use_string_ids {
let _ = ws.set_signaller(JanusVRSignallerStr::default().upcast());
@ -4702,6 +4729,7 @@ impl BaseWebRTCSinkImpl for JanusVRWebRTCSink {}
#[glib::object_subclass]
impl ObjectSubclass for JanusVRWebRTCSink {
const NAME: &'static str = "GstJanusVRWebRTCSink";
type Type = super::JanusVRWebRTCSink;
type ParentType = super::BaseWebRTCSink;
type Type = crate::webrtcsink::JanusVRWebRTCSink;
type ParentType = crate::webrtcsink::BaseWebRTCSink;
}
}

View file

@ -53,20 +53,24 @@ glib::wrapper! {
pub struct WebRTCSink(ObjectSubclass<imp::WebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[cfg(feature = "aws")]
glib::wrapper! {
pub struct AwsKvsWebRTCSink(ObjectSubclass<imp::AwsKvsWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
pub struct AwsKvsWebRTCSink(ObjectSubclass<imp::aws::AwsKvsWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[cfg(feature = "whip")]
glib::wrapper! {
pub struct WhipWebRTCSink(ObjectSubclass<imp::WhipWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
pub struct WhipWebRTCSink(ObjectSubclass<imp::whip::WhipWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[cfg(feature = "livekit")]
glib::wrapper! {
pub struct LiveKitWebRTCSink(ObjectSubclass<imp::LiveKitWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
pub struct LiveKitWebRTCSink(ObjectSubclass<imp::livekit::LiveKitWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[cfg(feature = "janus")]
glib::wrapper! {
pub struct JanusVRWebRTCSink(ObjectSubclass<imp::JanusVRWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
pub struct JanusVRWebRTCSink(ObjectSubclass<imp::janus::JanusVRWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[derive(thiserror::Error, Debug)]
@ -140,24 +144,28 @@ pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Rank::NONE,
WebRTCSink::static_type(),
)?;
#[cfg(feature = "aws")]
gst::Element::register(
Some(plugin),
"awskvswebrtcsink",
gst::Rank::NONE,
AwsKvsWebRTCSink::static_type(),
)?;
#[cfg(feature = "whip")]
gst::Element::register(
Some(plugin),
"whipclientsink",
gst::Rank::NONE,
WhipWebRTCSink::static_type(),
)?;
#[cfg(feature = "livekit")]
gst::Element::register(
Some(plugin),
"livekitwebrtcsink",
gst::Rank::NONE,
LiveKitWebRTCSink::static_type(),
)?;
#[cfg(feature = "janus")]
/**
* element-janusvrwebrtcsink:
*

View file

@ -2,11 +2,9 @@
use gst::prelude::*;
use crate::livekit_signaller::LiveKitSignaller;
use crate::signaller::{prelude::*, Signallable, Signaller};
use crate::utils::{Codec, Codecs, NavigationEvent, AUDIO_CAPS, RTP_CAPS, VIDEO_CAPS};
use crate::webrtcsrc::WebRTCSrcPad;
use crate::whip_signaller::WhipServerSignaller;
use anyhow::{Context, Error};
use gst::glib;
use gst::subclass::prelude::*;
@ -1255,6 +1253,11 @@ impl ObjectSubclass for WebRTCSrc {
type Interfaces = (gst::URIHandler,);
}
#[cfg(feature = "whip")]
pub(super) mod whip {
use super::*;
use crate::whip_signaller::WhipServerSignaller;
#[derive(Default)]
pub struct WhipServerSrc {}
@ -1262,7 +1265,9 @@ impl ObjectImpl for WhipServerSrc {
fn constructed(&self) {
self.parent_constructed();
let element = self.obj();
let ws = element.upcast_ref::<super::BaseWebRTCSrc>().imp();
let ws = element
.upcast_ref::<crate::webrtcsrc::BaseWebRTCSrc>()
.imp();
let _ = ws.set_signaller(WhipServerSignaller::default().upcast());
@ -1300,9 +1305,15 @@ impl BaseWebRTCSrcImpl for WhipServerSrc {}
#[glib::object_subclass]
impl ObjectSubclass for WhipServerSrc {
const NAME: &'static str = "GstWhipServerSrc";
type Type = super::WhipServerSrc;
type ParentType = super::BaseWebRTCSrc;
type Type = crate::webrtcsrc::WhipServerSrc;
type ParentType = crate::webrtcsrc::BaseWebRTCSrc;
}
}
#[cfg(feature = "livekit")]
pub(super) mod livekit {
use super::*;
use crate::livekit_signaller::LiveKitSignaller;
#[derive(Default)]
pub struct LiveKitWebRTCSrc;
@ -1311,7 +1322,9 @@ impl ObjectImpl for LiveKitWebRTCSrc {
fn constructed(&self) {
self.parent_constructed();
let element = self.obj();
let ws = element.upcast_ref::<super::BaseWebRTCSrc>().imp();
let ws = element
.upcast_ref::<crate::webrtcsrc::BaseWebRTCSrc>()
.imp();
let _ = ws.set_signaller(LiveKitSignaller::new_consumer().upcast());
}
@ -1341,6 +1354,7 @@ impl BaseWebRTCSrcImpl for LiveKitWebRTCSrc {}
#[glib::object_subclass]
impl ObjectSubclass for LiveKitWebRTCSrc {
const NAME: &'static str = "GstLiveKitWebRTCSrc";
type Type = super::LiveKitWebRTCSrc;
type ParentType = super::BaseWebRTCSrc;
type Type = crate::webrtcsrc::LiveKitWebRTCSrc;
type ParentType = crate::webrtcsrc::BaseWebRTCSrc;
}
}

View file

@ -49,12 +49,14 @@ glib::wrapper! {
pub struct WebRTCSrc(ObjectSubclass<imp::WebRTCSrc>) @extends BaseWebRTCSrc, gst::Bin, gst::Element, gst::Object, @implements gst::URIHandler, gst::ChildProxy;
}
#[cfg(feature = "whip")]
glib::wrapper! {
pub struct WhipServerSrc(ObjectSubclass<imp::WhipServerSrc>) @extends BaseWebRTCSrc, gst::Bin, gst::Element, gst::Object, @implements gst::URIHandler, gst::ChildProxy;
pub struct WhipServerSrc(ObjectSubclass<imp::whip::WhipServerSrc>) @extends BaseWebRTCSrc, gst::Bin, gst::Element, gst::Object, @implements gst::URIHandler, gst::ChildProxy;
}
#[cfg(feature = "livekit")]
glib::wrapper! {
pub struct LiveKitWebRTCSrc(ObjectSubclass<imp::LiveKitWebRTCSrc>) @extends BaseWebRTCSrc, gst::Bin, gst::Element, gst::Object, gst::ChildProxy;
pub struct LiveKitWebRTCSrc(ObjectSubclass<imp::livekit::LiveKitWebRTCSrc>) @extends BaseWebRTCSrc, gst::Bin, gst::Element, gst::Object, gst::ChildProxy;
}
glib::wrapper! {
@ -73,6 +75,7 @@ pub fn register(plugin: Option<&gst::Plugin>) -> Result<(), glib::BoolError> {
WebRTCSrc::static_type(),
)?;
#[cfg(feature = "whip")]
gst::Element::register(
plugin,
"whipserversrc",
@ -80,6 +83,7 @@ pub fn register(plugin: Option<&gst::Plugin>) -> Result<(), glib::BoolError> {
WhipServerSrc::static_type(),
)?;
#[cfg(feature = "livekit")]
/**
* element-livekitwebrtcsrc:
*