1use bitflags::bitflags;
2use std::{fmt, str};
3
4use crate::v4l_sys::*;
5
6bitflags! {
7 #[allow(clippy::unreadable_literal)]
8 pub struct Flags: u32 {
9 const VIDEO_CAPTURE = 0x00000001;
10 const VIDEO_OUTPUT = 0x00000002;
11 const VIDEO_OVERLAY = 0x00000004;
12 const VBI_CAPTURE = 0x00000010;
13 const VBI_OUTPUT = 0x00000020;
14 const SLICED_VBI_CAPTURE = 0x00000040;
15 const SLICED_VBI_OUTPUT = 0x00000080;
16 const RDS_CAPTURE = 0x00000100;
17 const VIDEO_OUTPUT_OVERLAY = 0x00000200;
18 const HW_FREQ_SEEK = 0x00000400;
19 const RDS_OUTPUT = 0x00000800;
20
21 const VIDEO_CAPTURE_MPLANE = 0x00001000;
22 const VIDEO_OUTPUT_MPLANE = 0x00002000;
23 const VIDEO_M2M_MPLANE = 0x00004000;
24 const VIDEO_M2M = 0x00008000;
25
26 const TUNER = 0x00010000;
27 const AUDIO = 0x00020000;
28 const RADIO = 0x00040000;
29 const MODULATOR = 0x00080000;
30
31 const SDR_CAPTURE = 0x00100000;
32 const EXT_PIX_FORMAT = 0x00200000;
33 const SDR_OUTPUT = 0x00400000;
34 const META_CAPTURE = 0x00800000;
35
36 const READ_WRITE = 0x01000000;
37 const ASYNC_IO = 0x02000000;
38 const STREAMING = 0x04000000;
39 const META_OUTPUT = 0x08000000;
40
41 const TOUCH = 0x10000000;
42
43 const DEVICE_CAPS = 0x80000000;
44 }
45}
46
47impl From<u32> for Flags {
48 fn from(flags: u32) -> Self {
49 Self::from_bits_truncate(flags)
50 }
51}
52
53impl From<Flags> for u32 {
54 fn from(flags: Flags) -> Self {
55 flags.bits()
56 }
57}
58
59impl fmt::Display for Flags {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 fmt::Debug::fmt(self, f)
62 }
63}
64
65#[derive(Debug)]
66pub struct Capabilities {
68 pub driver: String,
70 pub card: String,
72 pub bus: String,
74 pub version: (u8, u8, u8),
76
77 pub capabilities: Flags,
79}
80
81impl From<v4l2_capability> for Capabilities {
82 fn from(cap: v4l2_capability) -> Self {
83 Self {
84 driver: str::from_utf8(&cap.driver)
85 .unwrap()
86 .trim_matches(char::from(0))
87 .to_string(),
88 card: str::from_utf8(&cap.card)
89 .unwrap()
90 .trim_matches(char::from(0))
91 .to_string(),
92 bus: str::from_utf8(&cap.bus_info)
93 .unwrap()
94 .trim_matches(char::from(0))
95 .to_string(),
96 version: (
97 ((cap.version >> 16) & 0xff) as u8,
98 ((cap.version >> 8) & 0xff) as u8,
99 (cap.version & 0xff) as u8,
100 ),
101 capabilities: Flags::from(cap.device_caps),
102 }
103 }
104}
105
106impl fmt::Display for Capabilities {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108 writeln!(f, "Driver : {}", self.driver)?;
109 writeln!(f, "Card : {}", self.card)?;
110 writeln!(f, "Bus : {}", self.bus)?;
111 writeln!(
112 f,
113 "Version : {}.{}.{}",
114 self.version.0, self.version.1, self.version.2
115 )?;
116 writeln!(f, "Capabilities : {}", self.capabilities)?;
117 Ok(())
118 }
119}