use crate::signaller::Signallable;
use gst::glib;
use gst::prelude::*;
use gst::subclass::prelude::*;
mod homegrown_cc;
mod imp;
mod pad;
glib::wrapper! {
pub struct BaseWebRTCSink(ObjectSubclass<imp::BaseWebRTCSink>) @extends gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
glib::wrapper! {
pub struct WebRTCSinkPad(ObjectSubclass<pad::WebRTCSinkPad>) @extends gst::GhostPad, gst::ProxyPad, gst::Pad, gst::Object;
}
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::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::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::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::janus::JanusVRWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[cfg(feature = "whep")]
glib::wrapper! {
pub struct WhepWebRTCSink(ObjectSubclass<imp::whep::WhepWebRTCSink>) @extends BaseWebRTCSink, gst::Bin, gst::Element, gst::Object, @implements gst::ChildProxy, gst_video::Navigation;
}
#[derive(thiserror::Error, Debug)]
pub enum WebRTCSinkError {
#[error("no session with id")]
NoSessionWithId(String),
#[error("consumer refused media")]
ConsumerRefusedMedia { session_id: String, media_idx: u32 },
#[error("consumer did not provide valid payload for media")]
ConsumerNoValidPayload { session_id: String, media_idx: u32 },
#[error("SDP mline index is currently mandatory")]
MandatorySdpMlineIndex,
#[error("duplicate session id")]
DuplicateSessionId(String),
#[error("error setting up consumer pipeline")]
SessionPipelineError {
session_id: String,
peer_id: String,
details: String,
},
#[error("Bitrate handling currently not supported for requested encoder")]
BitrateNotSupported,
}
impl Default for BaseWebRTCSink {
fn default() -> Self {
glib::Object::new()
}
}
impl BaseWebRTCSink {
pub fn with_signaller(signaller: Signallable) -> Self {
let ret: BaseWebRTCSink = glib::Object::new();
let ws = ret.imp();
ws.set_signaller(signaller).unwrap();
ret
}
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
#[repr(u32)]
#[enum_type(name = "GstWebRTCSinkCongestionControl")]
pub enum WebRTCSinkCongestionControl {
#[enum_value(name = "Disabled: no congestion control is applied", nick = "disabled")]
Disabled,
#[enum_value(name = "Homegrown: simple sender-side heuristic", nick = "homegrown")]
Homegrown,
#[enum_value(name = "Google Congestion Control algorithm", nick = "gcc")]
GoogleCongestionControl,
}
#[glib::flags(name = "GstWebRTCSinkMitigationMode")]
pub enum WebRTCSinkMitigationMode {
#[flags_value(name = "No mitigation applied", nick = "none")]
NONE = 0b00000000,
#[flags_value(name = "Lowered resolution", nick = "downscaled")]
DOWNSCALED = 0b00000001,
#[flags_value(name = "Lowered framerate", nick = "downsampled")]
DOWNSAMPLED = 0b00000010,
}
#[derive(Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
#[repr(u32)]
#[enum_type(name = "GstJanusVRWebRTCJanusState")]
pub enum JanusVRSignallerState {
#[default]
Initialized,
SessionCreated,
VideoroomAttached,
RoomJoined,
Negotiating,
WebrtcUp,
}
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
WebRTCSinkPad::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
BaseWebRTCSink::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
WebRTCSinkCongestionControl::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
WebRTCSinkMitigationMode::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
gst::Element::register(
Some(plugin),
"webrtcsink",
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")]
gst::Element::register(
Some(plugin),
"janusvrwebrtcsink",
gst::Rank::NONE,
JanusVRWebRTCSink::static_type(),
)?;
#[cfg(feature = "whep")]
gst::Element::register(
Some(plugin),
"whepserversink",
gst::Rank::NONE,
WhepWebRTCSink::static_type(),
)?;
#[cfg(feature = "janus")]
JanusVRSignallerState::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
Ok(())
}