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

/*! Fetches a frame from the first camera and decodes it using the GPU.
 * WIP: unfinished!
*/

use std::fs;
use std::io;
use std::io::Write;
use vidi;
use vidi::{Config, CaptureStream, FourCC};


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 mut stream = camera.start(
                Config{fourcc: FourCC::new(b"YUYV"), width: 640, height: 480},
                4
            ).unwrap();
            let (buf, meta, _next) = stream.next().unwrap();
            
            let mmap = buf.memory_map_ro().unwrap();
            let data = mmap.as_slice();

            println!(
                "Buffer size: {}, seq: {}, timestamp: {}",
                data.len(),
                meta.sequence,
                meta.timestamp
            );
            fs::File::create("frame.yuyv").unwrap().write_all(&data).unwrap();
        }
    }
    Ok(())
}