v4l/video/capture/
parameters.rs1use bitflags::bitflags;
2use std::{fmt, mem};
3
4use crate::fraction::Fraction;
5use crate::parameters::Capabilities;
6use crate::v4l_sys::*;
7
8bitflags! {
9 pub struct Modes: u32 {
10 const HIGH_QUALITY = 0x1000;
11 }
12}
13
14impl From<u32> for Modes {
15 fn from(caps: u32) -> Self {
16 Self::from_bits_truncate(caps)
17 }
18}
19
20impl From<Modes> for u32 {
21 fn from(modes: Modes) -> Self {
22 modes.bits()
23 }
24}
25
26impl fmt::Display for Modes {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 fmt::Debug::fmt(self, f)
29 }
30}
31
32#[derive(Debug, Copy, Clone)]
33pub struct Parameters {
35 pub capabilities: Capabilities,
36 pub modes: Modes,
37 pub interval: Fraction,
38}
39
40impl Parameters {
41 pub fn new(frac: Fraction) -> Self {
42 Parameters {
43 capabilities: Capabilities::from(0),
44 modes: Modes::from(0),
45 interval: frac,
46 }
47 }
48
49 pub fn with_fps(fps: u32) -> Self {
50 Parameters {
51 capabilities: Capabilities::from(0),
52 modes: Modes::from(0),
53 interval: Fraction::new(1, fps),
54 }
55 }
56}
57
58impl fmt::Display for Parameters {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 writeln!(f, "capabilities : {}", self.capabilities)?;
61 writeln!(f, "modes : {}", self.modes)?;
62 writeln!(f, "interval : {} [s]", self.interval)?;
63 Ok(())
64 }
65}
66
67impl From<v4l2_captureparm> for Parameters {
68 fn from(params: v4l2_captureparm) -> Self {
69 Self {
70 capabilities: Capabilities::from(params.capability),
71 modes: Modes::from(params.capturemode),
72 interval: Fraction::from(params.timeperframe),
73 }
74 }
75}
76
77impl From<Parameters> for v4l2_captureparm {
78 fn from(parameters: Parameters) -> Self {
79 Self {
80 capability: parameters.capabilities.into(),
81 capturemode: parameters.modes.into(),
82 timeperframe: parameters.interval.into(),
83 ..unsafe { mem::zeroed() }
84 }
85 }
86}