l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
482 stars 111 forks source link

🐛 v4l support share device handle, to behave like MF backend #127

Closed OlivierLDff closed 1 year ago

OlivierLDff commented 1 year ago

fix #123

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