From 4222f86537170c202ff7f13e8f69b7e642a979ea Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 14 Oct 2022 10:31:02 +0200 Subject: [PATCH] Temporarily use legacy screen capture API --- .../Sources/LiveKitBridge/LiveKitBridge.swift | 9 +--- crates/live_kit/src/live_kit.rs | 53 +------------------ 2 files changed, 2 insertions(+), 60 deletions(-) diff --git a/crates/live_kit/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift b/crates/live_kit/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift index 2fc35e4e8c..7109e6dcf3 100644 --- a/crates/live_kit/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift +++ b/crates/live_kit/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift @@ -86,17 +86,10 @@ public func LKRoomPublishVideoTrack(room: UnsafeRawPointer, track: UnsafeRawPoin } } -@_cdecl("LKCreateScreenShareTrackForWindow") -public func LKCreateScreenShareTrackForWindow(windowId: uint32) -> UnsafeMutableRawPointer { - let track = LocalVideoTrack.createMacOSScreenShareTrack(source: .window(id: windowId)) - return Unmanaged.passRetained(track).toOpaque() -} - @_cdecl("LKCreateScreenShareTrackForDisplay") public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { let display = Unmanaged.fromOpaque(display).takeRetainedValue() - print("!!!!!!!!!! display id", display.displayID) - let track = LocalVideoTrack.createMacOSScreenShareTrack(source: display) + let track = LocalVideoTrack.createMacOSScreenShareTrack(source: display, preferredMethod: .legacy) return Unmanaged.passRetained(track).toOpaque() } diff --git a/crates/live_kit/src/live_kit.rs b/crates/live_kit/src/live_kit.rs index 8cec1e2f65..f2d61c261a 100644 --- a/crates/live_kit/src/live_kit.rs +++ b/crates/live_kit/src/live_kit.rs @@ -1,15 +1,9 @@ use anyhow::{anyhow, Context, Result}; use core_foundation::{ array::{CFArray, CFArrayRef}, - base::{TCFType, TCFTypeRef}, - dictionary::CFDictionary, - number::CFNumber, + base::TCFType, string::{CFString, CFStringRef}, }; -use core_graphics::window::{ - kCGNullWindowID, kCGWindowListOptionExcludeDesktopElements, kCGWindowListOptionOnScreenOnly, - kCGWindowNumber, kCGWindowOwnerName, kCGWindowOwnerPID, CGWindowListCopyWindowInfo, -}; use futures::{ channel::{mpsc, oneshot}, Future, @@ -63,7 +57,6 @@ extern "C" { error: CFStringRef, ), ); - fn LKCreateScreenShareTrackForWindow(windowId: u32) -> *const c_void; fn LKCreateScreenShareTrackForDisplay(display: *const c_void) -> *const c_void; } @@ -194,10 +187,6 @@ impl Drop for RoomDelegate { pub struct LocalVideoTrack(*const c_void); impl LocalVideoTrack { - pub fn screen_share_for_window(window_id: u32) -> Self { - Self(unsafe { LKCreateScreenShareTrackForWindow(window_id) }) - } - pub fn screen_share_for_display(display: MacOSDisplay) -> Self { let ptr = display.0; let this = Self(unsafe { LKCreateScreenShareTrackForDisplay(ptr) }); @@ -251,46 +240,6 @@ impl Drop for RemoteVideoTrack { } } -#[derive(Debug)] -pub struct WindowInfo { - pub id: u32, - pub owner_pid: i32, - pub owner_name: Option, -} - -pub fn list_windows() -> Vec { - unsafe { - let dicts = CFArray::::wrap_under_get_rule(CGWindowListCopyWindowInfo( - kCGWindowListOptionOnScreenOnly | kCGWindowListOptionExcludeDesktopElements, - kCGNullWindowID, - )); - - dicts - .iter() - .map(|dict| { - let id = - CFNumber::wrap_under_get_rule(*dict.get(kCGWindowNumber.as_void_ptr()) as _) - .to_i64() - .unwrap() as u32; - - let owner_pid = - CFNumber::wrap_under_get_rule(*dict.get(kCGWindowOwnerPID.as_void_ptr()) as _) - .to_i32() - .unwrap(); - - let owner_name = dict - .find(kCGWindowOwnerName.as_void_ptr()) - .map(|name| CFString::wrap_under_get_rule(*name as _).to_string()); - WindowInfo { - id, - owner_pid, - owner_name, - } - }) - .collect() - } -} - pub struct MacOSDisplay(*const c_void); impl Drop for MacOSDisplay {