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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/*! Safe wrapper around `libuvc` This crate gives access to webcams connected to the computer, allowing one to stream and capture video. # How to use this crate ```no_run use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::time::Duration; // Get a libuvc context let ctx = uvc::Context::new().expect("Could not get context"); // Get a default device let dev = ctx .find_device(None, None, None) .expect("Could not find device"); // Or create an iterator over all available devices let mut _devices = ctx.devices().expect("Could not enumerate devices"); // The device must be opened to create a handle to the device let devh = dev.open().expect("Could not open device"); // Most webcams support this format let format = uvc::StreamFormat { width: 640, height: 480, fps: 30, format: uvc::FrameFormat::YUYV, }; // Get the necessary stream information let mut streamh = devh .get_stream_handle_with_format(format) .expect("Could not open a stream with this format"); // This is a counter, increasing by one for every frame // This data must be 'static + Send + Sync to be used in // the callback used in the stream let counter = Arc::new(AtomicUsize::new(0)); // Get a stream, calling the closure as callback for every frame let stream = streamh .start_stream( |_frame, count| { count.fetch_add(1, Ordering::SeqCst); }, counter.clone(), ).expect("Could not start stream"); // Wait 10 seconds std::thread::sleep(Duration::new(10, 0)); // Explicitly stop the stream // The stream would also be stopped // when going out of scope (dropped) stream.stop(); println!("Counter: {}", counter.load(Ordering::SeqCst)); ``` See also `mirror.rs` in the examples to get an example of how to capture and display a stream */ mod context; mod controls; mod device; mod error; mod formats; mod frame; mod streaming; pub use streaming::{ActiveStream, StreamHandle}; pub use context::Context; pub use controls::{AutoExposureMode, AutoExposurePriority, ScanningMode}; pub use device::{ DescriptionSubtype, Device, DeviceDescription, DeviceHandle, DeviceList, FormatDescriptor, FormatDescriptors, FrameDescriptor, FrameDescriptors, }; pub use error::{Error, Result}; pub use formats::{FrameFormat, StreamFormat}; pub use frame::Frame;