Skip to content

Commit

Permalink
Add debug in a ton of structs
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Jan 17, 2020
1 parent b94d92d commit 7facfde
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"

[dependencies]
derivative = "1.0.3"
libc = "0.2"

[features]
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub use v4l2::pubconsts as consts;

pub type Result<T> = result::Result<T, Error>;

#[macro_use]
extern crate derivative;

#[derive(Debug)]
pub enum Error {
/// I/O error when using the camera.
Expand Down Expand Up @@ -103,6 +106,7 @@ impl From<io::Error> 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)`.
Expand Down Expand Up @@ -245,6 +249,7 @@ impl fmt::Debug for IntervalInfo {
}
}

#[derive(Debug)]
pub struct Frame {
/// Width and height of the frame.
pub resolution: (u32, u32),
Expand Down Expand Up @@ -699,6 +704,7 @@ impl Drop for Camera {
}
}

#[derive(Debug)]
pub struct FormatIter<'a> {
camera: &'a Camera,
index: u32,
Expand Down Expand Up @@ -726,6 +732,7 @@ impl<'a> Iterator for FormatIter<'a> {
}
}

#[derive(Debug)]
pub struct ControlIter<'a> {
camera: &'a Camera,
id: u32,
Expand Down
30 changes: 30 additions & 0 deletions src/v4l2.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -162,6 +163,7 @@ impl Format {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct PixFormat {
pub width: u32,
Expand All @@ -188,6 +190,7 @@ impl PixFormat {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct RequestBuffers {
pub count: u32,
Expand All @@ -207,13 +210,16 @@ impl RequestBuffers {
}
}

#[derive(Derivative)]
#[derivative(Debug)]
#[repr(C)]
pub struct Buffer {
pub index: u32,
pub btype: u32,
pub bytesused: u32,
pub flags: u32,
pub field: u32,
#[derivative(Debug="ignore")]
pub timestamp: Timeval,
pub timecode: TimeCode,
pub sequence: u32,
Expand All @@ -233,6 +239,7 @@ impl Buffer {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct TimeCode {
pub ttype: u32,
Expand All @@ -244,6 +251,7 @@ pub struct TimeCode {
pub userbits: [u8; 4],
}

#[derive(Debug)]
#[repr(C)]
pub struct FmtDesc {
pub index: u32,
Expand All @@ -262,10 +270,13 @@ impl FmtDesc {
}
}

#[derive(Derivative)]
#[derivative(Debug)]
#[repr(C)]
pub struct StreamParm {
pub ptype: u32,
pub parm: CaptureParm,
#[derivative(Debug="ignore")]
space: [u8; 160],
}

Expand All @@ -279,6 +290,7 @@ impl StreamParm {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct CaptureParm {
pub capability: u32,
Expand All @@ -289,12 +301,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,
Expand All @@ -320,12 +334,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,
Expand All @@ -336,6 +352,7 @@ pub struct FrmsizeStepwise {
pub step_height: u32,
}

#[derive(Debug)]
#[repr(C)]
pub struct Frmivalenum {
pub index: u32,
Expand Down Expand Up @@ -365,13 +382,15 @@ impl Frmivalenum {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct FrmivalStepwise {
pub min: Fract,
pub max: Fract,
pub step: Fract,
}

#[derive(Debug)]
#[repr(C)]
pub struct QueryCtrl {
pub id: u32,
Expand All @@ -393,6 +412,7 @@ impl QueryCtrl {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct QueryExtCtrl {
pub id: u32,
Expand Down Expand Up @@ -420,6 +440,7 @@ impl QueryExtCtrl {
}
}

#[derive(Debug)]
#[repr(C, packed)]
pub struct QueryMenu {
pub id: u32,
Expand All @@ -434,6 +455,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() };
Expand All @@ -452,6 +479,7 @@ impl QueryMenuData {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct Control {
pub id: u32,
Expand All @@ -464,6 +492,7 @@ impl Control {
}
}

#[derive(Debug)]
#[repr(C, packed)]
pub struct ExtControl {
pub id: u32,
Expand All @@ -483,6 +512,7 @@ impl ExtControl {
}
}

#[derive(Debug)]
#[repr(C)]
pub struct ExtControls<'a> {
pub ctrl_class: u32,
Expand Down

0 comments on commit 7facfde

Please sign in to comment.