Skip to Content
PlatformsLinux (Headless, C)

Linux (Headless C SDK)

Use the headless C SDK when your Linux application captures the video. Your app submits uncompressed frames and displays any scan guidance and results.

Install the SDK

From Download SDK , choose the archive for your Linux architecture.

  • shenai-sdk-linux-x64.zip
  • shenai-sdk-linux-arm64.zip

Extract the archive and build against the included library and shenai_sdk_c.h header.

See system requirements for runtime dependencies.

Quickstart (minimal flow)

The SDK starts in measurement mode. Keep submitting frames while it waits for the start conditions and throughout the scan. This example expects 1280 × 720 tightly packed BGR24 frames from your capture pipeline.

Use the shenai_sdk_c.h header shipped with your archive for the signatures below.

#include "shenai_sdk_c.h" /* Implement this function with your camera or video source. */ const uint8_t* get_next_frame(shen_frame_desc_t* desc); int main(void) { shen_context_t* ctx = NULL; shen_init_options_t opts = { .api_key_or_token = "YOUR_API_KEY_OR_TOKEN", .user_id = "user-123", .language = "en", .offline_mode = 0 }; if (shen_initialize(&opts, &ctx) != SHEN_STATUS_OK || ctx == NULL) { return 1; } int finished = 0; for (;;) { shen_frame_desc_t desc = { .width = 1280, .height = 720, .stride_bytes = 1280 * 3, .format = SHEN_PIXEL_FORMAT_BGR24, .timestamp_ns = -1 }; const uint8_t* frame_data = get_next_frame(&desc); if (!frame_data) { break; } if (shen_submit_frame(ctx, &desc, frame_data) != SHEN_STATUS_OK) break; shen_measurement_state_t state = SHEN_MEAS_NOT_STARTED; if (shen_get_measurement_state(ctx, &state) != SHEN_STATUS_OK) break; finished = state == SHEN_MEAS_FINISHED; if (finished || state == SHEN_MEAS_FAILED) break; } shen_measurement_results_t results; if (finished && shen_get_measurement_results(ctx, &results) == SHEN_STATUS_OK) { /* Read the metrics whose has_* flags are set. */ } else { finished = 0; } shen_deinitialize(ctx); shen_destroy_runtime(); return finished ? 0 : 1; }

Have get_next_frame return the next frame buffer, or NULL at the end of input. Set desc.timestamp_ns to the capture timestamp when available. See frame input for the supported layouts and buffer lifetime.

Status codes

Most functions return a shen_status_t value:

  • SHEN_STATUS_OK
  • SHEN_STATUS_NOT_INITIALIZED
  • SHEN_STATUS_INVALID_ARGUMENT
  • SHEN_STATUS_INVALID_STATE
  • SHEN_STATUS_LICENSE_INVALID
  • SHEN_STATUS_CONNECTION_ERROR
  • SHEN_STATUS_NO_DATA
  • SHEN_STATUS_INTERNAL_ERROR

Frame input

shen_submit_frame() accepts raw BGR24 and YUV420 frames.

  • SHEN_PIXEL_FORMAT_BGR24 accepts 8-bit B-G-R rows.
  • SHEN_PIXEL_FORMAT_I420, SHEN_PIXEL_FORMAT_NV12 and SHEN_PIXEL_FORMAT_NV21 accept contiguous 8-bit limited-range BT.601 camera frames with even dimensions. Set stride_bytes to the width in pixels. The buffer holds width * height * 3 / 2 bytes.
  • For BGR24, stride_bytes >= width * 3.
  • timestamp_ns: optional. If set to a negative value, the SDK synthesizes monotonic timestamps from frame submission time.
shen_frame_desc_t desc = { .width = width, .height = height, .stride_bytes = stride, .format = SHEN_PIXEL_FORMAT_BGR24, .timestamp_ns = timestamp_ns }; shen_submit_frame(ctx, &desc, frame_data);

When you provide timestamp_ns, it should be a monotonic capture timestamp. The synthesized fallback is intended for simple live pipelines where explicit timestamps are not readily accessible. For best measurement accuracy, provide source timestamps whenever they are available and prefer uniform sampling of at least 30 FPS.

Keep the input buffer valid and unchanged until shen_submit_frame() returns. The C API copies the frame into SDK-owned memory during the call, so you can then reuse or release your buffer even though processing continues asynchronously. A successful submission does not mean a measurement has finished.

Initialization and configuration

See the C initialization example for credential handling and initialization errors. For a camera source, grant the capture process access to the device.

Use shen_init_options_t to pass your API key or token, user id, language, and frame processing mode. Set offline_mode = 0 for asynchronous frame processing; non-zero values synchronize frame processing and make shen_submit_frame() wait for each frame to finish. This is a processing/scheduling option, not a way to bypass network license activation. The SDK can be initialized multiple times; subsequent calls reuse the same engine and return SHEN_STATUS_OK.

Configuration options are set through explicit setters. You can also apply a full SDK config JSON string via shen_apply_sdk_config() and inspect the current configuration with shen_get_sdk_config_string().

shen_set_precision_mode(ctx, SHEN_PRECISION_STRICT); shen_set_measurement_preset(ctx, SHEN_MEAS_PRESET_ONE_MINUTE_ALL_METRICS); const char* config_json = load_config_json(); shen_apply_sdk_config(config_json);

Replace load_config_json() with your config loader.

Custom measurement config

shen_custom_measurement_config_t cfg = {0}; cfg.has_duration_seconds = 1; cfg.duration_seconds = 30.0f; shen_metric_t instant_metrics[] = { SHEN_METRIC_HEART_RATE }; cfg.instant_metrics = instant_metrics; cfg.instant_metrics_count = sizeof(instant_metrics) / sizeof(instant_metrics[0]); shen_set_custom_measurement_config(ctx, &cfg);

If you call shen_get_custom_measurement_config(), release the returned arrays with shen_release_custom_measurement_config().

Preset semantics and metric meanings match the documentation in Configuration. Use the corresponding SHEN_MEAS_PRESET_*, SHEN_METRIC_*, and SHEN_HEALTH_INDEX_* constants.

Operating mode and state

For a manual Start control, switch to positioning mode before you begin feeding frames. While frames arrive, check readiness to enable Start. When the user presses Start, check again and start the measurement once.

/* Once, before capture starts. */ shen_set_operating_mode(ctx, SHEN_OPERATING_POSITIONING);
/* In the Start handler, while the capture loop continues. */ int ready = 0; if (shen_is_ready_to_start_measurement(ctx, &ready) == SHEN_STATUS_OK && ready) { shen_start_measurement(ctx); }

Use shen_get_operating_mode() to read the current mode. To start automatically, select SHEN_OPERATING_MEASURE. Track the scan separately with shen_get_measurement_state() and shen_get_progress_percent().

You can provide your own positioning guidance using:

shen_face_state_t face_state; shen_get_face_state(ctx, &face_state); shen_normalized_face_bbox_t bbox; shen_get_normalized_face_bbox(ctx, &bbox); shen_face_pose_t pose; shen_get_face_pose(ctx, &pose);

Realtime metrics and heartbeats

shen_realtime_metrics_t metrics; shen_get_realtime_metrics(ctx, 30.0, &metrics); int hr_10s = 0; shen_get_heart_rate_10s(ctx, &hr_10s); shen_heartbeat_array_t heartbeats = {0}; shen_get_realtime_heartbeats(ctx, 30.0, &heartbeats); shen_release_heartbeat_array(&heartbeats);

Final results and history

shen_measurement_results_t exposes all final metrics. Use has_* flags to check availability.

Results map to the metrics described in Results, with additional optional fields for blood pressure confidence, weight, and height in the C API.

shen_measurement_results_t results; if (shen_get_measurement_results(ctx, &results) == SHEN_STATUS_OK) { /* Results are available in results.* */ } shen_heartbeat_array_t hb = {0}; shen_get_measurement_results_with_heartbeats(ctx, &results, &hb); shen_release_heartbeat_array(&hb); shen_measurement_results_history_t history = {0}; if (shen_get_measurement_results_history(ctx, &history) == SHEN_STATUS_OK) { shen_release_measurement_results_history(&history); }

Health risks (optional)

The C API includes health risks computation. Set has_* flags for each provided field:

shen_risks_factors_t factors = {0}; factors.has_age = 1; factors.age = 42; factors.has_gender = 1; factors.gender = SHEN_GENDER_FEMALE; shen_health_risks_t risks; shen_compute_health_risks(ctx, &factors, &risks);

Raw data, reports, and FHIR

Read the signal quality, images, and PPG signal you need. Release each returned buffer when you finish using it.

float signal_quality = 0.0f; shen_get_current_signal_quality_metric(ctx, &signal_quality); float bad_signal_seconds = 0.0f; shen_get_total_bad_signal_seconds(ctx, &bad_signal_seconds); shen_blob_t png = {0}; shen_get_face_texture_png(ctx, &png); shen_release_blob(&png); shen_blob_t quality_png = {0}; shen_get_signal_quality_map_png(ctx, &quality_png); shen_release_blob(&quality_png); shen_blob_t meta_png = {0}; shen_get_meta_prediction_image_png(ctx, &meta_png); shen_release_blob(&meta_png); shen_float_array_t signal = {0}; shen_get_full_ppg_signal(ctx, &signal); shen_release_float_array(&signal); const char* fhir = shen_get_result_as_fhir_observation();

After a successful scan, PDF reports require network access and a license with reports enabled. Request a report once and poll for the result. For example, this helper waits up to about 30 seconds for PDF bytes. Run it outside the frame capture loop.

#include <unistd.h> #include "shenai_sdk_c.h" shen_status_t get_report(shen_context_t* ctx, shen_blob_t* pdf) { shen_status_t status = shen_request_measurement_results_pdf_bytes(ctx); if (status != SHEN_STATUS_OK) return status; for (int attempt = 0; attempt < 30; ++attempt) { sleep(1); status = shen_get_measurement_results_pdf_bytes(ctx, pdf); if (status != SHEN_STATUS_NO_DATA) break; } return status; }

On success, use the bytes and call shen_release_blob(). For a URL, call shen_request_measurement_results_pdf_url(ctx) once and poll shen_get_measurement_results_pdf_url() until it returns a nonempty string or your deadline expires.

Use shen_send_measurement_results_pdf_to_email() to deliver reports by email, and shen_send_result_fhir_observation() to push the FHIR payload to a server.

For internal testing, see Diagnostic video recording for the recording controls. Keep recording disabled in end-user integrations.

Memory ownership

Release buffers and arrays returned by the SDK using the matching helpers:

  • shen_release_custom_measurement_config()
  • shen_release_heartbeat_array()
  • shen_release_measurement_results_history()
  • shen_release_health_risks_factors()
  • shen_release_blob()
  • shen_release_float_array()

Use shen_free() for any heap memory explicitly documented as allocated by the SDK. Strings returned by functions such as shen_get_version() are owned by the library and must not be freed.

Metadata and debug helpers

const char* version = shen_get_version(); int initialized = shen_is_initialized(); const char* plan = shen_get_pricing_plan(); const char* trace_id = shen_get_trace_id(); const char* measurement_id = shen_get_measurement_id();