improve video, ignore same image

This commit is contained in:
rustdesk
2022-04-24 02:50:28 +08:00
parent 264db496ff
commit 4d5d0a4c62
6 changed files with 37 additions and 8 deletions

View File

@@ -30,3 +30,16 @@ pub use self::convert::*;
pub const STRIDE_ALIGN: usize = 64; // commonly used in libvpx vpx_img_alloc caller
mod vpx;
#[inline]
pub fn would_block_if_equal(old: &mut Vec<u128>, b: &[u8]) -> std::io::Result<()> {
let b = unsafe {
std::slice::from_raw_parts::<u128>(b.as_ptr() as _, b.len() / 16)
};
if b == &old[..] {
return Err(std::io::ErrorKind::WouldBlock.into());
}
old.resize(b.len(), 0);
old.copy_from_slice(b);
Ok(())
}

View File

@@ -8,6 +8,7 @@ pub struct Capturer {
frame: Arc<Mutex<Option<quartz::Frame>>>,
use_yuv: bool,
i420: Vec<u8>,
saved_raw_data: Vec<u128>, // for faster compare and copy
}
impl Capturer {
@@ -38,6 +39,7 @@ impl Capturer {
frame,
use_yuv,
i420: Vec::new(),
saved_raw_data: Vec::new(),
})
}
@@ -57,6 +59,7 @@ impl Capturer {
match frame {
Some(mut frame) => {
crate::would_block_if_equal(&mut self.saved_raw_data, frame.inner())?;
if self.use_yuv {
frame.nv12_to_i420(self.width(), self.height(), &mut self.i420);
}

View File

@@ -17,7 +17,7 @@ impl Capturer {
}
pub fn frame<'a>(&'a mut self, _timeout_ms: u32) -> io::Result<Frame<'a>> {
Ok(Frame(self.0.frame()))
Ok(Frame(self.0.frame()?))
}
}