Crate ci2_async

source ·
Expand description

This crate defines a trait, AsyncCamera, whose AsyncCamera::frames method returns a futures::Stream for asynchronous usage.

It also provides a struct, ThreadedAsyncCameraModule which will take a camera module implementing the ci2::CameraModule trait and wrap it into a new struct that also implements the ci2::CameraModule in addition to returning a ThreadedAsyncCamera which implements the AsyncCamera trait.

For ThreadedAsyncCameraModule to work, it requires that the wrapped camera type C implements the ci2::Camera and Send traits. It operates by serializing access to the camera by wrapping Arc<Mutex<C>>. The AsyncCamera::frames method spawns a thread on on which an infinite loop is used to grab frames from the camera. Therefore other camera access happens only between frame acquisitions. Thus, when image exposure times are on the order of 10 msec, this calls to access the camera (e.g. to chance exposure time) may block for about 10 msec.

The structs ThreadedAsyncCameraModule and ThreadedAsyncCamera here are a generic implementation that can be used at the cost of spawning a new thread.

It would be possible for an upstream camera backend module to directly implement the AsyncCamera trait. Such a camera-specific backend could implement AsyncCamera without serializing access to the camera but rather by taking advantage of functionality in most camera drivers.

Structs§

Enums§

Traits§

  • Defines a method to return a stream of frames.

Functions§