Merge branch '510-janus-state' into 'main'

webrtc: janus: add 'janus-state' property to the signaller

Closes #510

See merge request gstreamer/gst-plugins-rs!1505
This commit is contained in:
Guillaume Desmottes 2024-04-27 00:09:16 +00:00
commit aeaa0cc58c
2 changed files with 62 additions and 3 deletions

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
use crate::signaller::{Signallable, SignallableImpl};
use crate::webrtcsink::JanusVRSignallerState;
use crate::RUNTIME;
use anyhow::{anyhow, Error};
@ -268,6 +269,7 @@ struct State {
transaction_id: Option<String>,
room_id: Option<JanusId>,
feed_id: Option<JanusId>,
janus_state: JanusVRSignallerState,
}
#[derive(Clone)]
@ -294,6 +296,20 @@ impl Default for Settings {
#[derive(Default, Properties)]
#[properties(wrapper_type = super::JanusVRSignaller)]
pub struct Signaller {
/**
* GstJanusVRWebRTCSignaller:janus-state:
*
* The current state of the signaller.
* Since: plugins-rs-0.14.0
*/
#[property(
name = "janus-state",
// FIXME: can't use `member =` with enums: https://github.com/gtk-rs/gtk-rs-core/issues/1338
get = |self_: &Self| self_.state.lock().unwrap().janus_state,
type = JanusVRSignallerState,
blurb = "The current state of the signaller",
builder(JanusVRSignallerState::Initialized)
)]
state: Mutex<State>,
#[property(name="janus-endpoint", get, set, type = String, member = janus_endpoint, blurb = "The Janus server endpoint to POST SDP offer to")]
#[property(name="display-name", get, set, type = String, member = display_name, blurb = "The name of the publisher in the Janus Video Room")]
@ -445,6 +461,13 @@ impl Signaller {
match reply {
JsonReply::WebRTCUp => {
gst::trace!(CAT, imp: self, "WebRTC streaming is working!");
{
let mut state = self.state.lock().unwrap();
state.janus_state = JanusVRSignallerState::WebrtcUp;
}
self.obj().notify("janus-state");
}
JsonReply::Success(success) => {
if let Some(data) = success.data {
@ -457,6 +480,8 @@ impl Signaller {
self.set_handle_id(data.id);
self.join_room();
}
self.obj().notify("janus-state");
}
}
JsonReply::Event(event) => {
@ -482,7 +507,12 @@ impl Signaller {
}
gst::trace!(CAT, imp: self, "Joined room {:?} successfully", joined.room);
{
let mut state = self.state.lock().unwrap();
state.janus_state = JanusVRSignallerState::RoomJoined;
}
self.session_requested();
self.obj().notify("janus-state");
}
VideoRoomData::Event(room_event) => {
if room_event.error_code.is_some() && room_event.error.is_some() {
@ -569,11 +599,15 @@ impl Signaller {
}
fn set_session_id(&self, session_id: u64) {
self.state.lock().unwrap().session_id = Some(session_id);
let mut state = self.state.lock().unwrap();
state.session_id = Some(session_id);
state.janus_state = JanusVRSignallerState::SessionCreated;
}
fn set_handle_id(&self, handle_id: u64) {
self.state.lock().unwrap().handle_id = Some(handle_id);
let mut state = self.state.lock().unwrap();
state.handle_id = Some(handle_id);
state.janus_state = JanusVRSignallerState::VideoroomAttached;
}
fn attach_plugin(&self) {
@ -672,7 +706,7 @@ impl Signaller {
fn publish(&self, offer: &gst_webrtc::WebRTCSessionDescription) {
let (transaction, session_id, handle_id, apisecret) = {
let state = self.state.lock().unwrap();
let mut state = self.state.lock().unwrap();
let settings = self.settings.lock().unwrap();
if settings.room_id.is_none() {
@ -680,6 +714,8 @@ impl Signaller {
return;
}
state.janus_state = JanusVRSignallerState::Negotiating;
(
state.transaction_id.clone().unwrap(),
state.session_id.unwrap(),
@ -687,6 +723,8 @@ impl Signaller {
settings.secret_key.clone(),
)
};
self.obj().notify("janus-state");
let sdp_data = offer.sdp().as_text().unwrap();
self.send(OutgoingMessage::Publish(PublishMsg {
janus: "message".to_string(),

View file

@ -134,6 +134,26 @@ enum WebRTCSinkMitigationMode {
DOWNSAMPLED = 0b00000010,
}
#[derive(Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
#[repr(u32)]
#[enum_type(name = "GstJanusVRWebRTCJanusState")]
/// State of the Janus Signaller.
pub enum JanusVRSignallerState {
#[default]
/// Initial state when the signaller is created.
Initialized,
/// The Janus session has been created.
SessionCreated,
/// The session has been attached to the videoroom plugin.
VideoroomAttached,
/// The room has been joined.
RoomJoined,
/// The WebRTC stream is being negotiated.
Negotiating,
/// The WebRTC stream is streaming to Janus.
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());
@ -223,6 +243,7 @@ pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
* - This plugin supports both the legacy Video Room plugin as well as the `multistream` one;
* - If you see a warning in the logs related to `rtpgccbwe`, you're probably missing the `gst-plugin-rtp` in your system.
*/
JanusVRSignallerState::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
gst::Element::register(
Some(plugin),
"janusvrwebrtcsink",