mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 01:34:02 +00:00
Use the display's resolution for the video frames
co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
0f5bd9a3b9
commit
4148786a74
6 changed files with 44 additions and 26 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -7030,7 +7030,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "libwebrtc"
|
||||
version = "0.3.7"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"cxx",
|
||||
"jni",
|
||||
|
@ -7164,7 +7164,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "livekit"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"futures-util",
|
||||
|
@ -7186,7 +7186,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "livekit-api"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"async-tungstenite 0.25.1",
|
||||
"futures-util",
|
||||
|
@ -7211,7 +7211,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "livekit-protocol"
|
||||
version = "0.3.6"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"livekit-runtime",
|
||||
|
@ -7228,7 +7228,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "livekit-runtime"
|
||||
version = "0.3.1"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"async-io 2.4.0",
|
||||
"async-std",
|
||||
|
@ -14907,7 +14907,7 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
|
|||
[[package]]
|
||||
name = "webrtc-sys"
|
||||
version = "0.3.5"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cxx",
|
||||
|
@ -14920,7 +14920,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "webrtc-sys-build"
|
||||
version = "0.3.5"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=799f10133d93ba2a88642cd480d01ec4da53408c#799f10133d93ba2a88642cd480d01ec4da53408c"
|
||||
source = "git+https://github.com/zed-industries/rust-sdks?rev=1f6af333fc8872683c30b39354cec312a1026a0a#1f6af333fc8872683c30b39354cec312a1026a0a"
|
||||
dependencies = [
|
||||
"fs2",
|
||||
"regex",
|
||||
|
|
|
@ -393,7 +393,7 @@ jupyter-protocol = { version = "0.3.0" }
|
|||
jupyter-websocket-client = { version = "0.5.0" }
|
||||
libc = "0.2"
|
||||
linkify = "0.10.0"
|
||||
livekit = { git = "https://github.com/zed-industries/rust-sdks", rev="799f10133d93ba2a88642cd480d01ec4da53408c", features = ["dispatcher", "services-dispatcher", "rustls-tls-native-roots"], default-features = false }
|
||||
livekit = { git = "https://github.com/zed-industries/rust-sdks", rev="1f6af333fc8872683c30b39354cec312a1026a0a", features = ["dispatcher", "services-dispatcher", "rustls-tls-native-roots"], default-features = false }
|
||||
log = { version = "0.4.16", features = ["kv_unstable_serde", "serde"] }
|
||||
markup5ever_rcdom = "0.3.0"
|
||||
nanoid = "0.4"
|
||||
|
|
|
@ -239,7 +239,7 @@ pub trait PlatformDisplay: Send + Sync + Debug {
|
|||
/// A source of on-screen video content that can be captured.
|
||||
pub trait ScreenCaptureSource {
|
||||
/// Returns the video resolution of this source.
|
||||
fn resolution(&self) -> Result<Size<Pixels>>;
|
||||
fn resolution(&self) -> Size<DevicePixels>;
|
||||
|
||||
/// Start capture video from this source, invoking the given callback
|
||||
/// with each frame.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
platform::{ScreenCaptureFrame, ScreenCaptureSource, ScreenCaptureStream},
|
||||
px, size, Pixels, Size,
|
||||
size, DevicePixels, Size,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use block::ConcreteBlock;
|
||||
|
@ -9,6 +9,10 @@ use cocoa::{
|
|||
foundation::NSArray,
|
||||
};
|
||||
use core_foundation::base::TCFType;
|
||||
use core_graphics::display::{
|
||||
CGDirectDisplayID, CGDisplayCopyDisplayMode, CGDisplayModeGetPixelHeight,
|
||||
CGDisplayModeGetPixelWidth, CGDisplayModeRelease,
|
||||
};
|
||||
use ctor::ctor;
|
||||
use futures::channel::oneshot;
|
||||
use media::core_media::{CMSampleBuffer, CMSampleBufferRef};
|
||||
|
@ -25,6 +29,7 @@ use std::{cell::RefCell, ffi::c_void, mem, ptr, rc::Rc};
|
|||
#[derive(Clone)]
|
||||
pub struct MacScreenCaptureSource {
|
||||
sc_display: id,
|
||||
size: Size<DevicePixels>,
|
||||
}
|
||||
|
||||
pub struct MacScreenCaptureStream {
|
||||
|
@ -43,12 +48,9 @@ const FRAME_CALLBACK_IVAR: &str = "frame_callback";
|
|||
const SCStreamOutputTypeScreen: NSInteger = 0;
|
||||
|
||||
impl ScreenCaptureSource for MacScreenCaptureSource {
|
||||
fn resolution(&self) -> Result<Size<Pixels>> {
|
||||
unsafe {
|
||||
let width: i64 = msg_send![self.sc_display, width];
|
||||
let height: i64 = msg_send![self.sc_display, height];
|
||||
Ok(size(px(width as f32), px(height as f32)))
|
||||
}
|
||||
fn resolution(&self) -> Size<DevicePixels> {
|
||||
// Remove this / 2 to break track publication
|
||||
self.size.map(|u| u / 1)
|
||||
}
|
||||
|
||||
fn stream(
|
||||
|
@ -68,6 +70,10 @@ impl ScreenCaptureSource for MacScreenCaptureSource {
|
|||
let delegate: id = msg_send![delegate, init];
|
||||
let output: id = msg_send![output, init];
|
||||
|
||||
let resolution = self.resolution();
|
||||
let _: () = msg_send![configuration, setWidth:resolution.width.0];
|
||||
let _: () = msg_send![configuration, setHeight:resolution.height.0];
|
||||
|
||||
output.as_mut().unwrap().set_ivar(
|
||||
FRAME_CALLBACK_IVAR,
|
||||
Box::into_raw(Box::new(frame_callback)) as *mut c_void,
|
||||
|
@ -156,12 +162,23 @@ pub(crate) fn get_sources() -> oneshot::Receiver<Result<Vec<Box<dyn ScreenCaptur
|
|||
};
|
||||
let result = if error == nil {
|
||||
let displays: id = msg_send![shareable_content, displays];
|
||||
|
||||
let mut result = Vec::new();
|
||||
for i in 0..displays.count() {
|
||||
let display = displays.objectAtIndex(i);
|
||||
let display: id = msg_send![display, retain];
|
||||
|
||||
let display_id: CGDirectDisplayID = msg_send![display, displayID];
|
||||
let display_mode_ref = CGDisplayCopyDisplayMode(display_id);
|
||||
let width = CGDisplayModeGetPixelWidth(display_mode_ref);
|
||||
let height = CGDisplayModeGetPixelHeight(display_mode_ref);
|
||||
CGDisplayModeRelease(display_mode_ref);
|
||||
|
||||
let source = MacScreenCaptureSource {
|
||||
sc_display: msg_send![display, retain],
|
||||
sc_display: display,
|
||||
size: size(DevicePixels(width as i32), DevicePixels(height as i32)),
|
||||
};
|
||||
|
||||
result.push(Box::new(source) as Box<dyn ScreenCaptureSource>);
|
||||
}
|
||||
Ok(result)
|
||||
|
|
|
@ -46,8 +46,8 @@ pub struct TestScreenCaptureSource {}
|
|||
pub struct TestScreenCaptureStream {}
|
||||
|
||||
impl ScreenCaptureSource for TestScreenCaptureSource {
|
||||
fn resolution(&self) -> Result<crate::Size<crate::Pixels>> {
|
||||
Ok(size(px(1.), px(1.)))
|
||||
fn resolution(&self) -> crate::Size<crate::DevicePixels> {
|
||||
size(crate::DevicePixels(1), crate::DevicePixels(1))
|
||||
}
|
||||
|
||||
fn stream(
|
||||
|
|
|
@ -23,14 +23,14 @@ use webrtc::{
|
|||
video_stream::native::NativeVideoStream,
|
||||
};
|
||||
|
||||
#[cfg(all(not(any(test, feature = "test-support")), not(target_os = "windows")))]
|
||||
// #[cfg(all(not(any(test, feature = "test-support")), not(target_os = "windows")))]
|
||||
use livekit::track::RemoteAudioTrack;
|
||||
#[cfg(all(not(any(test, feature = "test-support")), not(target_os = "windows")))]
|
||||
// #[cfg(all(not(any(test, feature = "test-support")), not(target_os = "windows")))]
|
||||
pub use livekit::*;
|
||||
#[cfg(any(test, feature = "test-support", target_os = "windows"))]
|
||||
use test::track::RemoteAudioTrack;
|
||||
#[cfg(any(test, feature = "test-support", target_os = "windows"))]
|
||||
pub use test::*;
|
||||
// #[cfg(any(test, feature = "test-support", target_os = "windows"))]
|
||||
// use test::track::RemoteAudioTrack;
|
||||
// #[cfg(any(test, feature = "test-support", target_os = "windows"))]
|
||||
// pub use test::*;
|
||||
|
||||
pub use remote_video_track_view::{RemoteVideoTrackView, RemoteVideoTrackViewEvent};
|
||||
|
||||
|
@ -143,7 +143,8 @@ pub fn init(
|
|||
pub async fn capture_local_video_track(
|
||||
capture_source: &dyn ScreenCaptureSource,
|
||||
) -> Result<(track::LocalVideoTrack, Box<dyn ScreenCaptureStream>)> {
|
||||
let resolution = capture_source.resolution()?;
|
||||
let resolution = capture_source.resolution();
|
||||
dbg!(&resolution);
|
||||
let track_source = NativeVideoSource::new(VideoResolution {
|
||||
width: resolution.width.0 as u32,
|
||||
height: resolution.height.0 as u32,
|
||||
|
|
Loading…
Reference in a new issue