v4l/video/traits.rs
1use std::io;
2
3use crate::video::capture::Parameters as CaptureParameters;
4use crate::video::output::Parameters as OutputParameters;
5use crate::{
6 format::Description as FormatDescription, format::Format, format::FourCC,
7 frameinterval::FrameInterval, framesize::FrameSize,
8};
9
10/// Capture device protocol
11pub trait Capture {
12 /// Returns a vector of all frame intervals that the device supports for the given pixel format
13 /// and frame size
14 fn enum_frameintervals(
15 &self,
16 fourcc: FourCC,
17 width: u32,
18 height: u32,
19 ) -> io::Result<Vec<FrameInterval>>;
20
21 /// Returns a vector of valid framesizes that the device supports for the given pixel format
22 fn enum_framesizes(&self, fourcc: FourCC) -> io::Result<Vec<FrameSize>>;
23
24 /// Returns a vector of valid formats for this device
25 ///
26 /// The "emulated" field describes formats filled in by libv4lconvert.
27 /// There may be a conversion related performance penalty when using them.
28 fn enum_formats(&self) -> io::Result<Vec<FormatDescription>>;
29
30 /// Returns the format currently in use
31 fn format(&self) -> io::Result<Format>;
32
33 /// Modifies the capture format and returns the actual format
34 ///
35 /// The driver tries to match the format parameters on a best effort basis.
36 /// Thus, if the combination of format properties cannot be achieved, the closest possible
37 /// settings are used and reported back.
38 ///
39 ///
40 /// # Arguments
41 ///
42 /// * `fmt` - Desired format
43 fn set_format(&self, fmt: &Format) -> io::Result<Format>;
44
45 /// Returns the parameters currently in use
46 fn params(&self) -> io::Result<CaptureParameters>;
47
48 /// Modifies the capture parameters and returns the actual parameters
49 ///
50 /// # Arguments
51 ///
52 /// * `params` - Desired parameters
53 fn set_params(&self, params: &CaptureParameters) -> io::Result<CaptureParameters>;
54}
55
56/// Output device protocol
57pub trait Output {
58 /// Returns a vector of all frame intervals that the device supports for the given pixel format
59 /// and frame size
60 fn enum_frameintervals(
61 &self,
62 fourcc: FourCC,
63 width: u32,
64 height: u32,
65 ) -> io::Result<Vec<FrameInterval>>;
66
67 /// Returns a vector of valid framesizes that the device supports for the given pixel format
68 fn enum_framesizes(&self, fourcc: FourCC) -> io::Result<Vec<FrameSize>>;
69
70 /// Returns a vector of valid formats for this device
71 ///
72 /// The "emulated" field describes formats filled in by libv4lconvert.
73 /// There may be a conversion related performance penalty when using them.
74 fn enum_formats(&self) -> io::Result<Vec<FormatDescription>>;
75
76 /// Returns the format currently in use
77 fn format(&self) -> io::Result<Format>;
78
79 /// Modifies the capture format and returns the actual format
80 ///
81 /// The driver tries to match the format parameters on a best effort basis.
82 /// Thus, if the combination of format properties cannot be achieved, the closest possible
83 /// settings are used and reported back.
84 ///
85 /// # Arguments
86 ///
87 /// * `fmt` - Desired format
88 fn set_format(&self, fmt: &Format) -> io::Result<Format>;
89
90 /// Returns the parameters currently in use
91 fn params(&self) -> io::Result<OutputParameters>;
92
93 /// Modifies the output parameters and returns the actual parameters
94 ///
95 /// # Arguments
96 ///
97 /// * `params` - Desired parameters
98 fn set_params(&self, params: &OutputParameters) -> io::Result<OutputParameters>;
99}