OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C API referencev12.0

optris_sdk_pre_roll_state

Everything the pre-roll ring can be asked about: whether it is on, the duration actually in force, how deep the ring is, how much is in it, and whether it holds all the history it was asked for.

Worth reading rather than assuming, because the duration can differ from what was asked for.

A struct rather than a handful of out-parameters, for the reason optris_sdk_recording_stats gives: adding a parameter to a function that is already exported changes its signature, and a caller compiled against the old one would pass five arguments to a function that reads six. A struct_size is additive, and the next field costs nothing. There was a four-out-parameter optris_sdk_imager_get_pre_roll() beside this until API version 30; it could not say how much history the ring holds or whether it is full, and comparing its out_buffered with its out_frames -- the only test it allowed -- is never true on a camera that delivers fewer frames than its sensor's rate.

Call optris_sdk_pre_roll_state_init() first.

Public attributes

struct_size

uint32_t struct_size

Set to sizeof(optris_sdk_pre_roll_state).

enabled

int32_t enabled

1 when frames are being buffered at all, else 0.

duration_ms

uint32_t duration_ms

The duration in force, in milliseconds, after any raise to the frame period and any cut by the memory budget. Zero when disabled.

frames

uint32_t frames

How many frames the ring may hold.

A memory bound, not the history's length: the most the ring will ever spend, derived from the sensor's rate. A source delivering more slowly than the sensor rate reaches duration_ms long before it reaches this, and may never reach this at all.

buffered

uint32_t buffered

How many frames are in it right now.

Warning: Comparing this with frames is not how to tell a full pre-roll. Use holds_duration.

holds_duration

int32_t holds_duration

1 when the ring holds all the history it was asked for, else 0.

The test to wait on before starting a recording. True once either bound has bitten -- a frame evicted for being older than duration_ms, or the frame count reaching frames -- so it covers a camera delivering below its sensor rate and one delivering above it, with no tolerance for the caller to choose.

Goes back to 0 immediately after a recording starts: the start hands the whole ring to the write queue, so the pre-roll begins refilling from nothing.

Placed here, between two 32-bit fields, rather than after held_us where it reads more naturally: there it left a 4-byte hole before held_us and another after itself, and a hole this struct does not spell out is a hole the hand-written .NET mirror has to guess at. Six 32-bit fields then two 64-bit ones is 40 bytes with no padding anywhere.

held_us

uint64_t held_us

The span the ring actually holds, in microseconds: its newest frame's timestamp less its oldest. Zero when fewer than two frames are in it.

The number to show a user as "the pre-roll holds 4.8 of 5 s". buffered is a frame count against a capacity derived from the sensor's rate, and a camera does not always deliver at that rate -- subsampled, or restricted to 9 fps. A 32 Hz camera delivering 9 fps with 5 s armed holds its whole 5 s in about 45 of its 160 frames, so the counts read 28 % while the buffer is full.

It tops out just under duration_ms rather than at it, because a span is measured between two stamps and so falls one delivered frame period short. That period is the one number a caller outside the SDK has not got, which is why holds_duration exists.

bytes

uint64_t bytes

Roughly how much memory the full ring costs, in bytes.