From 9844291a792eff0d58f0965eae25266f6c38b23b Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 14 Oct 2023 11:06:07 +0200 Subject: [PATCH] io: Replace fd() with as_raw_fd() --- src/io/mod.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/io/mod.rs b/src/io/mod.rs index d9688a6..dd35dbe 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -3,6 +3,7 @@ use std::{ marker::PhantomData, mem, ops::{Index, IndexMut}, + os::unix::io::AsRawFd, ptr, slice, sync::Arc, }; @@ -47,6 +48,10 @@ impl Queue { self.bufs.len() } + pub fn is_empty(&self) -> bool { + self.bufs.is_empty() + } + /// Request a number of buffers be allocated in the drivers' queue /// /// Returns the number of actual buffers. Some drivers will require a certain minimum number @@ -65,7 +70,7 @@ impl Queue { unsafe { v4l2::ioctl( - self.handle.fd(), + self.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_REQBUFS, &mut v4l2_reqbufs as *mut _ as *mut std::os::raw::c_void, )?; @@ -88,7 +93,7 @@ impl Queue { unsafe { v4l2::ioctl( - self.handle.fd(), + self.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_QUERYBUF, &mut buf as *mut _ as *mut std::os::raw::c_void, )?; @@ -101,7 +106,7 @@ impl Queue { fn streamon(&mut self) -> io::Result<()> { unsafe { v4l2::ioctl( - self.handle.fd(), + self.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_STREAMON, &mut self.buf_type as *mut _ as *mut std::os::raw::c_void, ) @@ -112,7 +117,7 @@ impl Queue { fn streamoff(&mut self) -> io::Result<()> { unsafe { v4l2::ioctl( - self.handle.fd(), + self.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_STREAMOFF, &mut self.buf_type as *mut _ as *mut std::os::raw::c_void, ) @@ -125,7 +130,7 @@ impl Queue { unsafe { v4l2::ioctl( - self.handle.fd(), + self.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_QBUF, buf as *mut _ as *mut std::os::raw::c_void, ) @@ -138,7 +143,7 @@ impl Queue { unsafe { v4l2::ioctl( - self.handle.fd(), + self.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_DQBUF, buf as *mut _ as *mut std::os::raw::c_void, ) @@ -244,7 +249,7 @@ impl Queue, queue::Idle> { let mapping = unsafe { v4l2::ioctl( - queue.handle.fd(), + queue.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_QUERYBUF, &mut v4l2_buf as *mut _ as *mut std::os::raw::c_void, )?; @@ -254,7 +259,7 @@ impl Queue, queue::Idle> { v4l2_buf.length as usize, libc::PROT_READ | libc::PROT_WRITE, libc::MAP_SHARED, - queue.handle.fd(), + queue.handle.as_raw_fd(), v4l2_buf.m.offset as libc::off_t, )?; @@ -322,7 +327,7 @@ impl Queue { }; unsafe { v4l2::ioctl( - queue.handle.fd(), + queue.handle.as_raw_fd(), v4l2::vidioc::VIDIOC_G_FMT, &mut v4l2_fmt as *mut _ as *mut std::os::raw::c_void, )?;