Skip to content

Commit

Permalink
ioctl: add frameintervals
Browse files Browse the repository at this point in the history
Add support for VIDIOC_ENUM_FRAMEINTERVALS ioctl.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
  • Loading branch information
aesteve-rh authored and Gnurou committed Jul 4, 2023
1 parent 23f8a15 commit f3353c9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod dqbuf;
mod encoder_cmd;
mod enum_fmt;
mod expbuf;
mod frameintervals;
mod framesizes;
mod g_ext_ctrls;
mod g_fmt;
Expand All @@ -32,6 +33,7 @@ pub use dqbuf::*;
pub use encoder_cmd::*;
pub use enum_fmt::*;
pub use expbuf::*;
pub use frameintervals::*;
pub use framesizes::*;
pub use g_ext_ctrls::*;
pub use g_fmt::*;
Expand Down
47 changes: 47 additions & 0 deletions lib/src/ioctl/frameintervals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::os::unix::io::AsRawFd;
use thiserror::Error;

use crate::{bindings, PixelFormat};

pub trait FrameIntervals {
fn from(input: bindings::v4l2_frmivalenum) -> Self;
}

impl FrameIntervals for bindings::v4l2_frmivalenum {
fn from(input: bindings::v4l2_frmivalenum) -> Self {
input
}
}

#[doc(hidden)]
mod ioctl {
use crate::bindings::v4l2_frmivalenum;
nix::ioctl_readwrite!(vidioc_enum_frameintervals, b'V', 75, v4l2_frmivalenum);
}

#[derive(Debug, Error)]
pub enum FrameIntervalsError {
#[error("Unexpected ioctl error: {0}")]
IoctlError(nix::Error),
}

pub fn enum_frame_intervals<T: FrameIntervals>(
fd: &impl AsRawFd,
index: u32,
pixel_format: PixelFormat,
width: u32,
heigth: u32,
) -> Result<T, FrameIntervalsError> {
let mut frame_interval = bindings::v4l2_frmivalenum {
index,
pixel_format: pixel_format.into(),
width: width,
height: heigth,
..unsafe { std::mem::zeroed() }
};

match unsafe { ioctl::vidioc_enum_frameintervals(fd.as_raw_fd(), &mut frame_interval) } {
Ok(_) => Ok(T::from(frame_interval)),
Err(e) => Err(FrameIntervalsError::IoctlError(e)),
}
}

0 comments on commit f3353c9

Please sign in to comment.