fix android get raw data (#8171)

If `std::ptr::copy_nonoverlapping` is not in `take`, it's not protected by the lock.

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-05-28 16:35:59 +08:00
committed by GitHub
parent 278d593580
commit 010b17509a
3 changed files with 21 additions and 15 deletions

View File

@@ -36,13 +36,7 @@ impl Capturer {
impl crate::TraitCapturer for Capturer {
fn frame<'a>(&'a mut self, _timeout: Duration) -> io::Result<Frame<'a>> {
if let Some(buf) = get_video_raw() {
crate::would_block_if_equal(&mut self.saved_raw_data, buf)?;
// Is it safe to directly return buf without copy?
self.rgba.resize(buf.len(), 0);
unsafe {
std::ptr::copy_nonoverlapping(buf.as_ptr(), self.rgba.as_mut_ptr(), buf.len())
};
if get_video_raw(&mut self.rgba, &mut self.saved_raw_data).is_some() {
Ok(Frame::PixelBuffer(PixelBuffer::new(
&self.rgba,
self.width(),