Headless Mode on C++
The SmartSpectra C++ SDK is headless by default — wire up metric and frame callbacks for custom integrations.
The SDK doesn't ship UI. Register lambdas with SetOnMetrics,
SetOnVideoOutput, and SetOnError; rendering is your code's job. The
C++ sample apps show reference UI implementations.
Use this when you want to:
- Render metrics in your own UI
- Process metrics with no UI at all (logging, server-side, batch)
- Feed your own frames instead of the SDK's built-in camera
Lifecycle states, reported via OnProcessingStatusChangedFn and GetStatus():
| Status | Value | Meaning |
|---|---|---|
kUninitialized | 0 | SDK constructed but not yet initialized |
kIdle | 1 | Pipeline is not running |
kStarting | 2 | Pipeline is initializing |
kRunning | 3 | Actively measuring — data is flowing |
kStopping | 4 | Teardown in progress, will return to kIdle |
kError | 5 | Something went wrong |
namespace spectra = presage::smartspectra;
spectra::SmartSpectraConfig config;
config.api_key = "YOUR_API_KEY";
config.requested_metrics = spectra::SmartSpectraConfig::BreathingMetrics();
spectra::SmartSpectra sdk(config);
sdk.SetOnMetrics([](const spectra::Metrics& metrics, int64_t ts) {
// Process metrics
});
sdk.SetOnVideoOutput([](const spectra::FrameBuffer& frame, int64_t ts) {
// Optional: render frame in your own UI
});
if (const auto source_error =
sdk.UseCamera().SetResolution(1280, 720).SetFps(30).Build();
!source_error.ok()) {
// Handle setup error
} else if (const auto err = sdk.Start(); !err.ok()) {
// Handle startup error
}
// ... run until done ...
sdk.Stop();For custom frame input instead of the built-in camera:
std::shared_ptr<spectra::CustomInput> handle;
if (auto err = sdk.UseCustomInput().Build(handle); !err.ok()) {
// Handle setup error: err.FullMessage()
}
// Feed frames manually:
// handle->Send(frame, timestamp_us);
// timestamp_us must be strictly monotonic.SetOnMetrics fires the same way regardless of frame source. See
C++ Metrics for the metric request configuration and the
metric catalog.
Feed a recorded video through UseFile instead of a live camera to run an
unattended measurement in a CI pipeline — see
Headless Testing in CI for the
cross-platform model and prerequisites (API key, network access, your own
recorded video).
The minimal_example sample supports this out of the box:
./build/samples/minimal_example/minimal_example \
--api_key=YOUR_API_KEY --input_video_path=/path/to/video.mp4The sample plays the file through the same pipeline as a live camera, prints metrics as they arrive, and exits when the file finishes — a non-zero exit code (or no metrics printed) means the run failed. Use a 30–60 second clip (well-lit, mostly still face) in a widely-supported container/codec such as MP4 (H.264). A clip of only a few seconds will not produce readings: pulse rate needs 12 seconds, breathing rate starts at roughly 10 seconds and is not confident until 30, and HRV starts at roughly 30 seconds and is not confident until 60.
A provider-neutral CI step (GitHub Actions), after installing or building the SDK for your platform:
- name: Headless measurement smoke
run: |
./build/samples/minimal_example/minimal_example \
--api_key="${{ secrets.SMARTSPECTRA_API_KEY }}" \
--input_video_path=./test-assets/face.mp4There is no offline mode — the CI runner needs network access to the SmartSpectra service to authenticate and run a measurement.
LLM Insights
Ask natural-language questions about a measurement and receive LLM Insights through the SmartSpectra C++ SDK, alongside the metrics stream.
Migration Guide
Release-by-release migration notes for the SmartSpectra C++ SDK: breaking API changes, renamed headers, and what each upgrade requires.