Introduce a global array that keep track of every opened device
A device can be shared between multiple capture backend, but only one can open the stream
Cleaning of dropped device is done lazily
There is no fuzzing test in the library, or anything so I tested everything in the capture example:
let mut other_camera = Camera::new(index.clone(), requested.clone()).unwrap();
let callback_index = index.clone();
let callback_requested = requested.clone();
let mut cb = CallbackCamera::new(index.clone(), requested.clone(), move |buf| {
println!("Captured frame of size {}", buf.buffer().len());
other_camera
.open_stream()
.expect_err("Should not be able to open stream while other stream is open");
let controls = other_camera.camera_controls().expect("Should be able to get controls, other camera just used to fetch stream at the moment");
println!("Controls: {controls:?}");
let _ = Camera::new(callback_index.clone(), callback_requested.clone())
.expect("Should be able to still open a camera and close it");
})
.unwrap();
cb.open_stream().unwrap();
loop {
std::thread::sleep(std::time::Duration::from_millis(1000));
}
fix #123
There is no fuzzing test in the library, or anything so I tested everything in the capture example:
fix #123