OptrisOptrisDocumentation

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

optris::sdk::rec::RecordingStats

What a running or just-finished recording did with its frames.

Reset when a recording starts, so these describe the current recording -- or, once it has stopped, the last one.

The accounting rule: The accounting rule Every frame this 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 writer, and between those two moments it is in the queue. Once a recording has stopped the queue is empty and the sum is over the counters alone.

A recording that SegmentLimitAction::kStopRecording ends at its limit (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 they are in none of the counters.

Public attributes

frames_written

uint64_t frames_written = 0

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, and releases them as it goes and finally when the recording is stopped. So this answers "did the recording get my frame", which is what it is for, and it is not a statement that a reader opening the file at this instant would find that frame in it.

StopRecording() is what makes the file complete, and it is a barrier: it drains the write queue and finishes the container before it returns, so a file opened after it has returned holds every frame this counter has counted.

frames_dimension_mismatch

uint64_t frames_dimension_mismatch = 0

Frames refused because they were not the size the file was opened with. A mid-recording mode switch, or a camera that settles on another format after a reconnect, produces these -- and every one of them is a frame missing from the file while IsRecording() still reports true.

frames_write_error

uint64_t frames_write_error = 0

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 -- a disk that refused one frame is not going to take the sixty behind it.

frames_dropped_backlog

uint64_t frames_dropped_backlog = 0

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 and never a re-ordering. Before this counter covered the steady-state write path, a recording to a USB stick that kept 58 % of its frames reported "47,887 written, none lost".

Non-zero means the target cannot sustain this camera. Roughly what it needs is the bytes a frame compresses to times the frame rate; bytes_written divided by frames_written is the first of those, measured on the recording that is running.

A few of these also appear at a stop that could not wait for the queue -- a StopRecording() called from inside a recording handler, which runs on the thread that would have to do the waiting.

It was previously documented as "zero unless pre-roll is in use", which was true of the code and was the hole in it.

bytes_written

uint64_t bytes_written = 0

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: It is the file on disk, not something ahead of it Read between two writes it equals the size of the files exactly. Every write ends in a flush, so the container holds nothing back. Measured from .NET on Windows 11 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: a finished part is banked before its handle closes.

This field was documented as lagging "the file on disk by whatever is still buffered" until every write was made to flush, and for four months after that, by when the sentence was the wrong way round.

What it does lag is #frames_written, by up to one Cluster: What it does lag is #frames_written, by up to one Cluster It grows when the Matroska muxer closes a Cluster, not with every frame, because a Cluster is assembled in a buffer of the muxer's own and reaches the file only when it closes. At FFV1's default 12-frame keyframe interval that is a step every 12 frames; a Cluster also closes at 5 MiB or 5 s, whichever comes first. With RecordingOptions::all_intra every frame is a keyframe and the steps are per frame.

At a file's start it lags by the cover's look-ahead as well -- up to six frames or 400 ms, see PreviewConfig::write_preview -- and then catches up in one step.

Taking a rate from it: Taking a rate from it Use bytes_written_at_us, which says when this last changed. Dividing a difference in this field by the interval between two of your own reads instead gives a figure that swings with where the reads land relative to the steps: measured at a coefficient of variation of 15-20 % at 32 Hz and up to 71 % at 8 Hz over a one-second window.

bytes_written_at_us

uint64_t bytes_written_at_us = 0

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

What this is for: What this is for A write rate, computed exactly and at whatever rate you like to poll. bytes_written steps once per Matroska Cluster and those steps are the only moments either field moves, 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, and it does not depend on when the reads were taken. Without this field the only way to place a step was to poll fast enough to catch it: Optris Connect read the statistics ten times a second, per camera, for exactly that reason, and its first rate still arrived 1.1 to 2.4 s after its first read.

What is in the bytes it is timed against: What is in the bytes it is timed against Everything the file holds, the cover and the notice blocks included -- see PreviewConfig::write_preview for what those cost and for the share they are of a small camera's first three minutes. An application that wants the scene's rate alone has to subtract them itself; the SDK does not split the count.

Monotonic, and not a date: Monotonic, and not a date Only differences between two readings of this field mean anything. Its epoch is the host's, not this recording's, and subtracting it from a wall clock gives nonsense -- the same convention as ShutterEvent's timestamp. Zero until the first Cluster closes, which is also when bytes_written first moves.

The one step that is not a frame's: The one step that is not a frame's The trailer, at the stop. bytes_written picks up the Cues and the last Cluster once the file is closed, and this field is stamped then too -- so a rate taken across a stop is the trailer's write rate and not the recording's. Read both before the stop if the recording's own rate is what you are after.

queue_depth

uint32_t queue_depth = 0

How many frames are waiting to be written right now.

The honest live measure of whether the target is keeping up: a depth that sits near zero is a target with room to spare, and one that sits near queue_capacity is a target about to start dropping frames. An application can warn on the second before any frame is lost.

With a pre-roll, compare against the live figures: With a pre-roll, compare against the live figures A recording that starts with a pre-roll is handed the whole ring at once, and queue_capacity is sized to hold it plus the live queue -- so such a recording opens near its capacity on a perfectly healthy drive. Subtract queue_preroll from this and compare the remainder against queue_live_capacity; those two mean the same thing for every pre-roll length, including none.

queue_peak

uint32_t queue_peak = 0

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: a peak near queue_capacity is the handover on a pre-rolled recording and a drive falling behind on any other, and the 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_preroll_peak

uint32_t queue_preroll_peak = 0

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 the handover is at its largest the instant it is made. Read it beside queue_peak: a peak that equals 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 the handover and almost never a slow drive -- and queue_peak on its own reports the two identically. That is the same finding as queue_depth's, one field over: the durable figure needed the same attribution the instantaneous one was given.

Its own maximum, not the pre-roll standing at the peak: Its own maximum, not the pre-roll standing at the peak Latching whatever the pre-roll count happened to be at the moment of the deepest queue would make this field's value depend on how far the writer had got -- the scheduling dependence this field exists to remove. Its own maximum is reached at the handover, under the controller's mutex, before the writer can pop anything, so it is the same number on every run and every platform.

It therefore agrees with queue_capacity - queue_live_capacity whenever the attribution is working, and that is the point rather than a redundancy: those two are computed by different routes -- a per-frame from_preroll count against the queue's size at the moment it was sized -- so this is the only durable evidence that the per-frame count works. Before it, the only way to see that was to sample faster than the writer drains.

What is still not here: What is still not here The high-water mark of the live depth, queue_depth - queue_preroll, which is what queue_live_capacity would be compared against after the fact. It is not derivable from these figures -- 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 only answerable by polling.

queue_capacity

uint32_t queue_capacity = 0

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. Reported rather than assumed because queue_peak means nothing without it.

Includes the pre-roll a recording was handed at its start, which is why it is not the number to judge a slow drive by. It is queue_live_capacity plus however many frames the pre-roll ring held, and it does not change while the recording runs.

queue_preroll

uint32_t queue_preroll = 0

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.

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. Optris Connect could only warn on frames_dropped_backlog, from the first frame already lost, because these figures could not tell a slow drive from a pre-roll being written.

queue_live_capacity

uint32_t queue_live_capacity = 0

The room for live frames: what queue_capacity is 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. This is what queue_depth - queue_preroll is to be compared against, 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.

longest_write_ms

uint32_t longest_write_ms = 0

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

Measured on the writer thread around the whole of one frame's work, so it covers the FFV1 encode, the metadata block, the muxer and whatever write() calls the finished Cluster caused. 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 writer thread, not what it cost the camera, which is the point of there being a writer thread at all.

last_error

std::string last_error

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