Add LiveKit APIs for starting and stopping audio tracks

This commit is contained in:
Max Brunsfeld 2024-01-12 14:46:17 -08:00
parent c2d56cd5f8
commit aa50f69940
3 changed files with 25 additions and 11 deletions

View file

@ -286,6 +286,18 @@ public func LKRemoteAudioTrackGetSid(track: UnsafeRawPointer) -> CFString {
return track.sid! as CFString
}
@_cdecl("LKRemoteAudioTrackStart")
public func LKRemoteAudioTrackStart(track: UnsafeRawPointer) {
let track = Unmanaged<RemoteAudioTrack>.fromOpaque(track).takeUnretainedValue()
track.start()
}
@_cdecl("LKRemoteAudioTrackStop")
public func LKRemoteAudioTrackStop(track: UnsafeRawPointer) {
let track = Unmanaged<RemoteAudioTrack>.fromOpaque(track).takeUnretainedValue()
track.stop()
}
@_cdecl("LKDisplaySources")
public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFArray?, CFString?) -> Void) {
MacOSScreenCapturer.sources(for: .display, includeCurrentApplication: false, preferredMethod: .legacy).then { displaySources in

View file

@ -18,8 +18,6 @@ use std::{
sync::{Arc, Weak},
};
// SAFETY: Most live kit types are threadsafe:
// https://github.com/livekit/client-sdk-swift#thread-safety
macro_rules! pointer_type {
($pointer_name:ident) => {
#[repr(transparent)]
@ -134,8 +132,10 @@ extern "C" {
) -> *const c_void;
fn LKRemoteAudioTrackGetSid(track: swift::RemoteAudioTrack) -> CFStringRef;
fn LKVideoTrackAddRenderer(track: swift::RemoteVideoTrack, renderer: *const c_void);
fn LKRemoteVideoTrackGetSid(track: swift::RemoteVideoTrack) -> CFStringRef;
fn LKRemoteAudioTrackStart(track: swift::RemoteAudioTrack);
fn LKRemoteAudioTrackStop(track: swift::RemoteAudioTrack);
fn LKVideoTrackAddRenderer(track: swift::RemoteVideoTrack, renderer: *const c_void);
fn LKDisplaySources(
callback_data: *mut c_void,
@ -853,12 +853,12 @@ impl RemoteAudioTrack {
&self.publisher_id
}
pub fn enable(&self) -> impl Future<Output = Result<()>> {
async { Ok(()) }
pub fn start(&self) {
unsafe { LKRemoteAudioTrackStart(self.native_track) }
}
pub fn disable(&self) -> impl Future<Output = Result<()>> {
async { Ok(()) }
pub fn stop(&self) {
unsafe { LKRemoteAudioTrackStop(self.native_track) }
}
}

View file

@ -262,6 +262,7 @@ impl TestServer {
let track = Arc::new(RemoteAudioTrack {
sid: sid.clone(),
publisher_id: identity.clone(),
running: AtomicBool::new(true),
});
let publication = Arc::new(RemoteTrackPublication);
@ -644,6 +645,7 @@ impl RemoteVideoTrack {
pub struct RemoteAudioTrack {
sid: Sid,
publisher_id: Sid,
running: AtomicBool,
}
impl RemoteAudioTrack {
@ -655,12 +657,12 @@ impl RemoteAudioTrack {
&self.publisher_id
}
pub fn enable(&self) -> impl Future<Output = Result<()>> {
async { Ok(()) }
pub fn start(&self) {
self.running.store(true, SeqCst);
}
pub fn disable(&self) -> impl Future<Output = Result<()>> {
async { Ok(()) }
pub fn stop(&self) {
self.running.store(false, SeqCst);
}
}