mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
set width,height,stride together with the rgba data for rendering
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -50,7 +50,7 @@ pub use helper::*;
|
||||
use scrap::{
|
||||
codec::Decoder,
|
||||
record::{Recorder, RecorderContext},
|
||||
ImageFormat,
|
||||
ImageFormat, ImageRgb,
|
||||
};
|
||||
|
||||
use crate::common::{self, is_keyboard_mode_supported};
|
||||
@@ -980,7 +980,7 @@ impl AudioHandler {
|
||||
/// Video handler for the [`Client`].
|
||||
pub struct VideoHandler {
|
||||
decoder: Decoder,
|
||||
pub rgb: Vec<u8>,
|
||||
pub rgb: ImageRgb,
|
||||
recorder: Arc<Mutex<Option<Recorder>>>,
|
||||
record: bool,
|
||||
}
|
||||
@@ -990,7 +990,7 @@ impl VideoHandler {
|
||||
pub fn new() -> Self {
|
||||
VideoHandler {
|
||||
decoder: Decoder::new(),
|
||||
rgb: Default::default(),
|
||||
rgb: ImageRgb::new(ImageFormat::ARGB, crate::DST_STRIDE_RGBA),
|
||||
recorder: Default::default(),
|
||||
record: false,
|
||||
}
|
||||
@@ -1001,11 +1001,7 @@ impl VideoHandler {
|
||||
pub fn handle_frame(&mut self, vf: VideoFrame) -> ResultType<bool> {
|
||||
match &vf.union {
|
||||
Some(frame) => {
|
||||
let res = self.decoder.handle_video_frame(
|
||||
frame,
|
||||
(ImageFormat::ARGB, crate::DST_STRIDE_RGBA),
|
||||
&mut self.rgb,
|
||||
);
|
||||
let res = self.decoder.handle_video_frame(frame, &mut self.rgb);
|
||||
if self.record {
|
||||
self.recorder
|
||||
.lock()
|
||||
@@ -1757,7 +1753,7 @@ pub fn start_video_audio_threads<F>(
|
||||
Arc<AtomicUsize>,
|
||||
)
|
||||
where
|
||||
F: 'static + FnMut(&mut Vec<u8>) + Send,
|
||||
F: 'static + FnMut(&scrap::ImageRgb) + Send,
|
||||
{
|
||||
let (video_sender, video_receiver) = mpsc::channel::<MediaData>();
|
||||
let video_queue = Arc::new(ArrayQueue::<VideoFrame>::new(VIDEO_QUEUE_SIZE));
|
||||
|
||||
@@ -179,8 +179,9 @@ pub type FlutterRgbaRendererPluginOnRgba = unsafe extern "C" fn(
|
||||
struct VideoRenderer {
|
||||
// TextureRgba pointer in flutter native.
|
||||
ptr: usize,
|
||||
width: i32,
|
||||
height: i32,
|
||||
width: usize,
|
||||
height: usize,
|
||||
size: usize,
|
||||
on_rgba_func: Option<Symbol<'static, FlutterRgbaRendererPluginOnRgba>>,
|
||||
}
|
||||
|
||||
@@ -209,6 +210,7 @@ impl Default for VideoRenderer {
|
||||
ptr: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
size: 0,
|
||||
on_rgba_func,
|
||||
}
|
||||
}
|
||||
@@ -217,24 +219,30 @@ impl Default for VideoRenderer {
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
impl VideoRenderer {
|
||||
#[inline]
|
||||
pub fn set_size(&mut self, width: i32, height: i32) {
|
||||
pub fn set_size(&mut self, width: usize, height: usize) {
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
}
|
||||
|
||||
pub fn on_rgba(&self, rgba: &Vec<u8>) {
|
||||
if self.ptr == usize::default() || self.width == 0 || self.height == 0 {
|
||||
pub fn on_rgba(&self, rgba: &scrap::ImageRgb) {
|
||||
if self.ptr == usize::default() {
|
||||
return;
|
||||
}
|
||||
|
||||
// It is also Ok to skip this check.
|
||||
if self.width != rgba.w || self.height != rgba.h {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(func) = &self.on_rgba_func {
|
||||
unsafe {
|
||||
func(
|
||||
self.ptr as _,
|
||||
rgba.as_ptr() as _,
|
||||
rgba.len() as _,
|
||||
self.width as _,
|
||||
self.height as _,
|
||||
crate::DST_STRIDE_RGBA as _,
|
||||
rgba.raw.as_ptr() as _,
|
||||
rgba.raw.len() as _,
|
||||
rgba.w as _,
|
||||
rgba.h as _,
|
||||
rgba.stride as _,
|
||||
)
|
||||
};
|
||||
}
|
||||
@@ -315,7 +323,7 @@ impl FlutterHandler {
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
pub fn set_size(&mut self, width: i32, height: i32) {
|
||||
pub fn set_size(&mut self, width: usize, height: usize) {
|
||||
*self.notify_rendered.write().unwrap() = false;
|
||||
self.renderer.write().unwrap().set_size(width, height);
|
||||
}
|
||||
@@ -492,7 +500,7 @@ impl InvokeUiSession for FlutterHandler {
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(feature = "flutter_texture_render"))]
|
||||
fn on_rgba(&self, data: &mut Vec<u8>) {
|
||||
fn on_rgba(&self, rgba: &scrap::ImageRgb) {
|
||||
// If the current rgba is not fetched by flutter, i.e., is valid.
|
||||
// We give up sending a new event to flutter.
|
||||
if self.rgba_valid.load(Ordering::Relaxed) {
|
||||
@@ -500,7 +508,7 @@ impl InvokeUiSession for FlutterHandler {
|
||||
}
|
||||
self.rgba_valid.store(true, Ordering::Relaxed);
|
||||
// Return the rgba buffer to the video handler for reusing allocated rgba buffer.
|
||||
std::mem::swap::<Vec<u8>>(data, &mut *self.rgba.write().unwrap());
|
||||
std::mem::swap::<Vec<u8>>(rgba.raw, &mut *self.rgba.write().unwrap());
|
||||
if let Some(stream) = &*self.event_stream.read().unwrap() {
|
||||
stream.add(EventToUI::Rgba);
|
||||
}
|
||||
@@ -508,8 +516,8 @@ impl InvokeUiSession for FlutterHandler {
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
fn on_rgba(&self, data: &mut Vec<u8>) {
|
||||
self.renderer.read().unwrap().on_rgba(data);
|
||||
fn on_rgba(&self, rgba: &scrap::ImageRgb) {
|
||||
self.renderer.read().unwrap().on_rgba(rgba);
|
||||
if *self.notify_rendered.read().unwrap() {
|
||||
return;
|
||||
}
|
||||
@@ -1047,5 +1055,4 @@ pub fn stop_global_event_stream(app_type: String) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn get_rgba() {
|
||||
}
|
||||
unsafe extern "C" fn get_rgba() {}
|
||||
|
||||
@@ -539,7 +539,7 @@ pub fn session_change_resolution(id: String, width: i32, height: i32) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_set_size(_id: String, _width: i32, _height: i32) {
|
||||
pub fn session_set_size(_id: String, _width: usize, _height: usize) {
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
if let Some(session) = SESSIONS.write().unwrap().get_mut(&_id) {
|
||||
session.set_size(_width, _height);
|
||||
|
||||
@@ -223,12 +223,12 @@ impl InvokeUiSession for SciterHandler {
|
||||
self.call("adaptSize", &make_args!());
|
||||
}
|
||||
|
||||
fn on_rgba(&self, data: &mut Vec<u8>) {
|
||||
fn on_rgba(&self, rgba: &scrap::ImageRgb) {
|
||||
VIDEO
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_mut()
|
||||
.map(|v| v.render_frame(data).ok());
|
||||
.map(|v| v.render_frame(rgba.raw).ok());
|
||||
}
|
||||
|
||||
fn set_peer_info(&self, pi: &PeerInfo) {
|
||||
|
||||
@@ -926,7 +926,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
|
||||
fn update_block_input_state(&self, on: bool);
|
||||
fn job_progress(&self, id: i32, file_num: i32, speed: f64, finished_size: f64);
|
||||
fn adapt_size(&self);
|
||||
fn on_rgba(&self, data: &mut Vec<u8>);
|
||||
fn on_rgba(&self, rgba: &scrap::ImageRgb);
|
||||
fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool);
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
fn clipboard(&self, content: String);
|
||||
@@ -1207,7 +1207,7 @@ pub async fn io_loop<T: InvokeUiSession>(handler: Session<T>) {
|
||||
let frame_count_cl = frame_count.clone();
|
||||
let ui_handler = handler.ui_handler.clone();
|
||||
let (video_sender, audio_sender, video_queue, decode_fps) =
|
||||
start_video_audio_threads(move |data: &mut Vec<u8>| {
|
||||
start_video_audio_threads(move |data: &scrap::ImageRgb| {
|
||||
frame_count_cl.fetch_add(1, Ordering::Relaxed);
|
||||
ui_handler.on_rgba(data);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user