diff --git a/Cargo.toml b/Cargo.toml index c29ee3e..06c9531 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ license = "MIT OR Apache-2.0" readme = "README.md" [dependencies] +derivative = "1.0.3" libc = "0.2" [features] diff --git a/src/lib.rs b/src/lib.rs index d681521..8de0bca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,9 @@ pub use v4l2::pubconsts as consts; pub type Result = result::Result; +#[macro_use] +extern crate derivative; + #[derive(Debug)] pub enum Error { /// I/O error when using the camera. @@ -103,6 +106,7 @@ impl From for Error { } } +#[derive(Debug)] pub struct Config<'a> { /// The mix of numerator and denominator. v4l2 uses frame intervals instead of frame rates. /// Default is `(1, 10)`. @@ -245,6 +249,7 @@ impl fmt::Debug for IntervalInfo { } } +#[derive(Debug)] pub struct Frame { /// Width and height of the frame. pub resolution: (u32, u32), @@ -699,6 +704,7 @@ impl Drop for Camera { } } +#[derive(Debug)] pub struct FormatIter<'a> { camera: &'a Camera, index: u32, @@ -726,6 +732,7 @@ impl<'a> Iterator for FormatIter<'a> { } } +#[derive(Debug)] pub struct ControlIter<'a> { camera: &'a Camera, id: u32, diff --git a/src/v4l2.rs b/src/v4l2.rs index c9025a6..e71e9cd 100644 --- a/src/v4l2.rs +++ b/src/v4l2.rs @@ -1,6 +1,7 @@ #![allow(clippy::unreadable_literal)] use std::ffi::CString; +use std::fmt; use std::os::unix::io::RawFd; use std::ptr::null_mut; use std::{io, mem, usize}; @@ -132,12 +133,15 @@ pub fn mmap(length: usize, fd: RawFd, offset: usize) -> io::Result }) } +#[derive(Derivative)] +#[derivative(Debug)] #[repr(C)] pub struct Format { pub ftype: u32, #[cfg(target_pointer_width = "64")] padding: u32, pub fmt: PixFormat, + #[derivative(Debug="ignore")] space: [u8; 156], } @@ -162,6 +166,7 @@ impl Format { } } +#[derive(Debug)] #[repr(C)] pub struct PixFormat { pub width: u32, @@ -188,6 +193,7 @@ impl PixFormat { } } +#[derive(Debug)] #[repr(C)] pub struct RequestBuffers { pub count: u32, @@ -207,6 +213,8 @@ impl RequestBuffers { } } +#[derive(Derivative)] +#[derivative(Debug)] #[repr(C)] pub struct Buffer { pub index: u32, @@ -214,6 +222,7 @@ pub struct Buffer { pub bytesused: u32, pub flags: u32, pub field: u32, + #[derivative(Debug="ignore")] pub timestamp: Timeval, pub timecode: TimeCode, pub sequence: u32, @@ -233,6 +242,7 @@ impl Buffer { } } +#[derive(Debug)] #[repr(C)] pub struct TimeCode { pub ttype: u32, @@ -244,6 +254,7 @@ pub struct TimeCode { pub userbits: [u8; 4], } +#[derive(Debug)] #[repr(C)] pub struct FmtDesc { pub index: u32, @@ -262,10 +273,13 @@ impl FmtDesc { } } +#[derive(Derivative)] +#[derivative(Debug)] #[repr(C)] pub struct StreamParm { pub ptype: u32, pub parm: CaptureParm, + #[derivative(Debug="ignore")] space: [u8; 160], } @@ -279,6 +293,7 @@ impl StreamParm { } } +#[derive(Debug)] #[repr(C)] pub struct CaptureParm { pub capability: u32, @@ -289,12 +304,14 @@ pub struct CaptureParm { reserved: [u32; 4], } +#[derive(Debug)] #[repr(C)] pub struct Fract { pub numerator: u32, pub denominator: u32, } +#[derive(Debug)] #[repr(C)] pub struct Frmsizeenum { pub index: u32, @@ -320,12 +337,14 @@ impl Frmsizeenum { } } +#[derive(Debug)] #[repr(C)] pub struct FrmsizeDiscrete { pub width: u32, pub height: u32, } +#[derive(Debug)] #[repr(C)] pub struct FrmsizeStepwise { pub min_width: u32, @@ -336,6 +355,7 @@ pub struct FrmsizeStepwise { pub step_height: u32, } +#[derive(Debug)] #[repr(C)] pub struct Frmivalenum { pub index: u32, @@ -365,6 +385,7 @@ impl Frmivalenum { } } +#[derive(Debug)] #[repr(C)] pub struct FrmivalStepwise { pub min: Fract, @@ -372,6 +393,7 @@ pub struct FrmivalStepwise { pub step: Fract, } +#[derive(Debug)] #[repr(C)] pub struct QueryCtrl { pub id: u32, @@ -393,6 +415,7 @@ impl QueryCtrl { } } +#[derive(Debug)] #[repr(C)] pub struct QueryExtCtrl { pub id: u32, @@ -420,6 +443,7 @@ impl QueryExtCtrl { } } +#[derive(Debug)] #[repr(C, packed)] pub struct QueryMenu { pub id: u32, @@ -434,6 +458,12 @@ pub union QueryMenuData { value: i64, } +impl fmt::Debug for QueryMenuData { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self.name()) + } +} + impl QueryMenu { pub fn new(id: u32) -> QueryMenu { let mut menu: QueryMenu = unsafe { mem::zeroed() }; @@ -452,6 +482,7 @@ impl QueryMenuData { } } +#[derive(Debug)] #[repr(C)] pub struct Control { pub id: u32, @@ -464,6 +495,7 @@ impl Control { } } +#[derive(Debug)] #[repr(C, packed)] pub struct ExtControl { pub id: u32, @@ -483,6 +515,7 @@ impl ExtControl { } } +#[derive(Debug)] #[repr(C)] pub struct ExtControls<'a> { pub ctrl_class: u32,