libuvc 0.1.0

Safe wrapper around libuvc, a cross-platform library for USB video devices
use libuvc::{Context, Error, FrameFormat, Timeout, VsDescSubtype};

fn main() -> Result<(), Error> {
    let ctx = Context::new()?;
    let dev = ctx.find_device(None, None, None)?;
    let devh = dev.open()?;

    let format = devh
        .format_descs()
        .find(|f| f.descriptor_subtype() == VsDescSubtype::FormatMjpeg)
        .unwrap();
    let frame = format
        .frame_descs()
        .find(|f| f.descriptor_subtype() == VsDescSubtype::FrameMjpeg)
        .unwrap();

    let mut ctrl = devh.get_stream_ctrl_format_size(
        FrameFormat::Mjpeg,
        Some(frame.width().into()),
        Some(frame.height().into()),
        None,
    )?;

    let strmh = devh.open_stream(&mut ctrl)?;
    strmh.start()?;
    let frame = strmh.frame(Timeout::Forever)?;
    strmh.stop()?;

    std::fs::write("capture.jpg", frame.data()).unwrap();

    Ok(())
}