[][src]Struct v4l::output::device::Device

pub struct Device { /* fields omitted */ }

Linux output device abstraction

Implementations

impl Device[src]

pub fn new(index: usize) -> Result<Self>[src]

Returns an output device by index

Devices are usually enumerated by the system. An index of zero thus represents the first device the system got to know about.

Arguments

  • index - Index (0: first, 1: second, ..)

Example

use v4l::output::Device;
let dev = Device::new(0);

pub fn with_path<P: AsRef<Path>>(path: P) -> Result<Self>[src]

Returns an output device by path

Linux device nodes are usually found in /dev/videoX or /sys/class/video4linux/videoX.

Arguments

  • path - Path (e.g. "/dev/video0")

Example

use v4l::output::Device;
let dev = Device::with_path("/dev/video0");

pub fn enum_formats(&self) -> Result<Vec<Description>>[src]

Returns a vector of valid formats for this device

The "emulated" field describes formats filled in by libv4lconvert. There may be a conversion related performance penalty when using them.

Example

use v4l::output::Device;

if let Ok(dev) = Device::new(0) {
    let formats = dev.enum_formats();
    if let Ok(formats) = formats {
        for fmt in formats {
            print!("{}", fmt);
        }
    }
}

pub fn format(&self) -> Result<Format>[src]

Returns the format currently in use

Example

use v4l::output::Device;

if let Ok(dev) = Device::new(0) {
    let fmt = dev.format();
    if let Ok(fmt) = fmt {
        print!("Active format:\n{}", fmt);
    }
}

pub fn set_format(&mut self, fmt: &Format) -> Result<Format>[src]

Modifies the output format and returns the actual format

The driver tries to match the format parameters on a best effort basis. Thus, if the combination of format properties cannot be achieved, the closest possible settings are used and reported back.

Arguments

  • fmt - Desired format

Example

use v4l::output::Device;

if let Ok(mut dev) = Device::new(0) {
    let fmt = dev.format();
    if let Ok(mut fmt) = fmt {
        fmt.width = 640;
        fmt.height = 480;
        print!("Desired format:\n{}", fmt);

        let fmt = dev.set_format(&fmt);
        match fmt {
            Ok(fmt) => print!("Actual format:\n{}", fmt),
            Err(e) => print!("{}", e),
        }
    }
}

pub fn params(&self) -> Result<Parameters>[src]

Returns the parameters currently in use

Example

use v4l::output::Device;

if let Ok(dev) = Device::new(0) {
    let params = dev.params();
    if let Ok(params) = params {
        print!("Active parameters:\n{}", params);
    }
}

pub fn set_params(&mut self, params: &Parameters) -> Result<Parameters>[src]

Modifies the output parameters and returns the actual parameters

Arguments

  • params - Desired parameters

Example

use v4l::output::{Device, Parameters};

if let Ok(mut dev) = Device::new(0) {
    let params = dev.params();
    if let Ok(mut params) = params {
        params = Parameters::with_fps(30);
        print!("Desired parameters:\n{}", params);

        let params = dev.set_params(&params);
        match params {
            Ok(params) => print!("Actual parameters:\n{}", params),
            Err(e) => print!("{}", e),
        }
    }
}

pub fn control(&self, id: u32) -> Result<Control>[src]

Returns the control value for an ID

Arguments

  • id - Control identifier

Example

use v4l::output::Device;
use v4l::Control;
use v4l2_sys::V4L2_CID_BRIGHTNESS;

if let Ok(dev) = Device::new(0) {
    let ctrl = dev.control(V4L2_CID_BRIGHTNESS);
    if let Ok(val) = ctrl {
        match val {
            Control::Value(val) => { println!("Brightness: {}", val) }
            _ => {}
        }
    }
}

pub fn set_control(&mut self, id: u32, val: Control) -> Result<()>[src]

Modifies the control value

Arguments

  • id - Control identifier
  • val - New value

Example

use v4l::output::Device;
use v4l::Control;
use v4l2_sys::V4L2_CID_BRIGHTNESS;

if let Ok(mut dev) = Device::new(0) {
    dev.set_control(V4L2_CID_BRIGHTNESS, Control::Value(0))
        .expect("Failed to set brightness");
}

Trait Implementations

impl Device for Device[src]

fn handle(&self) -> Arc<Handle>[src]

Returns the handle of the device

Example

use v4l::output::Device as OutputDevice;
use v4l::device::Device;

if let Ok(dev) = OutputDevice::new(0) {
    print!("Device file descriptor: {}", dev.handle().fd());
}

impl TryFrom<Info> for Device[src]

type Error = Error

The type returned in the event of a conversion error.

impl Write for Device[src]

Auto Trait Implementations

impl RefUnwindSafe for Device

impl Send for Device

impl Sync for Device

impl Unpin for Device

impl UnwindSafe for Device

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> QueryDevice for T where
    T: Device
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.