Skip to main content

Camera

Trait Camera 

Source
pub trait Camera: Send + Sync {
    // Required methods
    fn start(&self) -> Result<(), CameraError>;
    fn stop(&self);

    // Provided methods
    fn request_still(&self) -> Result<(), CameraError> { ... }
    fn set_torch(&self, _on: bool) -> bool { ... }
    fn lenses(&self) -> Vec<CameraLens> { ... }
    fn lens(&self) -> Option<String> { ... }
    fn use_lens(&self, _id: &str) -> bool { ... }
    fn has_flash(&self) -> bool { ... }
    fn set_flash(&self, _mode: FlashMode) -> bool { ... }
}
Expand description

A platform capture session.

A backend starts and stops the device and publishes what it produces through publish_camera_frame and publish_camera_state; nothing here is polled, and no method blocks for the length of a capture.

Required Methods§

Source

fn start(&self) -> Result<(), CameraError>

Opens the session.

Returns as soon as the request is accepted. The session’s progress arrives as CameraState, because opening a camera takes long enough on a phone that a screen has to show something in the meantime.

Source

fn stop(&self)

Stops the session and releases the device.

Provided Methods§

Source

fn request_still(&self) -> Result<(), CameraError>

Asks for a full-resolution still.

The picture arrives through publish_camera_still, because the device takes as long as it takes to expose and encode, and a call that blocked for it would block whatever asked.

Source

fn set_torch(&self, _on: bool) -> bool

Turns the torch on or off while the session runs.

Scanner-style applications light a dim scene rather than analysing photon-starved frames. Returns false where the device has no torch; the torch dies with the session.

Source

fn lenses(&self) -> Vec<CameraLens>

The devices the application may pick between, back cameras first and in field-of-view order, widest first, then the rest.

An empty list means the application shows no lens control: either the platform has one camera or the backend does not list them. Backends also publish this through publish_camera_lenses when a session opens, so a screen observes rememberCameraLenses rather than paying this blocking platform call per recomposition.

Source

fn lens(&self) -> Option<String>

The device the session is using, or None when nothing is open and the backend has no stored choice.

Source

fn use_lens(&self, _id: &str) -> bool

Opens id instead of the current device, keeping the session running. Returns false when the id is unknown or the backend cannot switch.

Source

fn has_flash(&self) -> bool

Whether the current device has a flash for stills.

Source

fn set_flash(&self, _mode: FlashMode) -> bool

What the flash does on the next still. Returns false where the device has no flash; the mode dies with the session.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§