From 42c95f71f6f243653dbda04ec0a4c25c59a1fbf6 Mon Sep 17 00:00:00 2001 From: fufesou Date: Thu, 2 Mar 2023 18:46:00 +0800 Subject: [PATCH] fix macos strid align Signed-off-by: fufesou --- libs/scrap/src/common/codec.rs | 6 ++++-- src/client.rs | 4 ++-- src/common.rs | 5 +++++ src/flutter.rs | 4 +++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libs/scrap/src/common/codec.rs b/libs/scrap/src/common/codec.rs index 3adc24a14..868a93f5a 100644 --- a/libs/scrap/src/common/codec.rs +++ b/libs/scrap/src/common/codec.rs @@ -306,12 +306,13 @@ impl Decoder { pub fn handle_video_frame( &mut self, frame: &video_frame::Union, + stride_align: usize, fmt: ImageFormat, rgb: &mut Vec, ) -> ResultType { match frame { video_frame::Union::Vp9s(vp9s) => { - Decoder::handle_vp9s_video_frame(&mut self.vpx, vp9s, fmt, rgb) + Decoder::handle_vp9s_video_frame(&mut self.vpx, vp9s, stride_align, fmt, rgb) } #[cfg(feature = "hwcodec")] video_frame::Union::H264s(h264s) => { @@ -352,6 +353,7 @@ impl Decoder { fn handle_vp9s_video_frame( decoder: &mut VpxDecoder, vp9s: &EncodedVideoFrames, + stride_align: usize, fmt: ImageFormat, rgb: &mut Vec, ) -> ResultType { @@ -369,7 +371,7 @@ impl Decoder { if last_frame.is_null() { Ok(false) } else { - last_frame.to(fmt, 1, rgb); + last_frame.to(fmt, stride_align, rgb); Ok(true) } } diff --git a/src/client.rs b/src/client.rs index 40a9f05b0..a2e893c49 100644 --- a/src/client.rs +++ b/src/client.rs @@ -49,7 +49,7 @@ use scrap::{ }; use crate::{ - common::{self, is_keyboard_mode_supported}, + common::{self, is_keyboard_mode_supported, STRIDE_ALIGN}, server::video_service::{SCRAP_X11_REF_URL, SCRAP_X11_REQUIRED}, }; @@ -949,7 +949,7 @@ impl VideoHandler { let fmt = ImageFormat::ABGR; #[cfg(not(all(target_os = "windows", feature = "flutter_texture_render")))] let fmt = ImageFormat::ARGB; - let res = self.decoder.handle_video_frame(frame, fmt, &mut self.rgb); + let res = self.decoder.handle_video_frame(frame, STRIDE_ALIGN, fmt, &mut self.rgb); if self.record { self.recorder .lock() diff --git a/src/common.rs b/src/common.rs index 5f24fd5c3..a6ef0142b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -39,6 +39,11 @@ pub const CLIPBOARD_INTERVAL: u64 = 333; pub const SYNC_PEER_INFO_DISPLAYS: i32 = 1; +#[cfg(all(target_os = "macos", feature = "flutter_texture_render"))] +pub const STRIDE_ALIGN: usize = 16; +#[cfg(not(all(target_os = "macos", feature = "flutter_texture_render")))] +pub const STRIDE_ALIGN: usize = 1; + // the executable name of the portable version pub const PORTABLE_APPNAME_RUNTIME_ENV_KEY: &str = "RUSTDESK_APPNAME"; diff --git a/src/flutter.rs b/src/flutter.rs index 2f660775f..6d4f143fb 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -206,7 +206,9 @@ impl VideoRenderer { self.width = width; self.height = height; self.data_len = if width > 0 && height > 0 { - (width * height * 4) as usize + let sa1 = crate::common::STRIDE_ALIGN - 1; + let w = (width as usize + sa1) & !sa1; + w * (height as usize) * 4 } else { 0 };