1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//! Prints detailed device information.
use std::{env, io, path::Path};
use anyhow::anyhow;
use linuxvideo::{controls::CtrlType, format::FrameSizes, BufType, Device};
fn main() -> anyhow::Result<()> {
env_logger::init();
let mut args = env::args_os().skip(1);
let path = args.next().ok_or_else(|| anyhow!("usage: info <device>"))?;
let device = Device::open(Path::new(&path))?;
list_device(device)?;
Ok(())
}
fn list_device(device: Device) -> io::Result<()> {
let caps = device.capabilities()?;
println!("card: {}", caps.card());
println!("driver: {}", caps.driver());
println!("bus info: {}", caps.bus_info());
println!("all capabilities: {:?}", caps.all_capabilities());
println!("avail. capabilities: {:?}", caps.device_capabilities());
for buf in device.supported_buf_types() {
println!("- supported formats for {:?} buffers:", buf);
for res in device.formats(buf) {
match res {
Ok(fmt) => {
println!(" - [{}] {}", fmt.pixel_format(), fmt.description());
if !fmt.flags().is_empty() {
println!(" {:?}", fmt.flags());
}
if buf == BufType::META_CAPTURE || buf == BufType::META_OUTPUT {
// Metadata formats like `UVCH` will return an error from `frame_sizes`.
continue;
}
let sizes = match device.frame_sizes(fmt.pixel_format()) {
Ok(sizes) => sizes,
Err(e) => {
println!(" - error while fetching supported frame sizes: {}", e);
continue;
}
};
match sizes {
FrameSizes::Discrete(iter) => {
for size in iter {
let intervals = device.frame_intervals(
fmt.pixel_format(),
size.width(),
size.height(),
)?;
println!(
" - [{:2}] {}x{} @ {}",
size.index(),
size.width(),
size.height(),
intervals,
);
}
}
FrameSizes::Stepwise(s) => {
let min_ivals = device.frame_intervals(
fmt.pixel_format(),
s.min_width(),
s.min_height(),
)?;
let max_ivals = device.frame_intervals(
fmt.pixel_format(),
s.max_width(),
s.max_height(),
)?;
println!(
" - {}x{} to {}x{} (step {}x{}) @ {} to {}",
s.min_width(),
s.min_height(),
s.max_width(),
s.max_height(),
s.step_width(),
s.step_height(),
min_ivals,
max_ivals,
);
}
FrameSizes::Continuous(s) => {
let min_ivals = device.frame_intervals(
fmt.pixel_format(),
s.min_width(),
s.min_height(),
)?;
let max_ivals = device.frame_intervals(
fmt.pixel_format(),
s.max_width(),
s.max_height(),
)?;
println!(
" - {}x{} to {}x{} @ {} to {}",
s.min_width(),
s.min_height(),
s.max_width(),
s.max_height(),
min_ivals,
max_ivals,
);
}
}
}
Err(e) => {
println!(" - error: {}", e);
}
}
}
println!("- active format for {:?} buffer:", buf);
match device.format(buf) {
Ok(format) => {
println!(" {:?}", format);
}
Err(e) => {
println!(" error: {}", e);
}
}
}
println!("- inputs:");
for res in device.inputs() {
match res {
Ok(input) => {
println!(" - [{:?}] {}", input.input_type(), input.name());
println!(" audioset: {:#b}", input.audioset());
println!(" tuner: {}", input.tuner());
println!(" std: {:?}", input.std());
println!(" capabilities: {:?}", input.capabilities());
}
Err(e) => {
println!(" - error: {}", e);
}
}
}
println!("- outputs:");
for res in device.outputs() {
match res {
Ok(output) => {
println!(" - [{:?}] {}", output.output_type(), output.name());
println!(" audioset: {:#b}", output.audioset());
println!(" modulator: {}", output.modulator());
println!(" std: {:?}", output.std());
println!(" capabilities: {:?}", output.capabilities());
}
Err(e) => {
println!(" - error: {}", e);
}
}
}
println!("- controls:");
for res in device.controls() {
match res {
Ok(desc) => {
print!(
" - [{:?}] \"{}\", {:?}",
desc.id(),
desc.name(),
desc.control_type()
);
match desc.control_type() {
CtrlType::INTEGER => {
print!(" [{}-{}", desc.minimum(), desc.maximum());
let step = desc.step();
if step != 1 {
print!(", step={step}");
}
print!(", default={}]", desc.default_value());
}
CtrlType::MENU => {
print!(" [{}-{}]", desc.minimum(), desc.maximum());
}
_ => {}
}
println!();
if !desc.flags().is_empty() {
println!(" {:?}", desc.flags());
}
if desc.control_type() == CtrlType::MENU {
// Enumerate menu options.
for res in device.enumerate_menu(&desc) {
match res {
Ok(item) => {
println!(" {}: {}", item.index(), item.name());
}
Err(e) => {
println!(" error: {}", e);
}
}
}
}
}
Err(e) => {
println!(" - error: {}", e);
}
}
}
println!();
Ok(())
}