RecordingStatistics
public sealed record RecordingStatistics : IEquatable<RecordingStatistics>
What the current, or last, recording did with its frames.
Without this a recording that has silently stopped growing looks exactly like a healthy one: ThermalCamera.IsRecording stays true while every frame is refused.
Reset when a recording starts and kept after it stops, so the totals are readable once the file is closed.
The accounting rule. Every frame the recording was offered is either in exactly one of the four counters or still in the write queue: offered == FramesWritten + FramesLost + QueueDepth. 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 SegmentLimitAction.StopRecording (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.
RecordingStatistics: constructors
public RecordingStatistics(ulong FramesWritten, ulong FramesDimensionMismatch, ulong FramesWriteError, ulong FramesDroppedBacklog, ulong BytesWritten, string LastError, uint QueueDepth = 0, uint QueuePeak = 0, uint QueueCapacity = 0, uint LongestWriteMs = 0, ulong BytesWrittenAtUs = 0, uint QueuePreRoll = 0, uint QueueLiveCapacity = 0, uint QueuePreRollPeak = 0)
What the current, or last, recording did with its frames.
FramesWritten: 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.StopRecordingis what makes the file complete, and it is a barrier.FramesDimensionMismatch: Frames refused because they were not the size the file was opened at: a mode switch mid-recording, or a camera that settles on another format after a reconnect.FramesWriteError: 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.FramesDroppedBacklog: 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 newest frame is 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 used to be "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 and none lost.BytesWritten: 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 on Windows 11 through this binding againstFileInfo.Lengthat 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 isFramesWritten, 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. Where every frame is a keyframe 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, and then catches up in one step. For a write rate, pair it withBytesWrittenAtUs. This was documented as lagging "the file on disk by whatever is still buffered", which was true until the flush-after-every-write change and backwards after it.LastError: The most recent write failure, or an empty string. Kept rather than only counted: "3 frames lost" and "No space left on device" answer different questions.QueueDepth: How many frames are waiting to be written right now. A depth near zero is a target with room to spare; one nearQueueCapacityis a target about to start dropping frames, so an application can warn before any frame is lost. With a pre-roll, compare the live figures instead. A recording that starts with a pre-roll is handed the whole ring at once andQueueCapacityis sized to hold it plus the live queue, so such a recording opens near its capacity on a perfectly healthy drive. SubtractQueuePreRollfrom this and compare the remainder againstQueueLiveCapacity; those two mean the same thing for every pre-roll length, including none.QueuePeak: The deepest the queue has been during this recording. WhatQueueDepthcannot 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 withQueuePreRollPeak, for the same reasonQueueDepthis read withQueuePreRoll: on a pre-rolled recording a peak nearQueueCapacityis the handover, on any other it is a drive falling behind, and this figure alone cannot tell them apart.QueueCapacity: 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. 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 isQueueLiveCapacityplus however many frames the pre-roll ring held, and it does not change while the recording runs.LongestWriteMs: 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 640×480 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.BytesWrittenAtUs: WhenBytesWrittenlast changed, in microseconds on the SDK's monotonic clock, the one C++ callers get throughstd::chrono::steady_clock. This is what makes a write rate exact.BytesWrittensteps once per Matroska Cluster and both fields move only at those steps, so for two readsaandb:csharp var bytesPerSecond = (b.BytesWritten - a.BytesWritten) * 1_000_000.0 / (b.BytesWrittenAtUs - a.BytesWrittenAtUs);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: a consumer reading these statistics ten times a second, per camera, still saw its first rate 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.QueuePreRoll: 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, soQueueDepth - QueuePreRollis the live depth. 30 s of pre-roll on a 640×480 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 the early warningQueueDepthis documented as, that is simply wrong, and there was no way to tell the two apart: a consumer was left warning onFramesDroppedBacklog, from the first frame already lost.QueueLiveCapacity: The room for live frames:QueueCapacityless 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 toQueueCapacitywhen no pre-roll was in use.QueuePreRollPeak: 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 besideQueuePeak: 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. 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, andQueuePeakon its own reports the two identically. This is the same correctionQueuePreRollmade toQueueDepth, applied to the figure that is kept rather than the one that is current. Not the high-water mark of the live depth.QueuePeak - QueuePreRollPeakis 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 pollingQueueDepthagainstQueueLiveCapacity.
Without this a recording that has silently stopped growing looks exactly like a healthy one: ThermalCamera.IsRecording stays true while every frame is refused.
Reset when a recording starts and kept after it stops, so the totals are readable once the file is closed.
The accounting rule. Every frame the recording was offered is either in exactly one of the four counters or still in the write queue: offered == FramesWritten + FramesLost + QueueDepth. 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 SegmentLimitAction.StopRecording (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.
RecordingStatistics: properties
public ulong BytesWritten { get; init; }
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 on Windows 11 through this binding 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 FramesWritten, 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. Where every frame is a keyframe 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, and then catches up in one step.
For a write rate, pair it with BytesWrittenAtUs. This was documented as lagging "the file on disk by whatever is still buffered", which was true until the flush-after-every-write change and backwards after it.
public ulong BytesWrittenAtUs { get; init; }
When BytesWritten 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. BytesWritten steps once per Matroska Cluster and both fields move only at those steps, so for two reads a and b:
var bytesPerSecond = (b.BytesWritten - a.BytesWritten) * 1_000_000.0 / (b.BytesWrittenAtUs - a.BytesWrittenAtUs);
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: a consumer reading these statistics ten times a second, per camera, still saw its first rate 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.
public ulong FramesDimensionMismatch { get; init; }
Frames refused because they were not the size the file was opened at: a mode switch mid-recording, or a camera that settles on another format after a reconnect.
public ulong FramesDroppedBacklog { get; init; }
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 newest frame is 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 used to be "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 and none lost.
public ulong FramesLost { get; }
Every frame this recording was offered and did not write.
The number worth asserting on after a recording: the three counters behind it have different causes but the same consequence. A frame still in the queue is not lost and is not here, see RecordingStatistics.QueueDepth.
public ulong FramesWriteError { get; init; }
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.
public ulong FramesWritten { get; init; }
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. StopRecording is what makes the file complete, and it is a barrier.
public string LastError { get; init; }
The most recent write failure, or an empty string. Kept rather than only counted: "3 frames lost" and "No space left on device" answer different questions.
public uint LongestWriteMs { get; init; }
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 640×480 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.
public uint QueueCapacity { get; init; }
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. 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 QueueLiveCapacity plus however many frames the pre-roll ring held, and it does not change while the recording runs.
public uint QueueDepth { get; init; }
How many frames are waiting to be written right now. A depth near zero is a target with room to spare; one near QueueCapacity is a target about to start dropping frames, so an application can warn before any frame is lost.
With a pre-roll, compare the live figures instead. A recording that starts with a pre-roll is handed the whole ring at once and QueueCapacity is sized to hold it plus the live queue, so such a recording opens near its capacity on a perfectly healthy drive. Subtract QueuePreRoll from this and compare the remainder against QueueLiveCapacity; those two mean the same thing for every pre-roll length, including none.
public uint QueueLiveCapacity { get; init; }
The room for live frames: QueueCapacity 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 QueueCapacity when no pre-roll was in use.
public uint QueuePeak { get; init; }
The deepest the queue has been during this recording. What QueueDepth 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 QueuePreRollPeak, for the same reason QueueDepth is read with QueuePreRoll: on a pre-rolled recording a peak near QueueCapacity is the handover, on any other it is a drive falling behind, and this figure alone cannot tell them apart.
public uint QueuePreRoll { get; init; }
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, so QueueDepth - QueuePreRoll is the live depth.
30 s of pre-roll on a 640×480 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 the early warning QueueDepth is documented as, that is simply wrong, and there was no way to tell the two apart: a consumer was left warning on FramesDroppedBacklog, from the first frame already lost.
public uint QueuePreRollPeak { get; init; }
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 QueuePeak: 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.
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 QueuePeak on its own reports the two identically. This is the same correction QueuePreRoll made to QueueDepth, applied to the figure that is kept rather than the one that is current.
Not the high-water mark of the live depth. QueuePeak - QueuePreRollPeak 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 QueueDepth against QueueLiveCapacity.