changing computer ( started tracks )
I used my Mac on the company trip
This commit is contained in:
Submodule crates/livekit-core/protocol updated: dc2a7bc3a0...8449c11069
@@ -1,7 +1,6 @@
|
||||
use futures_util::future::BoxFuture;
|
||||
use parking_lot::lock_api::RwLockUpgradableReadGuard;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::sync::atomic::AtomicU8;
|
||||
@@ -36,6 +35,7 @@ pub enum RoomError {
|
||||
|
||||
type RoomResult<T> = Result<T, RoomError>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConnectionState {
|
||||
Disconnected,
|
||||
Connecting,
|
||||
|
||||
@@ -10,7 +10,7 @@ pub(super) struct ParticipantShared {
|
||||
pub(super) identity: Mutex<ParticipantIdentity>,
|
||||
pub(super) name: Mutex<String>,
|
||||
pub(super) metadata: Mutex<String>,
|
||||
pub(super) tracks: RwLock<HashMap<TrackSid, Arc<TrackPublication>>>,
|
||||
pub(super) tracks: RwLock<HashMap<TrackSid, TrackPublication>>,
|
||||
}
|
||||
|
||||
impl ParticipantShared {
|
||||
@@ -50,7 +50,7 @@ pub enum Participant {
|
||||
Remote(RemoteParticipant),
|
||||
}
|
||||
|
||||
macro_rules! shared_method {
|
||||
macro_rules! shared_getter {
|
||||
($x:ident, $ret:ident) => {
|
||||
fn $x(&self) -> $ret {
|
||||
match self {
|
||||
@@ -62,10 +62,10 @@ macro_rules! shared_method {
|
||||
}
|
||||
|
||||
impl ParticipantTrait for Participant {
|
||||
shared_method!(sid, ParticipantSid);
|
||||
shared_method!(identity, ParticipantIdentity);
|
||||
shared_method!(name, String);
|
||||
shared_method!(metadata, String);
|
||||
shared_getter!(sid, ParticipantSid);
|
||||
shared_getter!(identity, ParticipantIdentity);
|
||||
shared_getter!(name, String);
|
||||
shared_getter!(metadata, String);
|
||||
|
||||
fn update_info(&self, info: ParticipantInfo) {
|
||||
match self {
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
use std::sync::Arc;
|
||||
use crate::room::id::TrackSid;
|
||||
use crate::room::participant::{impl_participant_trait, ParticipantShared};
|
||||
use crate::room::track_publication::RemoteTrackPublication;
|
||||
use crate::room::track::{RemoteAudioTrack, RemoteTrack, RemoteVideoTrack, TrackKind};
|
||||
use crate::room::track_publication::{
|
||||
RemoteTrackPublication, TrackPublication, TrackPublicationTrait,
|
||||
};
|
||||
use livekit_webrtc::media_stream::MediaStreamTrack;
|
||||
use std::time::Duration;
|
||||
use tokio::time::{sleep, timeout};
|
||||
|
||||
const ADD_TRACK_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
|
||||
// It should be fine to add event listeners in this structure
|
||||
// Registering after should be ParticipantConnected is fine to avoid missing events
|
||||
pub struct RemoteParticipant {
|
||||
shared: ParticipantShared,
|
||||
}
|
||||
@@ -18,16 +29,54 @@ impl RemoteParticipant {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn add_subscribed_media_track() {
|
||||
pub(super) async fn add_subscribed_media_track(
|
||||
&self,
|
||||
sid: &TrackSid,
|
||||
media_track: MediaStreamTrack,
|
||||
) {
|
||||
let wait_publication = async {
|
||||
loop {
|
||||
let publication = self.get_track_publication(sid);
|
||||
if let Some(publication) = publication {
|
||||
return publication;
|
||||
}
|
||||
|
||||
sleep(Duration::from_millis(50)).await;
|
||||
}
|
||||
};
|
||||
|
||||
let res = timeout(ADD_TRACK_TIMEOUT, wait_publication).await;
|
||||
|
||||
if let Ok(remote_publication) = res {
|
||||
let track = match remote_publication.kind() {
|
||||
TrackKind::Audio => {
|
||||
let audio_track = RemoteAudioTrack::new();
|
||||
RemoteTrack::Audio(audio_track)
|
||||
}
|
||||
TrackKind::Video => {
|
||||
let video_track = RemoteVideoTrack::new();
|
||||
RemoteTrack::Video(video_track)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
||||
|
||||
// TODO(theomonnom): call OnTrackSubscribed here
|
||||
|
||||
} else {
|
||||
// TODO(theomonnom): send error
|
||||
}
|
||||
}
|
||||
|
||||
fn get_track_publication(&self, sid: &str) -> Option<RemoteTrackPublication> {
|
||||
let track = self.shared.tracks.read().get(&sid.to_string().into()).unwrap().clone();
|
||||
|
||||
|
||||
None
|
||||
fn get_track_publication(&self, sid: &TrackSid) -> Option<RemoteTrackPublication> {
|
||||
self.shared.tracks.read().get(sid).map(|track| {
|
||||
if let TrackPublication::Remote(remote) = track {
|
||||
remote.clone()
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,70 @@
|
||||
#[derive(Debug)]
|
||||
pub enum TrackKind {
|
||||
Unknown,
|
||||
Audio,
|
||||
Video
|
||||
Video,
|
||||
}
|
||||
|
||||
impl From<u8> for TrackKind {
|
||||
fn from(val: u8) -> Self {
|
||||
match val {
|
||||
1 => Self::Audio,
|
||||
2 => Self::Video,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum StreamState {
|
||||
Unknown,
|
||||
Active,
|
||||
Paused,
|
||||
Unknown
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TrackSource {
|
||||
Unknown,
|
||||
Camera,
|
||||
Microphone,
|
||||
Screenshare,
|
||||
ScreenshareAudio,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl From<u8> for TrackSource {
|
||||
fn from(val: u8) -> Self {
|
||||
match val {
|
||||
1 => Self::Camera,
|
||||
2 => Self::Microphone,
|
||||
3 => Self::Screenshare,
|
||||
4 => Self::ScreenshareAudio,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LocalVideoTrack {}
|
||||
pub struct RemoteVideoTrack {}
|
||||
pub struct LocalAudioTrack {}
|
||||
pub struct RemoteAudioTrack {}
|
||||
|
||||
|
||||
pub struct RemoteAudioTrack {
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl RemoteVideoTrack {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl RemoteAudioTrack {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum RemoteTrack {
|
||||
Audio(RemoteAudioTrack),
|
||||
Video(RemoteVideoTrack),
|
||||
@@ -1,7 +1,16 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8};
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use parking_lot::Mutex;
|
||||
use crate::room::id::TrackSid;
|
||||
use crate::room::id::{ParticipantIdentity, ParticipantSid, TrackSid};
|
||||
use crate::room::track::{TrackKind, TrackSource};
|
||||
|
||||
pub trait TrackPublicationTrait {
|
||||
fn name(&self) -> String;
|
||||
fn sid(&self) -> TrackSid;
|
||||
fn kind(&self) -> TrackKind;
|
||||
fn source(&self) -> TrackSource;
|
||||
fn simulcasted(&self) -> bool;
|
||||
}
|
||||
|
||||
pub(super) struct TrackPublicationShared {
|
||||
pub(super) name: Mutex<String>,
|
||||
@@ -11,6 +20,59 @@ pub(super) struct TrackPublicationShared {
|
||||
pub(super) simulcasted: AtomicBool
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum TrackPublication {
|
||||
Local(LocalTrackPublication),
|
||||
Remote(RemoteTrackPublication)
|
||||
}
|
||||
|
||||
macro_rules! shared_getter {
|
||||
($x:ident, $ret:ident) => {
|
||||
fn $x(&self) -> $ret {
|
||||
match self {
|
||||
TrackPublication::Local(p) => p.$x(),
|
||||
TrackPublication::Remote(p) => p.$x(),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl TrackPublicationTrait for TrackPublication {
|
||||
shared_getter!(name, String);
|
||||
shared_getter!(sid, TrackSid);
|
||||
shared_getter!(kind, TrackKind);
|
||||
shared_getter!(source, TrackSource);
|
||||
shared_getter!(simulcasted, bool);
|
||||
}
|
||||
|
||||
macro_rules! impl_publication_trait {
|
||||
($x:ident) => {
|
||||
impl TrackPublicationTrait for $x {
|
||||
fn name(&self) -> String {
|
||||
self.shared.name.lock().clone()
|
||||
}
|
||||
|
||||
fn sid(&self) -> TrackSid {
|
||||
self.shared.sid.lock().clone()
|
||||
}
|
||||
|
||||
fn kind(&self) -> TrackKind {
|
||||
self.shared.kind.load(Ordering::SeqCst).into()
|
||||
}
|
||||
|
||||
fn source(&self) -> TrackSource {
|
||||
self.shared.source.load(Ordering::SeqCst).into()
|
||||
}
|
||||
|
||||
fn simulcasted(&self) -> bool {
|
||||
self.shared.simulcasted.load(Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LocalTrackPublication {
|
||||
shared: Arc<TrackPublicationShared>
|
||||
@@ -21,8 +83,5 @@ pub struct RemoteTrackPublication {
|
||||
shared: Arc<TrackPublicationShared>
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum TrackPublication {
|
||||
Local(LocalTrackPublication),
|
||||
Remote(RemoteTrackPublication)
|
||||
}
|
||||
impl_publication_trait!(LocalTrackPublication);
|
||||
impl_publication_trait!(RemoteTrackPublication);
|
||||
|
||||
@@ -52,7 +52,7 @@ fn macos_link_search_path() -> Option<String> {
|
||||
|
||||
fn main() {
|
||||
// TODO Download precompiled binaries of WebRTC for the target_os
|
||||
let target_os = "windows";
|
||||
let target_os = "macos";
|
||||
//let target_arch = "arm64";
|
||||
|
||||
let libwebrtc_dir = path::PathBuf::from("libwebrtc");
|
||||
|
||||
Reference in New Issue
Block a user