OptrisOptrisDocumentation

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

optris_sdk_recording_stats

What the current -- or last -- recording did with its frames.

Call optris_sdk_recording_stats_init() first.

The accounting rule: The accounting rule Every frame the recording was offered is either in exactly one of the four counters below or still in the write queue:

offered == frames_written + frames_dimension_mismatch +
           frames_write_error + frames_dropped_backlog +
           queue_depth

The last term is what makes it an identity rather than an approximation while a recording runs: a frame is accepted on the camera's thread and accounted for by the thread that writes it.

A recording ended at its limit by OPTRIS_SDK_SEGMENT_LIMIT_STOP_RECORDING (12.0.28) ends with the frame that reached the limit: that frame, and any already queued behind it, arrived after the file was finished and, like a frame that arrives after a stop, are in none of the counters.

Public attributes

struct_size

uint32_t struct_size

Set to sizeof(optris_sdk_recording_stats).

reserved0

uint32_t reserved0

Padding. Set to zero.

frames_written

uint64_t frames_written

Frames the recording has taken into the file.

A frame counts here once the container has accepted it, which is a moment before its bytes are necessarily on the disk: the container holds packets back so that it can interleave the file's streams. So this answers "did the recording get my frame" and is NOT a statement that a reader opening the file at this instant would find that frame in it. optris_sdk_imager_stop_recording() is what makes the file complete, and it is a barrier.

frames_dimension_mismatch

uint64_t frames_dimension_mismatch

Frames refused because they were not the size the file was opened at. A mode switch mid-recording produces these, and every one is a frame missing from the file while optris_sdk_imager_is_recording() still reports true.

frames_write_error

uint64_t frames_write_error

Frames lost to a write or encode failure: a full disk, a removed drive, an encoder error. Includes whatever was still queued when the failure ended the recording.

frames_dropped_backlog

uint64_t frames_dropped_backlog

Frames the recording was offered and did not store, because the writer could not keep up with the camera.

This is the counter a slow target shows up in. The frame was delivered, the queue was full, and the NEWEST frame was dropped rather than the oldest -- which keeps the file contiguous, so a gap in a recording is always a gap in time. Non-zero means the target cannot sustain this camera.

It was previously "zero unless pre-roll is used", which was true of the code and was the hole in it: a recording to a USB stick that kept 58 % of its frames reported "47,887 written, none lost".

bytes_written

uint64_t bytes_written

The size of this recording's files so far -- every part of a split recording, and each finished part's trailer, included.

It is the file on disk, not something ahead of it. Read between two writes it equals the files' size exactly: every write ends in a flush, so the container holds nothing back. Measured against FileInfo.Length at all 1,199 reads taken between two statistics reads that returned the same count, and after every stop. It never goes down at a roll-over.

What it does lag is frames_written, by up to one Matroska Cluster: it grows when the muxer closes one, not with every frame. At FFV1's default 12-frame keyframe interval that is a step every 12 frames, and a Cluster also closes at 5 MiB or 5 s. With all_intra the steps are per frame. At a file's start it lags by the cover's look-ahead too -- up to six frames or 400 ms -- and then catches up in one step.

For a rate, pair it with bytes_written_at_us. It does not lag the file on disk by whatever is still buffered; the writer flushes rather than buffering.

last_error

char last_error[OPTRIS_SDK_MAX_MESSAGE]

The most recent write failure, or an empty string when there has not been one. Kept rather than only counted: "3 frames lost" and "No space left on device" answer different questions.

queue_depth

uint32_t queue_depth

How many frames are waiting to be written right now.

A depth near zero is a target with room to spare; one near queue_capacity is a target about to start dropping frames, so an application can warn before any frame is lost.

Appended after version 12.0's layout: a caller compiled against an older header passes its own smaller struct_size and the four fields from here on are not written.

queue_peak

uint32_t queue_peak

The deepest the queue has been during this recording.

What queue_depth cannot tell a caller that polls: a stall of a second at 32 Hz fills and empties the queue between two polls a second apart, and this is the only trace it leaves.

Read it with queue_preroll_peak, for the same reason queue_depth is read with queue_preroll: on a pre-rolled recording a peak near queue_capacity is the handover, on any other it is a drive falling behind, and this figure alone cannot tell them apart. It is raised at the handover too -- it used to be raised only where a live frame was queued, so on a sensor small enough for the handover to drain between two frames arriving the deepest queue of the recording's life left no trace.

queue_capacity

uint32_t queue_capacity

How deep the queue may get before frames are dropped. Derived from the sensor and the frame rate -- about two seconds of frames, capped so a large sensor cannot turn a slow disk into an out-of-memory.

longest_write_ms

uint32_t longest_write_ms

The longest a single frame took to encode and put on disk, in milliseconds.

On a healthy disk the encode is essentially all of it -- 5.4 ms for a 640x480 frame of 78 KB, measured; a figure in the hundreds of milliseconds is the drive. Nothing waits on this: it is what the recording cost the thread that writes it, not what it cost the camera.

reserved1

uint32_t reserved1

Padding. Zero.

bytes_written_at_us

uint64_t bytes_written_at_us

When bytes_written last changed, in microseconds on the SDK's monotonic clock -- the one C++ callers get through std::chrono::steady_clock.

This is what makes a write rate exact. bytes_written steps once per Matroska Cluster and both fields move only at those steps, so for two reads A and B:

bytes per second = (B.bytes_written - A.bytes_written) * 1e6 /
                   (B.bytes_written_at_us - A.bytes_written_at_us)

That is the rate between two Cluster closes whatever your polling rate. Without it the only way to place a step is to poll fast enough to catch it: Optris Connect read these statistics ten times a second, per camera, and its first rate still arrived 1.1 to 2.4 s after its first read.

The bytes it is timed against are everything in the file, the cover and the notice blocks included; the SDK does not split the count.

Monotonic and not a date. Only differences mean anything -- the epoch is the host's, not this recording's. Zero until the first Cluster closes. The trailer at the stop is a step like any other, so a rate taken across a stop is the trailer's and not the recording's.

Appended after the four queue fields: a caller compiled against an older header passes its own smaller struct_size and this field is not written.

queue_preroll

uint32_t queue_preroll

How many of the queued frames are the pre-roll this recording was handed at its start, rather than frames the camera delivered while it ran.

Zero without a pre-roll, and falls to zero as the handover is written out. queue_depth - queue_preroll is the live depth, and queue_live_capacity is what to compare it against.

What it is for: What it is for 30 s of pre-roll on a 640x480 camera at 32 Hz starts at a depth of 960 against a capacity of 1024 -- 94 % full, on a healthy drive -- because writing the pre-roll out is 960 encodes while the live frames keep coming. Read as "a target about to start dropping frames", which is what queue_depth is documented as, that is simply wrong, and there was no way to tell the two apart. An application was left warning on frames_dropped_backlog, from the first frame already lost.

Appended after bytes_written_at_us, and guarded on its own: a caller compiled against an older header passes its own smaller struct_size and neither this nor the next field is written.

queue_live_capacity

uint32_t queue_live_capacity

The room for live frames: queue_capacity less the pre-roll handed over at the start.

Constant for the life of a recording, and the same quantity -- about two seconds of frames -- whatever the pre-roll was, so "half full" means one thing rather than one thing per pre-roll length. Equal to queue_capacity when no pre-roll was in use.

queue_preroll_peak

uint32_t queue_preroll_peak

The most of the queue that was ever the pre-roll handover.

Zero for a recording started without a pre-roll; otherwise the size of the handover, because a handover is at its largest the instant it is made. Read it beside queue_peak: a peak equal to this is fully accounted for by the handover, and a peak well above it had live frames piling up behind one.

What it is for: What it is for A pre-rolled recording is handed its whole ring at once, so the deepest its queue ever gets is almost always that handover and almost never a slow drive -- and queue_peak on its own reports the two identically. The durable figure needs the same attribution queue_depth one field over was given.

It is its own maximum, not the pre-roll standing at the peak: It is its own maximum, not the pre-roll standing at the peak Latching whatever the count happened to be at the deepest queue would make this depend on how far the writer had got, which is a scheduling dependence. Its own maximum is reached at the handover, before the writer can pop anything, so it reads the same on every run and every platform -- and it agrees with queue_capacity - queue_live_capacity, which is the point rather than a redundancy: the two are computed by different routes, so their agreeing is the only durable evidence that the per-frame pre-roll count works at all.

Not the high-water mark of the live depth. queue_peak - queue_preroll_peak is a difference of two maxima from possibly different moments, not a maximum of the difference, so "did this drive ever come close to dropping a frame" is still answerable only by polling queue_depth against queue_live_capacity.

Appended after queue_live_capacity, and guarded on its own: a caller compiled against an older header passes its own smaller struct_size and this field is not written.