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§
- Camera
Frame - One frame from the viewfinder.
- Camera
Lens - One capture device the application may pick.
- Camera
Lenses - The devices the application may pick between, and the one in use.
- Camera
Observer - Keeps a camera observer registered until it is dropped.
- Camera
Still - A full-resolution still photograph as an encoded image.
- Upright
Rgba - A frame’s pixels as tightly packed RGBA8, already the right way up.
Enums§
- Camera
Error - Camera
State - What the camera session is doing.
- Flash
Mode - What the light does when a still is captured.
- Frame
Format - How a frame’s pixels are laid out.
- Lens
Facing - Which way a capture device points.
Traits§
- Camera
- A platform capture session.
Functions§
- camera
- The installed camera, or
Nonewhere 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
Nonebefore the first one. - observe_
camera_ frames - Registers
observerfor frames. Applications collectrememberCameraFramesinstead of calling this. - observe_
camera_ lenses - Registers
observerfor 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
observerfor 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
observerfor 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.
- remember
Camera Frames - The frames the session produces, as a stream this composition collects.
- remember
Camera Lenses - The lens list and the device in use, observed for as long as this call stays in the composition.
- remember
Camera State - What the camera session is doing, observed for as long as this call stays in the composition.
- remember
Camera Stills - 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::Startingbefore 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§
- Camera
Ref - Shared handle to the platform camera.