From 87306a3d01d2fb08d2f1e37320306bd1fcb9dc0b Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 25 Nov 2022 18:27:17 +0800 Subject: [PATCH] wayland filter last same frame Signed-off-by: fufesou --- libs/scrap/src/wayland/pipewire.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libs/scrap/src/wayland/pipewire.rs b/libs/scrap/src/wayland/pipewire.rs index 6277ed97c..a7b4c1357 100644 --- a/libs/scrap/src/wayland/pipewire.rs +++ b/libs/scrap/src/wayland/pipewire.rs @@ -122,6 +122,7 @@ pub struct PipeWireRecorder { appsink: AppSink, width: usize, height: usize, + saved_raw_data: Vec, // for faster compare and copy } impl PipeWireRecorder { @@ -160,6 +161,7 @@ impl PipeWireRecorder { height: 0, buffer_cropped: vec![], is_cropped: false, + saved_raw_data: Vec::new(), }) } } @@ -192,6 +194,9 @@ impl Recorder for PipeWireRecorder { let buf = buf .into_mapped_buffer_readable() .map_err(|_| GStreamerError("Failed to map buffer.".into()))?; + if let Err(..) = crate::would_block_if_equal(&mut self.saved_raw_data, buf.as_slice()) { + return Ok(PixelProvider::NONE); + } let buf_size = buf.get_size(); // BGRx is 4 bytes per pixel if buf_size != (w * h * 4) { @@ -433,16 +438,10 @@ fn request_screen_cast( if version >= 4 { let restore_token = config::LocalConfig::get_option(RESTORE_TOKEN_CONF_KEY); if !restore_token.is_empty() { - args.insert( - RESTORE_TOKEN.to_string(), - Variant(Box::new(restore_token)), - ); + args.insert(RESTORE_TOKEN.to_string(), Variant(Box::new(restore_token))); } // persist_mode may be configured by the user. - args.insert( - "persist_mode".to_string(), - Variant(Box::new(2u32)), - ); + args.insert("persist_mode".to_string(), Variant(Box::new(2u32))); } } args.insert(