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.
| Field | Type | Description |
|---|---|---|
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.
| Value | Description |
|---|---|
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.
| Value | Description |
|---|---|
kUnknown |
enum Health
Streaming health reported by the onboard computer.
| Value | Description |
|---|---|
kUnknown |
struct Status
Snapshot of onboard camera status, from the periodic (~1 Hz) status report. `valid` is false until the first report arrives.
| Field | Type | Description |
|---|---|---|
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) -> voidSelect the video codec before calling Start().
Must match the onboard config "video_codec" value ("H264" or "H265"). Default is H264.
| Parameter | Type | Description |
|---|---|---|
codec |
VideoCodec |
Codec to use for decoding the incoming stream. |
auto SetVideoCodec(VideoCodec codec) -> voidSwitch 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.
| Parameter | Type | Description |
|---|---|---|
codec |
VideoCodec |
Codec the onboard encoder should switch to. |
auto SetStatusCallback(std::function<void(const Status&)> cb) -> voidRegister a callback fired on each onboard status update (~1 Hz).
| Parameter | Type | Description |
|---|---|---|
cb |
std::function<void(const Status&)> |
Invoked with the freshly received Status. |
auto Start(uint16_t port = 5600) -> boolStart the live video feed on the given UDP port.
| Parameter | Type | Description |
|---|---|---|
port |
uint16_t |
UDP port to receive the video stream on. Defaults to 5600. |
Returns: true if the stream started successfully.
auto Stop() -> voidStop the live video feed.
auto SetFrameCallback(std::function<void(const Frame&)> callback) -> voidRegister a callback invoked for every decoded frame.
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.
| Parameter | Type | Description |
|---|---|---|
callback |
std::function<void(const Frame&)> |
auto TakePhoto(const std::string& filepath = "") -> boolTake 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.
| Parameter | Type | Description |
|---|---|---|
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) -> boolTake a photo to an explicit destination, overriding the mask for this one call (does not change the persistent capture mask).
| Parameter | Type | Description |
|---|---|---|
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 = "") -> boolStart 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.
| Parameter | Type | Description |
|---|---|---|
filepath |
const std::string& |
Destination path (e.g. "/data/clip.mp4"). |
Returns: true if recording started for the selected destination(s).
auto StopRecording() -> voidStop recording and finalize the output file.
auto IsRecording() const -> boolReturns true while a recording is in progress.
Returns: true if recording is active, false otherwise.
auto GetCaptureMask() const -> uint8_tGet the current capture destination bitmask.
Returns: Bitmask indicating where captures are sent (OR of kCaptureGround / kCaptureOnboard).
auto SetCaptureMask(uint8_t mask) -> voidSet capture destination bitmask.
| Parameter | Type | Description |
|---|---|---|
mask |
uint8_t |
OR-combination of kCaptureGround and/or kCaptureOnboard. |
auto SetMediaMetadataCallback( std::function<void(const std::string&, uint64_t, uint32_t)> cb) -> voidRegister 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.
| Parameter | Type | Description |
|---|---|---|
std::string& |
std::function<void(const |
|
cb |
uint32_t)> |
Signature: callback(remote_filepath, size_bytes, duration_secs) |
Constants
| Name | Value | Description |
|---|---|---|
kCaptureNone |
0x00 |
Capture destination bitmask constants. |