From e0675fdac024e4a1f330114d65a169fbf1d3577f Mon Sep 17 00:00:00 2001 From: Jay Sistar Date: Thu, 21 Dec 2023 13:06:42 -0500 Subject: [PATCH] Adding change by @anatawa12 from https://github.com/raymanfx/libv4l-rs/pull/71#discussion_r1346704300 --- src/io/mmap/arena.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/io/mmap/arena.rs b/src/io/mmap/arena.rs index 2d6dd97..6d8a437 100644 --- a/src/io/mmap/arena.rs +++ b/src/io/mmap/arena.rs @@ -106,17 +106,21 @@ impl<'a> Arena<'a> { // each plane has to be mapped separately let mut planes = Vec::new(); for plane in &v4l2_planes { + let length = if !self.buf_type.planar() { + v4l2_buf.length as usize + } else { + plane.length as usize + }; let ptr = v4l2::mmap( ptr::null_mut(), - plane.length as usize, + length, libc::PROT_READ | libc::PROT_WRITE, libc::MAP_SHARED, self.handle.fd(), plane.m.mem_offset as libc::off_t, )?; - planes.push(slice::from_raw_parts_mut::( - ptr as *mut u8, plane.length as usize + ptr as *mut u8, length, )); }