Remove unnecessary mutexes from livekit client types
Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
ab6cd1d93a
commit
128a8ff0b9
1 changed files with 27 additions and 33 deletions
|
@ -164,29 +164,26 @@ pub enum ConnectionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
native_room: Mutex<swift::Room>,
|
native_room: swift::Room,
|
||||||
connection: Mutex<(
|
connection: Mutex<(
|
||||||
watch::Sender<ConnectionState>,
|
watch::Sender<ConnectionState>,
|
||||||
watch::Receiver<ConnectionState>,
|
watch::Receiver<ConnectionState>,
|
||||||
)>,
|
)>,
|
||||||
remote_audio_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteAudioTrackUpdate>>>,
|
remote_audio_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteAudioTrackUpdate>>>,
|
||||||
remote_video_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteVideoTrackUpdate>>>,
|
remote_video_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteVideoTrackUpdate>>>,
|
||||||
_delegate: Mutex<RoomDelegate>,
|
_delegate: RoomDelegate,
|
||||||
}
|
}
|
||||||
|
|
||||||
trait AssertSendSync: Send {}
|
|
||||||
impl AssertSendSync for Room {}
|
|
||||||
|
|
||||||
impl Room {
|
impl Room {
|
||||||
pub fn new() -> Arc<Self> {
|
pub fn new() -> Arc<Self> {
|
||||||
Arc::new_cyclic(|weak_room| {
|
Arc::new_cyclic(|weak_room| {
|
||||||
let delegate = RoomDelegate::new(weak_room.clone());
|
let delegate = RoomDelegate::new(weak_room.clone());
|
||||||
Self {
|
Self {
|
||||||
native_room: Mutex::new(unsafe { LKRoomCreate(delegate.native_delegate) }),
|
native_room: unsafe { LKRoomCreate(delegate.native_delegate) },
|
||||||
connection: Mutex::new(watch::channel_with(ConnectionState::Disconnected)),
|
connection: Mutex::new(watch::channel_with(ConnectionState::Disconnected)),
|
||||||
remote_audio_track_subscribers: Default::default(),
|
remote_audio_track_subscribers: Default::default(),
|
||||||
remote_video_track_subscribers: Default::default(),
|
remote_video_track_subscribers: Default::default(),
|
||||||
_delegate: Mutex::new(delegate),
|
_delegate: delegate,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -201,7 +198,7 @@ impl Room {
|
||||||
let (did_connect, tx, rx) = Self::build_done_callback();
|
let (did_connect, tx, rx) = Self::build_done_callback();
|
||||||
unsafe {
|
unsafe {
|
||||||
LKRoomConnect(
|
LKRoomConnect(
|
||||||
*self.native_room.lock(),
|
self.native_room,
|
||||||
url.as_concrete_TypeRef(),
|
url.as_concrete_TypeRef(),
|
||||||
token.as_concrete_TypeRef(),
|
token.as_concrete_TypeRef(),
|
||||||
did_connect,
|
did_connect,
|
||||||
|
@ -271,7 +268,7 @@ impl Room {
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
LKRoomPublishVideoTrack(
|
LKRoomPublishVideoTrack(
|
||||||
*self.native_room.lock(),
|
self.native_room,
|
||||||
track.0,
|
track.0,
|
||||||
callback,
|
callback,
|
||||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||||
|
@ -301,7 +298,7 @@ impl Room {
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
LKRoomPublishAudioTrack(
|
LKRoomPublishAudioTrack(
|
||||||
*self.native_room.lock(),
|
self.native_room,
|
||||||
track.0,
|
track.0,
|
||||||
callback,
|
callback,
|
||||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||||
|
@ -312,14 +309,14 @@ impl Room {
|
||||||
|
|
||||||
pub fn unpublish_track(&self, publication: LocalTrackPublication) {
|
pub fn unpublish_track(&self, publication: LocalTrackPublication) {
|
||||||
unsafe {
|
unsafe {
|
||||||
LKRoomUnpublishTrack(*self.native_room.lock(), publication.0);
|
LKRoomUnpublishTrack(self.native_room, publication.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remote_video_tracks(&self, participant_id: &str) -> Vec<Arc<RemoteVideoTrack>> {
|
pub fn remote_video_tracks(&self, participant_id: &str) -> Vec<Arc<RemoteVideoTrack>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let tracks = LKRoomVideoTracksForRemoteParticipant(
|
let tracks = LKRoomVideoTracksForRemoteParticipant(
|
||||||
*self.native_room.lock(),
|
self.native_room,
|
||||||
CFString::new(participant_id).as_concrete_TypeRef(),
|
CFString::new(participant_id).as_concrete_TypeRef(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -348,7 +345,7 @@ impl Room {
|
||||||
pub fn remote_audio_tracks(&self, participant_id: &str) -> Vec<Arc<RemoteAudioTrack>> {
|
pub fn remote_audio_tracks(&self, participant_id: &str) -> Vec<Arc<RemoteAudioTrack>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let tracks = LKRoomAudioTracksForRemoteParticipant(
|
let tracks = LKRoomAudioTracksForRemoteParticipant(
|
||||||
*self.native_room.lock(),
|
self.native_room,
|
||||||
CFString::new(participant_id).as_concrete_TypeRef(),
|
CFString::new(participant_id).as_concrete_TypeRef(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -380,7 +377,7 @@ impl Room {
|
||||||
) -> Vec<Arc<RemoteTrackPublication>> {
|
) -> Vec<Arc<RemoteTrackPublication>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let tracks = LKRoomAudioTrackPublicationsForRemoteParticipant(
|
let tracks = LKRoomAudioTrackPublicationsForRemoteParticipant(
|
||||||
*self.native_room.lock(),
|
self.native_room,
|
||||||
CFString::new(participant_id).as_concrete_TypeRef(),
|
CFString::new(participant_id).as_concrete_TypeRef(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -508,9 +505,8 @@ impl Room {
|
||||||
impl Drop for Room {
|
impl Drop for Room {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let native_room = &*self.native_room.lock();
|
LKRoomDisconnect(self.native_room);
|
||||||
LKRoomDisconnect(*native_room);
|
CFRelease(self.native_room.0);
|
||||||
CFRelease(native_room.0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -726,7 +722,7 @@ impl Drop for LocalTrackPublication {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RemoteTrackPublication {
|
pub struct RemoteTrackPublication {
|
||||||
native_publication: Mutex<swift::RemoteTrackPublication>,
|
native_publication: swift::RemoteTrackPublication,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RemoteTrackPublication {
|
impl RemoteTrackPublication {
|
||||||
|
@ -735,21 +731,19 @@ impl RemoteTrackPublication {
|
||||||
CFRetain(native_track_publication.0);
|
CFRetain(native_track_publication.0);
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
native_publication: Mutex::new(native_track_publication),
|
native_publication: native_track_publication,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sid(&self) -> String {
|
pub fn sid(&self) -> String {
|
||||||
unsafe {
|
unsafe {
|
||||||
CFString::wrap_under_get_rule(LKRemoteTrackPublicationGetSid(
|
CFString::wrap_under_get_rule(LKRemoteTrackPublicationGetSid(self.native_publication))
|
||||||
*self.native_publication.lock(),
|
|
||||||
))
|
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_muted(&self) -> bool {
|
pub fn is_muted(&self) -> bool {
|
||||||
unsafe { LKRemoteTrackPublicationIsMuted(*self.native_publication.lock()) }
|
unsafe { LKRemoteTrackPublicationIsMuted(self.native_publication) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_enabled(&self, enabled: bool) -> impl Future<Output = Result<()>> {
|
pub fn set_enabled(&self, enabled: bool) -> impl Future<Output = Result<()>> {
|
||||||
|
@ -767,7 +761,7 @@ impl RemoteTrackPublication {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
LKRemoteTrackPublicationSetEnabled(
|
LKRemoteTrackPublicationSetEnabled(
|
||||||
*self.native_publication.lock(),
|
self.native_publication,
|
||||||
enabled,
|
enabled,
|
||||||
complete_callback,
|
complete_callback,
|
||||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||||
|
@ -780,13 +774,13 @@ impl RemoteTrackPublication {
|
||||||
|
|
||||||
impl Drop for RemoteTrackPublication {
|
impl Drop for RemoteTrackPublication {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { CFRelease((*self.native_publication.lock()).0) }
|
unsafe { CFRelease(self.native_publication.0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RemoteAudioTrack {
|
pub struct RemoteAudioTrack {
|
||||||
native_track: Mutex<swift::RemoteAudioTrack>,
|
native_track: swift::RemoteAudioTrack,
|
||||||
sid: Sid,
|
sid: Sid,
|
||||||
publisher_id: String,
|
publisher_id: String,
|
||||||
}
|
}
|
||||||
|
@ -797,7 +791,7 @@ impl RemoteAudioTrack {
|
||||||
CFRetain(native_track.0);
|
CFRetain(native_track.0);
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
native_track: Mutex::new(native_track),
|
native_track,
|
||||||
sid,
|
sid,
|
||||||
publisher_id,
|
publisher_id,
|
||||||
}
|
}
|
||||||
|
@ -822,13 +816,13 @@ impl RemoteAudioTrack {
|
||||||
|
|
||||||
impl Drop for RemoteAudioTrack {
|
impl Drop for RemoteAudioTrack {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { CFRelease(self.native_track.lock().0) }
|
unsafe { CFRelease(self.native_track.0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RemoteVideoTrack {
|
pub struct RemoteVideoTrack {
|
||||||
native_track: Mutex<swift::RemoteVideoTrack>,
|
native_track: swift::RemoteVideoTrack,
|
||||||
sid: Sid,
|
sid: Sid,
|
||||||
publisher_id: String,
|
publisher_id: String,
|
||||||
}
|
}
|
||||||
|
@ -839,7 +833,7 @@ impl RemoteVideoTrack {
|
||||||
CFRetain(native_track.0);
|
CFRetain(native_track.0);
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
native_track: Mutex::new(native_track),
|
native_track,
|
||||||
sid,
|
sid,
|
||||||
publisher_id,
|
publisher_id,
|
||||||
}
|
}
|
||||||
|
@ -888,7 +882,7 @@ impl RemoteVideoTrack {
|
||||||
on_frame,
|
on_frame,
|
||||||
on_drop,
|
on_drop,
|
||||||
);
|
);
|
||||||
LKVideoTrackAddRenderer(*self.native_track.lock(), renderer);
|
LKVideoTrackAddRenderer(self.native_track, renderer);
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -896,7 +890,7 @@ impl RemoteVideoTrack {
|
||||||
|
|
||||||
impl Drop for RemoteVideoTrack {
|
impl Drop for RemoteVideoTrack {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { CFRelease(self.native_track.lock().0) }
|
unsafe { CFRelease(self.native_track.0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue