eye_hal/
lib.rs

1//! Eye is a cross platform camera capture and control library.
2//!
3//! Things like zero-copy buffer capture and transparent pixel format conversion are hallmark
4//! features of Eye which distinguish it from other camera capture crates.
5//!
6//! Additional documentation can currently also be found in the
7//! [README.md file which is most easily viewed on github](https://github.com/raymanfx/eye-rs/blob/master/README.md).
8//!
9//! [Jump forward to crate content](#reexports)
10//!
11//! # Overview
12//!
13//! Devices are created from platform specific indices. On Linux for example, the index 0 maps to
14//! the node present at /dev/video0 which is usually the first device seen by the kernel.
15//!
16//! Device instances can be used to perform various management and control tasks such as modifying
17//! the capture format, altering hardware parameters and more. For example, you would use the
18//! device API to set the exposure level or enable the autofocus mode of a connected camera.
19//!
20//! When it comes to actually capturing frames from the camera, you use the stream API instead.
21//! All devices offer a stream() call which returns the 'native' buffer stream, i.e. no copying is
22//! involved in userspace unless transparent format conversion is explicitly requested through the
23//! device API.
24//! Streams should abstract the native platform capture concepts and automatically choose the best
25//! way to grab frames from the camera as exposed by the OS drivers. For example, Linux platforms
26//! will almost always use mapped buffers or user mode buffers instead of just reading bytes into
27//! a userspace buffer which involves expensive copying in the driver.
28//!
29//! The common user of this crate will mainly be interested in frame capturing.
30//! Here is a very brief example of streaming I/O:
31//!
32//! ```no_run
33//! use eye_hal::PlatformContext;
34//! use eye_hal::traits::{Context, Device, Stream};
35//!
36//! // Create a context
37//! let ctx = PlatformContext::default();
38//!
39//! // Query for available devices.
40//! let devices = ctx.devices().expect("Failed to query devices");
41//! if devices.is_empty() {
42//!     panic!("No devices available");
43//! }
44//!
45//! // First, we need a capture device to read images from. For this example, let's just choose
46//! // whatever device is first in the list.
47//! let dev = ctx.open_device(&devices[0].uri).expect("Failed to open video device");
48//!
49//! // Query for available streams and just choose the first one.
50//! let streams = dev.streams().expect("Failed to query streams");
51//! let stream_desc = streams[0].clone();
52//! println!("Stream: {:?}", stream_desc);
53//!
54//! // Since we want to capture images, we need to access the native image stream of the device.
55//! // The backend will internally select a suitable implementation for the platform stream. On
56//! // Linux for example, most devices support memory-mapped buffers.
57//! let mut stream = dev.start_stream(&stream_desc).expect("Failed to setup capture stream");
58//!
59//! // Now we are all set to start capturing some frames!
60//! let _buf = stream
61//!     .next()
62//!     .expect("Stream is dead")
63//!     .expect("Failed to capture buffer");
64//!```
65
66//!
67//! Have a look at the examples to learn more about device and stream management.
68
69pub mod control;
70pub mod device;
71pub mod error;
72pub mod format;
73pub mod stream;
74pub mod traits;
75
76pub mod platform;
77
78pub use error::{Error, ErrorKind, Result};
79pub use platform::Context as PlatformContext;