livekit-utils crate + VideoRenderer proto
This commit is contained in:
@@ -7,6 +7,5 @@ pub mod proto {
|
||||
mod events;
|
||||
mod rtc_engine;
|
||||
mod signal_client;
|
||||
mod utils;
|
||||
|
||||
pub mod room;
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::room::id::{ParticipantIdentity, ParticipantSid, TrackSid};
|
||||
use crate::room::participant::local_participant::LocalParticipant;
|
||||
use crate::room::participant::remote_participant::RemoteParticipant;
|
||||
use crate::room::publication::{TrackPublication, TrackPublicationTrait};
|
||||
use crate::utils::wrap_variants;
|
||||
use futures_util::future::BoxFuture;
|
||||
use livekit_utils::enum_dispatch;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -74,7 +74,7 @@ pub enum ParticipantHandle {
|
||||
}
|
||||
|
||||
impl ParticipantHandle {
|
||||
// TODO(theomonnom): Add async support to wrap_variants ...
|
||||
// TODO(theomonnom): Add async support to wrap_variants ...
|
||||
pub(crate) async fn update_info(&self, info: ParticipantInfo) {
|
||||
match self {
|
||||
Self::Local(inner) => inner.clone().update_info(info).await,
|
||||
@@ -84,20 +84,20 @@ impl ParticipantHandle {
|
||||
}
|
||||
|
||||
impl ParticipantInternalTrait for ParticipantHandle {
|
||||
wrap_variants!(
|
||||
enum_dispatch!(
|
||||
[Local, Remote]
|
||||
fnc!(internal_events, Arc<ParticipantEvents>, []);
|
||||
fnc!(internal_events, &Self, [], Arc<ParticipantEvents>);
|
||||
);
|
||||
}
|
||||
|
||||
impl ParticipantTrait for ParticipantHandle {
|
||||
wrap_variants!(
|
||||
enum_dispatch!(
|
||||
[Local, Remote]
|
||||
fnc!(events, Arc<ParticipantEvents>, []);
|
||||
fnc!(sid, ParticipantSid, []);
|
||||
fnc!(identity, ParticipantIdentity, []);
|
||||
fnc!(name, String, []);
|
||||
fnc!(metadata, String, []);
|
||||
fnc!(events, &Self, [], Arc<ParticipantEvents>);
|
||||
fnc!(sid, &Self, [], ParticipantSid);
|
||||
fnc!(identity, &Self, [], ParticipantIdentity);
|
||||
fnc!(name, &Self, [], String);
|
||||
fnc!(metadata, &Self, [], String);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::room::id::TrackSid;
|
||||
use crate::room::track::local_track::LocalTrackHandle;
|
||||
use crate::room::track::remote_track::RemoteTrackHandle;
|
||||
use crate::room::track::{TrackHandle, TrackKind, TrackSource};
|
||||
use crate::utils::wrap_variants;
|
||||
use livekit_utils::enum_dispatch;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use std::sync::Arc;
|
||||
@@ -38,7 +38,11 @@ pub(super) struct TrackPublicationShared {
|
||||
}
|
||||
|
||||
impl TrackPublicationShared {
|
||||
pub fn new(info: TrackInfo, participant: ParticipantSid, track: Option<TrackHandle>) -> Arc<Self> {
|
||||
pub fn new(
|
||||
info: TrackInfo,
|
||||
participant: ParticipantSid,
|
||||
track: Option<TrackHandle>,
|
||||
) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
track: Mutex::new(track),
|
||||
name: Mutex::new(info.name),
|
||||
@@ -88,21 +92,21 @@ impl TrackPublication {
|
||||
}
|
||||
|
||||
impl TrackPublicationInternalTrait for TrackPublication {
|
||||
wrap_variants!(
|
||||
enum_dispatch!(
|
||||
[Local, Remote]
|
||||
fnc!(update_track, (), [track: Option<TrackHandle>]);
|
||||
fnc!(update_info, (), [info: TrackInfo]);
|
||||
fnc!(update_track, &Self, [track: Option<TrackHandle>], ());
|
||||
fnc!(update_info, &Self, [info: TrackInfo], ());
|
||||
);
|
||||
}
|
||||
|
||||
impl TrackPublicationTrait for TrackPublication {
|
||||
wrap_variants!(
|
||||
enum_dispatch!(
|
||||
[Local, Remote]
|
||||
fnc!(sid, TrackSid, []);
|
||||
fnc!(name, String, []);
|
||||
fnc!(kind, TrackKind, []);
|
||||
fnc!(source, TrackSource, []);
|
||||
fnc!(simulcasted, bool, []);
|
||||
fnc!(sid, &Self, [], TrackSid);
|
||||
fnc!(name, &Self, [], String);
|
||||
fnc!(kind, &Self, [], TrackKind);
|
||||
fnc!(source, &Self, [], TrackSource);
|
||||
fnc!(simulcasted, &Self, [], bool);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::room::track::local_audio_track::LocalAudioTrack;
|
||||
use crate::room::track::local_video_track::LocalVideoTrack;
|
||||
use crate::room::track::remote_audio_track::RemoteAudioTrack;
|
||||
use crate::room::track::remote_video_track::RemoteVideoTrack;
|
||||
use crate::utils::wrap_variants;
|
||||
use livekit_utils::enum_dispatch;
|
||||
use livekit_webrtc::media_stream::{MediaStreamTrackHandle, MediaStreamTrackTrait};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::atomic::AtomicU8;
|
||||
@@ -150,14 +150,14 @@ pub enum TrackHandle {
|
||||
}
|
||||
|
||||
impl TrackTrait for TrackHandle {
|
||||
wrap_variants!(
|
||||
enum_dispatch!(
|
||||
[LocalVideo, LocalAudio, RemoteVideo, RemoteAudio]
|
||||
fnc!(sid, TrackSid, []);
|
||||
fnc!(name, String, []);
|
||||
fnc!(kind, TrackKind, []);
|
||||
fnc!(stream_state, StreamState, []);
|
||||
fnc!(start, (), []);
|
||||
fnc!(stop, (), []);
|
||||
fnc!(sid, &Self, [], TrackSid);
|
||||
fnc!(name, &Self, [], String);
|
||||
fnc!(kind, &Self, [], TrackKind);
|
||||
fnc!(stream_state, &Self, [], StreamState);
|
||||
fnc!(start, &Self, [], ());
|
||||
fnc!(stop, &Self, [], ());
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::room::id::TrackSid;
|
||||
use crate::room::track::remote_audio_track::RemoteAudioTrack;
|
||||
use crate::room::track::remote_video_track::RemoteVideoTrack;
|
||||
use crate::room::track::TrackHandle;
|
||||
use crate::utils::wrap_variants;
|
||||
use livekit_utils::enum_dispatch;
|
||||
|
||||
use super::TrackTrait;
|
||||
|
||||
@@ -16,14 +16,14 @@ pub enum RemoteTrackHandle {
|
||||
}
|
||||
|
||||
impl TrackTrait for RemoteTrackHandle {
|
||||
wrap_variants!(
|
||||
enum_dispatch!(
|
||||
[Audio, Video]
|
||||
fnc!(sid, TrackSid, []);
|
||||
fnc!(name, String, []);
|
||||
fnc!(kind, TrackKind, []);
|
||||
fnc!(stream_state, StreamState, []);
|
||||
fnc!(start, (), []);
|
||||
fnc!(stop, (), []);
|
||||
fnc!(sid, &Self, [], TrackSid);
|
||||
fnc!(name, &Self, [], String);
|
||||
fnc!(kind, &Self, [], TrackKind);
|
||||
fnc!(stream_state, &Self, [], StreamState);
|
||||
fnc!(start, &Self, [], ());
|
||||
fnc!(stop, &Self, [], ());
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
macro_rules! wrap_variants {
|
||||
// This arm is used to avoid nested loops with the arguments
|
||||
// The arguments are transformed to $combined_args TokenTree
|
||||
(@match $self:ident $fnc:ident $combined_args:tt [$($variant:ident),+]) => {
|
||||
match $self {
|
||||
$(
|
||||
Self::$variant(inner) => inner.$fnc$combined_args,
|
||||
)+
|
||||
}
|
||||
};
|
||||
|
||||
($fnc:ident, $ret:ty, [$($arg:ident: $t:ty),*], [$($variant:ident),+]) => {
|
||||
fn $fnc(&self, $($arg: $t),*) -> $ret {
|
||||
wrap_variants!(@match self $fnc ($($arg,)*) [$($variant),+])
|
||||
}
|
||||
};
|
||||
|
||||
($variants:tt $(fnc!($fnc:ident, $ret:ty, $args:tt);)+) => {
|
||||
$(
|
||||
wrap_variants!($fnc, $ret, $args, $variants);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use wrap_variants;
|
||||
|
||||
Reference in New Issue
Block a user