Add LiveKit APIs for starting and stopping audio tracks
This commit is contained in:
parent
c2d56cd5f8
commit
aa50f69940
3 changed files with 25 additions and 11 deletions
|
@ -286,6 +286,18 @@ public func LKRemoteAudioTrackGetSid(track: UnsafeRawPointer) -> CFString {
|
||||||
return track.sid! as 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")
|
@_cdecl("LKDisplaySources")
|
||||||
public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFArray?, CFString?) -> Void) {
|
public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFArray?, CFString?) -> Void) {
|
||||||
MacOSScreenCapturer.sources(for: .display, includeCurrentApplication: false, preferredMethod: .legacy).then { displaySources in
|
MacOSScreenCapturer.sources(for: .display, includeCurrentApplication: false, preferredMethod: .legacy).then { displaySources in
|
||||||
|
|
|
@ -18,8 +18,6 @@ use std::{
|
||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
// SAFETY: Most live kit types are threadsafe:
|
|
||||||
// https://github.com/livekit/client-sdk-swift#thread-safety
|
|
||||||
macro_rules! pointer_type {
|
macro_rules! pointer_type {
|
||||||
($pointer_name:ident) => {
|
($pointer_name:ident) => {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
@ -134,8 +132,10 @@ extern "C" {
|
||||||
) -> *const c_void;
|
) -> *const c_void;
|
||||||
|
|
||||||
fn LKRemoteAudioTrackGetSid(track: swift::RemoteAudioTrack) -> CFStringRef;
|
fn LKRemoteAudioTrackGetSid(track: swift::RemoteAudioTrack) -> CFStringRef;
|
||||||
fn LKVideoTrackAddRenderer(track: swift::RemoteVideoTrack, renderer: *const c_void);
|
|
||||||
fn LKRemoteVideoTrackGetSid(track: swift::RemoteVideoTrack) -> CFStringRef;
|
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(
|
fn LKDisplaySources(
|
||||||
callback_data: *mut c_void,
|
callback_data: *mut c_void,
|
||||||
|
@ -853,12 +853,12 @@ impl RemoteAudioTrack {
|
||||||
&self.publisher_id
|
&self.publisher_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable(&self) -> impl Future<Output = Result<()>> {
|
pub fn start(&self) {
|
||||||
async { Ok(()) }
|
unsafe { LKRemoteAudioTrackStart(self.native_track) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable(&self) -> impl Future<Output = Result<()>> {
|
pub fn stop(&self) {
|
||||||
async { Ok(()) }
|
unsafe { LKRemoteAudioTrackStop(self.native_track) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,6 +262,7 @@ impl TestServer {
|
||||||
let track = Arc::new(RemoteAudioTrack {
|
let track = Arc::new(RemoteAudioTrack {
|
||||||
sid: sid.clone(),
|
sid: sid.clone(),
|
||||||
publisher_id: identity.clone(),
|
publisher_id: identity.clone(),
|
||||||
|
running: AtomicBool::new(true),
|
||||||
});
|
});
|
||||||
|
|
||||||
let publication = Arc::new(RemoteTrackPublication);
|
let publication = Arc::new(RemoteTrackPublication);
|
||||||
|
@ -644,6 +645,7 @@ impl RemoteVideoTrack {
|
||||||
pub struct RemoteAudioTrack {
|
pub struct RemoteAudioTrack {
|
||||||
sid: Sid,
|
sid: Sid,
|
||||||
publisher_id: Sid,
|
publisher_id: Sid,
|
||||||
|
running: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RemoteAudioTrack {
|
impl RemoteAudioTrack {
|
||||||
|
@ -655,12 +657,12 @@ impl RemoteAudioTrack {
|
||||||
&self.publisher_id
|
&self.publisher_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable(&self) -> impl Future<Output = Result<()>> {
|
pub fn start(&self) {
|
||||||
async { Ok(()) }
|
self.running.store(true, SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable(&self) -> impl Future<Output = Result<()>> {
|
pub fn stop(&self) {
|
||||||
async { Ok(()) }
|
self.running.store(false, SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue