vidi_configs/
vidi_configs.rs

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
/*
 * SPDX-FileCopyrightText: 2024 DorotaC
 *
 * SPDX-License-Identifier: MIT OR Apache-2.0
 */

/*! Lists available camera configurations.
*/

use clap::Parser;
use std::io;
use vidi;
use vidi::config::ConfigRequest;

/// Shows the matching formats for selected parameters.
///
/// Skipped parameters will be considered as "anything is fine".
#[derive(Parser)]
#[clap(about)]
struct Args {
    /// Width in pixels
    #[arg(long)]
    width: Option<u32>,
    /// Height in pixels
    #[arg(long)]
    height: Option<u32>,
    /// FourCC code, e.g. YUYV or MJPG
    #[arg(long)]
    #[clap(value_parser = |s: &str| s.as_bytes().try_into().map(vidi::FourCC::new))]
    fourcc: Option<vidi::FourCC>,
    /// How many configs should be printed at most
    #[arg(long, default_value_t=32)]
    count: usize,
}

fn main() -> io::Result<()> {
    let cameras_list = vidi::actors::camera_list::spawn()?;
    let cameras = cameras_list.cameras();
    let camera = cameras_list.create(&cameras[0].info.id())
        .expect("No such camera")
        .expect("Failed to get camera");
    dbg!(camera.get_id());
    {
        let mut camera = camera.acquire();
        if let Ok(ref mut camera) = camera {
            let db = camera.get_supported_configs()?;
            let args = Args::parse();
            let request = ConfigRequest {
                width: args.width,
                height: args.height,
                fourcc: args.fourcc,
                ..ConfigRequest::default()
            };
            for (i, config) in db.query_configs(request).iter().enumerate() {
                if i > args.count {
                    println!("More configs available...");
                    break;
                }
                println!("Config: {:?}", config);
            }
        }
    }
    Ok(())
}