Skip to main content

Module camera

Module camera 

Source
Expand description

The live camera: what it is doing, the frames it is producing, and the stills it takes.

Three things about a camera are easy to get wrong and expensive to get wrong twice, so the framework owns all three.

A camera is observable, not polled. A viewfinder that asks “is there a new frame yet?” every frame does that work whether or not one arrived, and learns about a failure only by noticing that frames stopped. Here the session publishes what it is doing and the frames it produces, and a screen reacts.

Frames arrive in the format the sensor produced. Encoding a preview frame as JPEG to hand it across a language boundary and decoding it back costs several milliseconds per frame, every frame, to arrive at the pixels the camera already had. FrameFormat::Nv12 is what a phone camera actually produces, and it converts to RGBA in one pass over the bytes.

Analysis is bounded and latest-wins. A detector that takes longer than a frame interval must fall behind rather than accumulate: a queue of stale frames costs memory to hold and produces answers about a scene that has already moved.

Structs§

CameraFrame
One frame from the viewfinder.
CameraLens
One capture device the application may pick.
CameraLenses
The devices the application may pick between, and the one in use.
CameraObserver
Keeps a camera observer registered until it is dropped.
CameraStill
A full-resolution still photograph as an encoded image.
UprightRgba
A frame’s pixels as tightly packed RGBA8, already the right way up.

Enums§

CameraError
CameraState
What the camera session is doing.
FlashMode
What the light does when a still is captured.
FrameFormat
How a frame’s pixels are laid out.
LensFacing
Which way a capture device points.

Traits§

Camera
A platform capture session.

Functions§

camera
The installed camera, or None where live capture is unsupported — which is when an application falls back to the image picker.
camera_lenses
The devices the application may pick between, as the backend last published them.
camera_state
What the session is doing.
camera_supported
Whether this platform has a live camera at all.
capture_camera_still
Takes one full-resolution still and resolves with it.
clear_platform_camera
Removes the platform camera and forgets everything the last session published.
dropped_camera_frames
How many frames were produced while every observer was still busy.
latest_camera_frame
The last frame the session produced, or None before the first one.
observe_camera_frames
Registers observer for frames. Applications collect rememberCameraFrames instead of calling this.
observe_camera_lenses
Registers observer for the lens list. The current list is delivered at once, so a screen composed mid-session shows the devices rather than waiting for the next change.
observe_camera_state
Registers observer for session state. The current state is delivered at once, so a screen composed mid-session shows what is happening rather than waiting for the next change.
observe_camera_stills
Registers observer for stills.
publish_camera_frame
Publishes a frame. Backends call this from whichever thread the platform delivers frames on.
publish_camera_lenses
Publishes the lens list and the device in use. Backends call this when a session opens and when the device changes.
publish_camera_state
Publishes what the session is doing.
publish_camera_still
Publishes the answer to a still request.
record_dropped_camera_frame
Records that the platform produced a frame nobody could take.
rememberCameraFrames
The frames the session produces, as a stream this composition collects.
rememberCameraLenses
The lens list and the device in use, observed for as long as this call stays in the composition.
rememberCameraState
What the camera session is doing, observed for as long as this call stays in the composition.
rememberCameraStills
The stills the session produces, as a stream this composition collects.
request_camera_still
Asks for a full-resolution still, which arrives through rememberCameraStills.
set_platform_camera
Installs the platform camera, replacing any previous one.
start_camera
Starts the camera, publishing CameraState::Starting before the backend is asked so a screen shows the wait rather than a gap.
stop_camera
Stops the camera and releases the device.

Type Aliases§

CameraRef
Shared handle to the platform camera.