feat: basic ffi server to support other languages (#34)

* wip

* wip

* wip

* wip

not a fan of the way I do handles ..

* errors and async semantic

* fix example
This commit is contained in:
Théo Monnom
2023-01-25 00:09:19 +01:00
committed by GitHub
parent 84d2f234f5
commit 1610f86316
24 changed files with 1231 additions and 66 deletions
+2
View File
@@ -23,4 +23,6 @@ pub use crate::webrtc::{
},
rtp_receiver::RtpReceiver,
rtp_transceiver::RtpTransceiver,
video_frame::{VideoFrame, VideoRotation},
video_frame_buffer::{VideoFrameBuffer, VideoFrameBufferTrait, VideoFrameBufferType},
};
+4
View File
@@ -49,8 +49,12 @@ pub struct ParticipantIdentity(String);
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct TrackSid(String);
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct RoomSid(String);
id_str! {
ParticipantSid;
ParticipantIdentity;
TrackSid;
RoomSid;
}
+3 -3
View File
@@ -5,7 +5,7 @@ use crate::rtc_engine::{EngineEvent, EngineEvents, EngineResult, RTCEngine};
use crate::signal_client::SignalOptions;
use crate::{RoomError, RoomEvent, RoomResult, SimulateScenario};
use livekit_utils::observer::Dispatcher;
use parking_lot::{Mutex, RwLock};
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use std::collections::HashMap;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::Arc;
@@ -149,8 +149,8 @@ impl RoomSession {
self.inner.state.load(Ordering::Acquire).try_into().unwrap()
}
pub fn participants(&self) -> &RwLock<HashMap<ParticipantSid, Arc<RemoteParticipant>>> {
&self.inner.participants
pub fn participants(&self) -> RwLockReadGuard<HashMap<ParticipantSid, Arc<RemoteParticipant>>> {
self.inner.participants.read()
}
pub async fn simulate_scenario(&self, scenario: SimulateScenario) -> EngineResult<()> {
+3
View File
@@ -1,3 +1,4 @@
use super::impl_track_trait;
use crate::prelude::*;
use std::sync::Arc;
@@ -27,3 +28,5 @@ impl TryFrom<TrackHandle> for AudioTrackHandle {
}
}
}
impl_track_trait!(AudioTrackHandle, enum_dispatch, [Local, Remote]);
+3
View File
@@ -1,3 +1,4 @@
use super::impl_track_trait;
use crate::prelude::*;
use std::sync::Arc;
@@ -27,3 +28,5 @@ impl TryFrom<TrackHandle> for LocalTrackHandle {
}
}
}
impl_track_trait!(LocalTrackHandle, enum_dispatch, [Audio, Video]);
+25
View File
@@ -117,6 +117,7 @@ pub trait TrackTrait {
fn name(&self) -> String;
fn kind(&self) -> TrackKind;
fn stream_state(&self) -> StreamState;
fn muted(&self) -> bool;
fn start(&self);
fn stop(&self);
fn register_observer(&self) -> mpsc::UnboundedReceiver<TrackEvent>;
@@ -201,6 +202,7 @@ impl TrackTrait for TrackHandle {
fnc!(name, &Self, [], String);
fnc!(kind, &Self, [], TrackKind);
fnc!(stream_state, &Self, [], StreamState);
fnc!(muted, &Self, [], bool);
fnc!(start, &Self, [], ());
fnc!(stop, &Self, [], ());
fnc!(register_observer, &Self, [], mpsc::UnboundedReceiver<TrackEvent>);
@@ -246,6 +248,10 @@ macro_rules! impl_track_trait {
self.shared.stream_state.load(Ordering::SeqCst).into()
}
fn muted(&self) -> bool {
self.shared.muted.load(Ordering::SeqCst)
}
fn start(&self) {
self.shared.start();
}
@@ -263,6 +269,25 @@ macro_rules! impl_track_trait {
}
}
};
($x:ident, enum_dispatch, [$($variant:ident),+]) => {
use livekit_utils::enum_dispatch;
use tokio::sync::mpsc;
impl TrackTrait for $x {
enum_dispatch!(
[$($variant),+]
fnc!(sid, &Self, [], TrackSid);
fnc!(name, &Self, [], String);
fnc!(kind, &Self, [], TrackKind);
fnc!(stream_state, &Self, [], StreamState);
fnc!(muted, &Self, [], bool);
fnc!(start, &Self, [], ());
fnc!(stop, &Self, [], ());
fnc!(register_observer, &Self, [], mpsc::UnboundedReceiver<TrackEvent>);
fnc!(set_muted, &Self, [muted: bool], ());
);
}
};
}
pub(super) use impl_track_trait;
+3 -16
View File
@@ -1,7 +1,6 @@
use super::impl_track_trait;
use crate::prelude::*;
use livekit_utils::enum_dispatch;
use std::sync::Arc;
use tokio::sync::mpsc;
#[derive(Clone, Debug)]
pub enum RemoteTrackHandle {
@@ -9,20 +8,6 @@ pub enum RemoteTrackHandle {
Video(Arc<RemoteVideoTrack>),
}
impl TrackTrait for RemoteTrackHandle {
enum_dispatch!(
[Audio, Video]
fnc!(sid, &Self, [], TrackSid);
fnc!(name, &Self, [], String);
fnc!(kind, &Self, [], TrackKind);
fnc!(stream_state, &Self, [], StreamState);
fnc!(start, &Self, [], ());
fnc!(stop, &Self, [], ());
fnc!(register_observer, &Self, [], mpsc::UnboundedReceiver<TrackEvent>);
fnc!(set_muted, &Self, [muted: bool], ());
);
}
impl From<RemoteTrackHandle> for TrackHandle {
fn from(remote_track: RemoteTrackHandle) -> Self {
match remote_track {
@@ -43,3 +28,5 @@ impl TryFrom<TrackHandle> for RemoteTrackHandle {
}
}
}
impl_track_trait!(RemoteTrackHandle, enum_dispatch, [Audio, Video]);
+3
View File
@@ -1,3 +1,4 @@
use super::impl_track_trait;
use crate::prelude::*;
use std::sync::Arc;
@@ -27,3 +28,5 @@ impl TryFrom<TrackHandle> for VideoTrackHandle {
}
}
}
impl_track_trait!(VideoTrackHandle, enum_dispatch, [Local, Remote]);