Camera

Camera class for managing video capture and streaming.

#include <camera.hpp>

Classes

class Camera

High-level handle for camera streaming, photo capture, and video recording.

Provides three capability groups: - Live streaming — Start / Stop / SetFrameCallback - Photo capture — TakePhoto - Video recording — StartRecording / StopRecording / IsRecording

Capture routing: TakePhoto / StartRecording save on the ground computer (from the live stream), on the onboard computer, or both, selected by the capture-destination mask (SetCaptureMask, default kCaptureGround). Ground captures write to the local path passed in; onboard captures run on the vehicle and report their finalized file via SetMediaMetadataCallback. All of these run concurrently with the live feed.

struct Frame

Decoded video frame delivered via SetFrameCallback.

FieldTypeDescription
width uint32_t Frame width in pixels.
height uint32_t Frame height in pixels.
data const uint8_t* RGBA8888 pixels. Valid only during the callback.
size size_t Buffer size in bytes (== width*height*4).

enum VideoCodec

Video codec used for streaming.

ValueDescription
kH264 H.264 codec.
kH265 H.265 / HEVC codec.
kVP9 VP9 codec (royalty-free; software-only encode, WebM recording).

enum CameraKind

Physical camera / source kind reported by the onboard computer.

ValueDescription
kUnknown

enum Health

Streaming health reported by the onboard computer.

ValueDescription
kUnknown

struct Status

Snapshot of onboard camera status, from the periodic (~1 Hz) status report. `valid` is false until the first report arrives.

FieldTypeDescription
cameraInstance uint8_t 1 = primary camera
codec VideoCodec codec actually active onboard
kind CameraKind
width uint32_t 0 = unknown
height uint32_t 0 = unknown
bitrateKbps uint32_t 0 = unknown / passthrough
framerate uint32_t fps; 0 = unknown
streaming bool
recording bool
codecFallback bool onboard fell back (e.g. VP9→H264)
diskLow bool
health Health
recordElapsedSecs uint32_t live recording duration; 0 if idle
diskFreeMb uint32_t 0 = unknown
valid bool false until the first report arrives
~Camera()

Destroys the Camera handle.

auto SetCodec(VideoCodec codec) -> void

Select the video codec before calling Start().

Note:

Must match the onboard config "video_codec" value ("H264" or "H265"). Default is H264.

ParameterTypeDescription
codec VideoCodec Codec to use for decoding the incoming stream.
auto SetVideoCodec(VideoCodec codec) -> void

Switch the onboard encoder at runtime.

Also sets the local receive decoder to match. The codec the onboard computer actually applies may differ if it falls back to a codec it supports; the applied codec arrives via the status callback / GetActiveCodec() shortly after.

ParameterTypeDescription
codec VideoCodec Codec the onboard encoder should switch to.
auto SetStatusCallback(std::function<void(const Status&)> cb) -> void

Register a callback fired on each onboard status update (~1 Hz).

ParameterTypeDescription
cb std::function<void(const Status&)> Invoked with the freshly received Status.
auto Start(uint16_t port = 5600) -> bool

Start the live video feed on the given UDP port.

ParameterTypeDescription
port uint16_t UDP port to receive the video stream on. Defaults to 5600.

Returns: true if the stream started successfully.

auto Stop() -> void

Stop the live video feed.

auto SetFrameCallback(std::function<void(const Frame&)> callback) -> void

Register a callback invoked for every decoded frame.

Note:

Invoked on an internal decode worker thread — not your UI thread. Keep the callback quick and marshal to your renderer (e.g. copy the RGBA pixels, see Frame). @c Frame::data is only valid for the duration of the call.

ParameterTypeDescription
callback std::function<void(const Frame&)>
auto TakePhoto(const std::string& filepath = "") -> bool

Take a photo, routed by the current capture-destination mask.

Destination depends on SetCaptureMask (default kCaptureGround): - kCaptureGround: saves a JPEG on the ground computer from the live stream (works while streaming), written to @p filepath. - kCaptureOnboard: asks the onboard computer to capture; the finalized file is reported asynchronously via SetMediaMetadataCallback (fire-and-forget). - kCaptureBoth: both of the above.

ParameterTypeDescription
filepath const std::string& Destination path (e.g. "/data/photo.jpg").

Returns: true if the request was accepted for the selected destination(s).

auto TakePhoto(const std::string& filepath, uint8_t mask) -> bool

Take a photo to an explicit destination, overriding the mask for this one call (does not change the persistent capture mask).

ParameterTypeDescription
filepath const std::string& Destination path; "" auto-generates a timestamped name.
mask uint8_t OR-combination of kCaptureGround / kCaptureOnboard

Returns: See TakePhoto(filepath).

auto StartRecording(const std::string& filepath = "") -> bool

Start recording, routed by the current capture-destination mask.

Like TakePhoto, honors SetCaptureMask: kCaptureGround records on the ground computer (MP4) at @p filepath; kCaptureOnboard records on the vehicle (finalized file reported via SetMediaMetadataCallback); kCaptureBoth does both. Runs in parallel with the live stream.

ParameterTypeDescription
filepath const std::string& Destination path (e.g. "/data/clip.mp4").

Returns: true if recording started for the selected destination(s).

auto StopRecording() -> void

Stop recording and finalize the output file.

auto IsRecording() const -> bool

Returns true while a recording is in progress.

Returns: true if recording is active, false otherwise.

auto GetCaptureMask() const -> uint8_t

Get the current capture destination bitmask.

Returns: Bitmask indicating where captures are sent (OR of kCaptureGround / kCaptureOnboard).

auto SetCaptureMask(uint8_t mask) -> void

Set capture destination bitmask.

ParameterTypeDescription
mask uint8_t OR-combination of kCaptureGround and/or kCaptureOnboard.
auto SetMediaMetadataCallback( std::function<void(const std::string&, uint64_t, uint32_t)> cb) -> void

Register a callback fired when the onboard computer reports a finalized capture (photo or recording).

This is how onboard (kCaptureOnboard) TakePhoto / StartRecording report their result, since those calls are fire-and-forget. For a photo, duration_secs is 0.

ParameterTypeDescription
std::string& std::function<void(const
cb uint32_t)> Signature: callback(remote_filepath, size_bytes, duration_secs)

Constants

NameValueDescription
kCaptureNone 0x00 Capture destination bitmask constants.