Skip to content

Commit

Permalink
io: Replace fd() with as_raw_fd()
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Oct 14, 2023
1 parent 384e7fb commit 9844291
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
marker::PhantomData,
mem,
ops::{Index, IndexMut},
os::unix::io::AsRawFd,
ptr, slice,
sync::Arc,
};
Expand Down Expand Up @@ -47,6 +48,10 @@ impl<B, S> Queue<B, S> {
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
Expand All @@ -65,7 +70,7 @@ impl<B, S> Queue<B, S> {

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,
)?;
Expand All @@ -88,7 +93,7 @@ impl<B, S> Queue<B, S> {

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,
)?;
Expand All @@ -101,7 +106,7 @@ impl<B, S> Queue<B, S> {
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,
)
Expand All @@ -112,7 +117,7 @@ impl<B, S> Queue<B, S> {
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,
)
Expand All @@ -125,7 +130,7 @@ impl<B, S> Queue<B, S> {

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,
)
Expand All @@ -138,7 +143,7 @@ impl<B, S> Queue<B, S> {

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,
)
Expand Down Expand Up @@ -244,7 +249,7 @@ impl Queue<Mmap<'_>, 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,
)?;
Expand All @@ -254,7 +259,7 @@ impl Queue<Mmap<'_>, 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,
)?;

Expand Down Expand Up @@ -322,7 +327,7 @@ impl Queue<UserPtr, queue::Idle> {
};
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,
)?;
Expand Down

0 comments on commit 9844291

Please sign in to comment.