mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-11 18:11:27 +03:00
add zero copy mode hareware codec for windows (#6778)
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -8,7 +8,9 @@ use hbb_common::{
|
||||
tokio::{self, sync::mpsc},
|
||||
ResultType,
|
||||
};
|
||||
use scrap::{Capturer, Frame, TraitCapturer, TraitFrame};
|
||||
#[cfg(feature = "gpucodec")]
|
||||
use scrap::AdapterDevice;
|
||||
use scrap::{Capturer, Frame, TraitCapturer, TraitPixelBuffer};
|
||||
use shared_memory::*;
|
||||
use std::{
|
||||
mem::size_of,
|
||||
@@ -381,21 +383,26 @@ pub mod server {
|
||||
}
|
||||
}
|
||||
match c.as_mut().map(|f| f.frame(spf)) {
|
||||
Some(Ok(f)) => {
|
||||
utils::set_frame_info(
|
||||
&shmem,
|
||||
FrameInfo {
|
||||
length: f.data().len(),
|
||||
width: display_width,
|
||||
height: display_height,
|
||||
},
|
||||
);
|
||||
shmem.write(ADDR_CAPTURE_FRAME, f.data());
|
||||
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
|
||||
utils::increase_counter(shmem.as_ptr().add(ADDR_CAPTURE_FRAME_COUNTER));
|
||||
first_frame_captured = true;
|
||||
dxgi_failed_times = 0;
|
||||
}
|
||||
Some(Ok(f)) => match f {
|
||||
Frame::PixelBuffer(f) => {
|
||||
utils::set_frame_info(
|
||||
&shmem,
|
||||
FrameInfo {
|
||||
length: f.data().len(),
|
||||
width: display_width,
|
||||
height: display_height,
|
||||
},
|
||||
);
|
||||
shmem.write(ADDR_CAPTURE_FRAME, f.data());
|
||||
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
|
||||
utils::increase_counter(shmem.as_ptr().add(ADDR_CAPTURE_FRAME_COUNTER));
|
||||
first_frame_captured = true;
|
||||
dxgi_failed_times = 0;
|
||||
}
|
||||
Frame::Texture(_) => {
|
||||
// should not happen
|
||||
}
|
||||
},
|
||||
Some(Err(e)) => {
|
||||
if e.kind() != std::io::ErrorKind::WouldBlock {
|
||||
// DXGI_ERROR_INVALID_CALL after each success on Microsoft GPU driver
|
||||
@@ -510,11 +517,10 @@ pub mod server {
|
||||
|
||||
// functions called in main process.
|
||||
pub mod client {
|
||||
use hbb_common::{anyhow::Context, message_proto::PointerDeviceEvent};
|
||||
|
||||
use crate::display_service;
|
||||
|
||||
use super::*;
|
||||
use crate::display_service;
|
||||
use hbb_common::{anyhow::Context, message_proto::PointerDeviceEvent};
|
||||
use scrap::PixelBuffer;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref RUNNING: Arc<Mutex<bool>> = Default::default();
|
||||
@@ -705,7 +711,11 @@ pub mod client {
|
||||
}
|
||||
let frame_ptr = base.add(ADDR_CAPTURE_FRAME);
|
||||
let data = slice::from_raw_parts(frame_ptr, (*frame_info).length);
|
||||
Ok(Frame::new(data, self.width, self.height))
|
||||
Ok(Frame::PixelBuffer(PixelBuffer::new(
|
||||
data,
|
||||
self.width,
|
||||
self.height,
|
||||
)))
|
||||
} else {
|
||||
let ptr = base.add(ADDR_CAPTURE_WOULDBLOCK);
|
||||
let wouldblock = utils::ptr_to_i32(ptr);
|
||||
@@ -732,6 +742,14 @@ pub mod client {
|
||||
fn set_gdi(&mut self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpucodec")]
|
||||
fn device(&self) -> AdapterDevice {
|
||||
AdapterDevice::default()
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpucodec")]
|
||||
fn set_output_texture(&mut self, _texture: bool) {}
|
||||
}
|
||||
|
||||
pub(super) fn start_ipc_server() -> mpsc::UnboundedSender<Data> {
|
||||
|
||||
Reference in New Issue
Block a user