vidi_loop_frames/vidi_loop_frames.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
/* Copyright (C) 2024 DorotaC
* SPDX-License-Identifier: MIT OR Apache-2.0
*/
/*! Fetches frames from the first camera, forever.
*
* Exit with Ctrl+C.
*/
use std::io;
use vidi;
use vidi::CaptureStream;
use vidi::config::ConfigRequest;
fn main() -> io::Result<()> {
let cameras_list = vidi::actors::camera_list::spawn()?;
let cameras = cameras_list.cameras();
// Take the first camera
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 configs = camera.get_supported_configs()?;
let config = configs.query_configs(ConfigRequest {
// Fill in desired properties here.
// See the configs example for configurations available in your camera
//fourcc: Some(vidi::FourCC::new(b"YUYV")),
//width: Some(640),
//height: Some(480),
..ConfigRequest::default()
}).iter().next().expect("No supported configs");
let mut stream = camera.start(config, 4).unwrap();
loop {
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
);
}
}
}
Ok(())
}