mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-09-03 02:03:48 +00:00
webrtc: janus: inline VideoRoomData members
No need to have explicit extra structs. Make the Janus API easier to read. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2244>
This commit is contained in:
parent
1000035974
commit
8147ed59ad
1 changed files with 51 additions and 68 deletions
|
@ -182,48 +182,38 @@ struct InnerSlowLink {
|
||||||
lost: u64,
|
lost: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct RoomJoined {
|
|
||||||
room: JanusId,
|
|
||||||
id: JanusId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct RoomEvent {
|
|
||||||
room: Option<JanusId>,
|
|
||||||
error_code: Option<i32>,
|
|
||||||
error: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct RoomDestroyed {
|
|
||||||
room: JanusId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct RoomTalking {
|
|
||||||
room: JanusId,
|
|
||||||
id: JanusId,
|
|
||||||
#[serde(rename = "audio-level-dBov-avg")]
|
|
||||||
audio_level: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct SlowLink {
|
|
||||||
#[serde(rename = "current-bitrate")]
|
|
||||||
current_bitrate: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(tag = "videoroom", rename_all = "kebab-case")]
|
#[serde(tag = "videoroom", rename_all = "kebab-case")]
|
||||||
enum VideoRoomData {
|
enum VideoRoomData {
|
||||||
Joined(RoomJoined),
|
Joined {
|
||||||
Event(RoomEvent),
|
room: JanusId,
|
||||||
Destroyed(RoomDestroyed),
|
id: JanusId,
|
||||||
Talking(RoomTalking),
|
},
|
||||||
StoppedTalking(RoomTalking),
|
Event {
|
||||||
|
room: Option<JanusId>,
|
||||||
|
error_code: Option<i32>,
|
||||||
|
error: Option<String>,
|
||||||
|
},
|
||||||
|
Destroyed {
|
||||||
|
room: JanusId,
|
||||||
|
},
|
||||||
|
Talking {
|
||||||
|
room: JanusId,
|
||||||
|
id: JanusId,
|
||||||
|
#[serde(rename = "audio-level-dBov-avg")]
|
||||||
|
audio_level: f32,
|
||||||
|
},
|
||||||
|
StoppedTalking {
|
||||||
|
room: JanusId,
|
||||||
|
id: JanusId,
|
||||||
|
#[serde(rename = "audio-level-dBov-avg")]
|
||||||
|
audio_level: f32,
|
||||||
|
},
|
||||||
#[serde(rename = "slow_link")]
|
#[serde(rename = "slow_link")]
|
||||||
SlowLink(SlowLink),
|
SlowLink {
|
||||||
|
#[serde(rename = "current-bitrate")]
|
||||||
|
current_bitrate: u32,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -480,19 +470,19 @@ impl Signaller {
|
||||||
JsonReply::Event(event) => {
|
JsonReply::Event(event) => {
|
||||||
if let Some(PluginData::VideoRoom { data: plugindata }) = event.plugindata {
|
if let Some(PluginData::VideoRoom { data: plugindata }) = event.plugindata {
|
||||||
match plugindata {
|
match plugindata {
|
||||||
VideoRoomData::Joined(joined) => {
|
VideoRoomData::Joined { room, id } => {
|
||||||
let feed_id_changed = {
|
let feed_id_changed = {
|
||||||
let mut feed_id_changed = false;
|
let mut feed_id_changed = false;
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
{
|
{
|
||||||
let mut settings = self.settings.lock().unwrap();
|
let mut settings = self.settings.lock().unwrap();
|
||||||
if settings.feed_id.as_ref() != Some(&joined.id) {
|
if settings.feed_id.as_ref() != Some(&id) {
|
||||||
settings.feed_id = Some(joined.id.clone());
|
settings.feed_id = Some(id.clone());
|
||||||
feed_id_changed = true;
|
feed_id_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.feed_id = Some(joined.id);
|
state.feed_id = Some(id);
|
||||||
|
|
||||||
feed_id_changed
|
feed_id_changed
|
||||||
};
|
};
|
||||||
|
@ -501,12 +491,7 @@ impl Signaller {
|
||||||
self.obj().notify("feed-id");
|
self.obj().notify("feed-id");
|
||||||
}
|
}
|
||||||
|
|
||||||
gst::trace!(
|
gst::trace!(CAT, imp = self, "Joined room {room:?} successfully",);
|
||||||
CAT,
|
|
||||||
imp = self,
|
|
||||||
"Joined room {:?} successfully",
|
|
||||||
joined.room
|
|
||||||
);
|
|
||||||
|
|
||||||
self.obj().emit_by_name::<()>(
|
self.obj().emit_by_name::<()>(
|
||||||
"state-updated",
|
"state-updated",
|
||||||
|
@ -515,12 +500,14 @@ impl Signaller {
|
||||||
|
|
||||||
self.session_requested();
|
self.session_requested();
|
||||||
}
|
}
|
||||||
VideoRoomData::Event(room_event) => {
|
VideoRoomData::Event {
|
||||||
if room_event.error_code.is_some() && room_event.error.is_some() {
|
error, error_code, ..
|
||||||
|
} => {
|
||||||
|
if error_code.is_some() && error.is_some() {
|
||||||
self.raise_error(format!(
|
self.raise_error(format!(
|
||||||
"code: {}, reason: {}",
|
"code: {}, reason: {}",
|
||||||
room_event.error_code.unwrap(),
|
error_code.unwrap(),
|
||||||
room_event.error.unwrap(),
|
error.unwrap(),
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -530,26 +517,22 @@ impl Signaller {
|
||||||
self.handle_answer(sdp);
|
self.handle_answer(sdp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VideoRoomData::Destroyed(room_destroyed) => {
|
VideoRoomData::Destroyed { room } => {
|
||||||
gst::trace!(
|
gst::trace!(CAT, imp = self, "Room {room} has been destroyed",);
|
||||||
CAT,
|
|
||||||
imp = self,
|
|
||||||
"Room {} has been destroyed",
|
|
||||||
room_destroyed.room
|
|
||||||
);
|
|
||||||
|
|
||||||
self.raise_error(format!(
|
self.raise_error(format!("room {room} has been destroyed",));
|
||||||
"room {} has been destroyed",
|
|
||||||
room_destroyed.room
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
VideoRoomData::Talking(talking) => {
|
VideoRoomData::Talking {
|
||||||
self.emit_talking(true, talking.id, talking.audio_level);
|
id, audio_level, ..
|
||||||
|
} => {
|
||||||
|
self.emit_talking(true, id, audio_level);
|
||||||
}
|
}
|
||||||
VideoRoomData::StoppedTalking(talking) => {
|
VideoRoomData::StoppedTalking {
|
||||||
self.emit_talking(false, talking.id, talking.audio_level);
|
id, audio_level, ..
|
||||||
|
} => {
|
||||||
|
self.emit_talking(false, id, audio_level);
|
||||||
}
|
}
|
||||||
VideoRoomData::SlowLink(_slow_link) => {
|
VideoRoomData::SlowLink { .. } => {
|
||||||
// TODO: use to reduce the bitrate?
|
// TODO: use to reduce the bitrate?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue