OptrisOptrisDocumentation

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

optris::sdk::rec::Recorder

Uses the FFV1 lossless codec in MKV containers to store raw thermal pixel data with zero quality loss. Supports multiple synchronized streams for multi-camera setups.

Public types

WriteInterposer

std::function< void(size_t bytes)> WriteInterposer

What a test puts between the muxer and the operating system.

Called on the writing thread immediately before each block of container bytes is handed to the OS, with the size of that block. Returning is what lets the write proceed, so sleeping here is a slow drive -- which is the only way to make one reproducible in a test.

Public static functions

Create

static std::unique_ptr< Recorder > Create(const GlobalConfig &config)

Create a recorder with global settings.

Allocates the MKV container. Call AddVideoStream() next.

Parameters

Name Description
config Container configuration (path, segmentation).

Returns: The recorder.

Exceptions

Name Description
InvalidArgumentException for a configuration that cannot be honoured.
IoException when the container cannot be allocated for the given path.

Create

static std::unique_ptr< Recorder > Create(const std::string &output_path, const StreamConfig &config)

Convenience factory for single-stream recording.

Creates a recorder and adds one video stream (index 0).

Parameters

Name Description
output_path Output file path.
config Stream configuration (dimensions, fps).

Returns: The recorder, with one stream.

Exceptions

Name Description
InvalidArgumentException, FeatureNotSupportedException or IoException as Create() and AddVideoStream() do.

Create

static std::unique_ptr< Recorder > Create(const GlobalConfig &config, SegmentLimitAction on_limit)

Create a recorder that does on_limit when a segment limit in config is reached.

Added in 12.0.10.

The same as Create(config) for SegmentLimitAction::kContinueSeries. With SegmentLimitAction::kStartNewRecording every file is a whole recording, named as SegmentLimitAction describes, and SetLimitCallback() is told when a limit ends one and starts the next. With SegmentLimitAction::kStopRecording (12.0.28) the first file is the only one: the limit finishes it, SetLimitCallback() is told with an empty second path, and every later WriteFrame() and WriteMarker() is accepted and dropped, because the recording is over.

Parameters

Name Description
config Container configuration (path, segmentation).
on_limit What a full file does. Fixed for the recorder's life, because it decides the first file's name.

Returns: The recorder.

Exceptions

Name Description
InvalidArgumentException, IoException as Create(config).

AttachToFile

static void AttachToFile(const std::string &path, const std::vector< Attachment > &attachments)

Add files to a recording that has already been written.

The counterpart to SetAttachmentProvider(), for what a session produces rather than what is known before it starts. A provider is asked immediately before the MKV header goes down, so anything that only exists once the recording ends (a log, a per-widget history, a report) can never travel inside the file through it. This is how it gets there.

Nothing distinguishes what this adds from what a provider added. The files come back through Player::ReadAttachments(), Player::GetAttachments() and the optris_sdk_recording_* reads in the same enumeration, in the same place in it, with the same digest recorded in otc-meta.json. A reader cannot tell when an attachment arrived, and is not meant to be able to.

This rewrites the file, and that is not an implementation: This rewrites the file, and that is not an implementation detail Matroska keeps its attachments in the Segment header, before the first Cluster, so there is no such thing as appending one: adding a file to a finished recording means writing the whole container out again. That is what ffmpeg -i in.mkv -attach … -c copy out.mkv does, and it is what this does. On a 5 GB recording it costs 5 GB of reading, 5 GB of writing, and 5 GB of free space while it runs. Call it once with every file rather than once per file.

What it will not do, whatever goes wrong: What it will not do, whatever goes wrong Lose the recording. path is opened for reading only. The result is written to a temporary file beside it, flushed to the operating system, reopened and checked (every attachment present at its recorded size, every track still there, the duration unchanged) and only then renamed over the original, which on both Linux and Windows is a single atomic operation. A crash, a power loss, a full disk or an FFmpeg failure at any point before that rename costs the temporary file and nothing else; the original is still the file it was, byte for byte.

This is why the file is not edited in place, which is what mkvpropedit --add-attachment does and is the cheaper operation: when the new Attachments element does not fit the free space the writer left, an in-place edit relocates data inside the original, and a process killed during that leaves a recording that is neither the old file nor the new one. The contract on AttachmentProvider ("an attachment is never a reason to lose a recording") holds here too, and it is worth the copy.

What it costs, measured: What it costs, measured The whole file read and the whole file written, on the drive it is on. That is minutes on a removable drive: 5,160,582,106 bytes in 10.2 s on a workstation SSD, and 4,292,417,332 bytes in 443.2 s -- seven and a half minutes, at 9.7 MB/s -- on a removable USB stick, to add 8,729 bytes. It needs free space for a second copy of the file for as long as it runs, and it blocks for the whole of it, with no progress and no way to cancel. A caller on a removable drive has to expect that and say so to its user.

Failure modes that remain, stated rather than hidden: Failure modes that remain, stated rather than hidden - Free space. Checked before a byte is written: the call fails with kIoError, naming what it needed and what was there, rather than filling the disk. The window between the check and the write belongs to whatever else is writing. - The file system's own file size limit. Separate from free space, and reported separately as kFileTooLarge so an application can tell the two apart -- more free space fixes one and not the other. Where a file system caps one file -- commonly at 4,294,967,295 bytes -- a part the recorder split just under that cap ends within a few megabytes of it: a measured one had 2,540,804 bytes of headroom left, so an attachment 2.5 MB larger would not have fitted. If you mean to attach to a part, leave room for it in max_segment_bytes. A result that certainly cannot fit is refused before anything is copied; one that turns out not to is stopped as the copy runs, rather than at the very end. Either way the original is untouched. On a file system whose limit cannot be identified nothing is checked, and the call behaves as it always did. - The file is open elsewhere. On Windows the rename fails and the call reports kIoError, with the original intact. On Linux it succeeds, and a reader that already has the file open keeps reading the bytes it opened; it sees the new attachment when it next opens the path, not before. - A temporary file left behind. Only by a crash or a kill, and it is <path>.otc-attach-<pid>.tmp beside the original, so it is recognizable and removable. Every failure this call returns from has already removed it.

Parameters

Name Description
path An .mkv this SDK or another Matroska writer wrote. Replaced by the rewritten file on success.
attachments What to add. Each needs a non-empty name of at most 255 bytes and at least one byte of content. Matroska stores no entry for an empty attachment, so one is refused rather than silently dropped. An empty MIME type is written as "application/octet-stream". Names need not be unique, here or in the file; a name already carried gets a second entry rather than replacing the first. Attachment::compress is ignored: an MKV attachment stream is stored verbatim, as it is for a provider's files.

Exceptions

Name Description
InvalidArgumentException for an empty list, an unusable or empty file, or a container that is not Matroska.
IoException when the source cannot be read, the disk is short, or the rewrite cannot be put in place.
FileTooLargeException when the result would exceed what one file may hold on the destination.

AttachToCopy

static void AttachToCopy(const std::string &source, const std::string &destination, const std::vector< Attachment > &attachments)

The same, writing the result somewhere else and leaving the source untouched.

For a caller who wants to keep the original as it is, or who is building a copy to hand on. AttachToFile() is this plus the atomic rename, so the safety described there is the safety of this call; the source is opened read-only either way.

Parameters

Name Description
source The .mkv to read. Never modified.
destination Where the rewritten file goes. Overwritten if it exists, and, like AttachToFile(), only by a rename of a verified temporary, so a failure does not leave a half-written file at destination either.
attachments What to add; see AttachToFile().

Exceptions

Name Description
As AttachToFile(), plus InvalidArgumentException when destination is the same file as source. Use AttachToFile() for that, which does it safely.

Public functions

~Recorder

~Recorder()

Recorder

Recorder(const Recorder &)=delete

operator=

Recorder & operator=(const Recorder &)=delete

AddVideoStream

auto AddVideoStream(const StreamConfig &config) -> int

Add a video stream to the recording.

Must be called before the first WriteFrame(). Each stream gets its own FFV1 encoder and a paired subtitle stream for metadata.

Parameters

Name Description
config Stream dimensions and frame rate.

Returns: Stream index (0, 1, ...).

Exceptions

Name Description
InvalidStateException when the header is already written, so no stream can be added.
FeatureNotSupportedException when this build's FFmpeg has no encoder for the stream's codec.
InvalidArgumentException for dimensions the encoder refuses.

GetContainerVideoStreamIndex

auto GetContainerVideoStreamIndex(int stream) const -> int

Which container stream a video stream was laid down on.

The number a foreign reader sees, which is not the index AddVideoStream() returned and is not 2 * stream either: track one of a recording is the viewable track -- the placard, or a false-colour track when one is written -- so the measurement starts at stream 1 on a file that has one and at stream 0 on a file that does not.

Valid only once the container's tracks have been declared, which happens as the header is written: from inside an AttachmentProvider callback, or any time after the first frame. Before that there is no answer and this returns -1, because guessing one is exactly the mistake this exists to stop.

Parameters

Name Description
stream Stream index from AddVideoStream().

Returns: Container stream index, or -1 when it is not yet known.

GetContainerMetadataStreamIndex

auto GetContainerMetadataStreamIndex(int stream) const -> int

Which container stream carries that video stream's per-frame telemetry.

Same validity window as GetContainerVideoStreamIndex(); -1 when unknown or when the stream has no telemetry track.

SetSegmentCallback

void SetSegmentCallback(std::function< void(const std::string &)> callback)

Register a callback for completed file segments.

Called when a segment file is finalized (only when max_segment_duration_sec > 0).

Parameters

Name Description
callback Receives the path of the completed file.

SetLimitCallback

void SetLimitCallback(std::function< void(const std::string &finished, const std::string &started)> callback)

Register a callback for a limit that ended a recording and started a new one, or ended it for good.

Added in 12.0.10.

Under SegmentLimitAction::kStartNewRecording and, since 12.0.28, SegmentLimitAction::kStopRecording, where started is always empty. A limit that continues the series reports through SetSegmentCallback() as it always has.

Called on the thread that wrote the frame that reached the limit, after the finished file is complete on disk.

Parameters

Name Description
callback Receives the finished file, and the file of the recording that started after it, which is empty only if the new file could not be opened, in which case that WriteFrame() throws.

AttachFile

void AttachFile(const std::string &name, const std::string &mime_type, const std::string &data)

Attach a static file to the MKV container.

Useful for embedding calibration data, device configuration, or other metadata. Must be called before any WriteFrame().

Note: This is the header-time form, and it only works when the caller controls the moment the file opens. An application attaching its own files should use SetAttachmentProvider() instead, which works for a recording a trigger started as well as one the application started.

Parameters

Name Description
name Filename for the attachment.
mime_type MIME type (e.g. "application/json").
data Raw file content.

Exceptions

Name Description
InvalidStateException when this recorder has no container yet, or its header is already written.

SetAttachmentProvider

void SetAttachmentProvider(AttachmentProvider provider)

Supply the application's attachments, pulled as each file's header is written.

Called once per output file, immediately before the MKV header is written, which is the last moment an attachment stream can be added, and the only moment that exists for a recording nobody called StartRecording() for. A segmented recording asks again for every segment, so each file stands on its own.

Must be set before the first WriteFrame(); afterwards the header of the current file is already down.

See also: AttachmentProvider for the contract the callback must keep.

SetFileMetadata

void SetFileMetadata(FileMetadata metadata)

Describe the recording, in the shared metadata schema.

Written into the header of every output file as an otc-meta.json attachment, the same document a snapshot carries in its otc:meta chunk, so a recording and a still image describe their device, their radiometry and their regions identically.

The rois array is the static half of the region state: identity, geometry, styling, alarm limits. What the regions do over time travels per frame; see the WriteFrame() overload that takes samples.

Must be set before the first WriteFrame().

SetStartTime

void SetStartTime(uint64_t unix_us)

When the recording started, if that is not now.

By default a recording's file says it was made when its header was written, on the host clock, which is right for a camera recorded live. A recording made from material captured earlier (a file converted from another format, frames replayed from an archive) would then say it was made when it was converted. This gives the file its real start instead: the container's creation_time, which Player::GetStartTimeUs() reads back, and the wall clock in a multipart recording's series block.

The frames' own capture stamps are not touched; they are whatever FrameMetadata::timestamp_us says, as for any recording.

Must be called before the header is written: before OpenOutput(), or before the first WriteFrame() for a recorder that never calls it. A later call is ignored for a file already opened and applies to the next segment.

Parameters

Name Description
unix_us Microseconds since the Unix epoch, UTC. Zero goes back to the host clock.

SetStartTimeZone

void SetStartTimeZone(const RecordingTimeZone &zone)

Which time zone the recording was made in, if that is not this computer's.

Every recording states its zone beside its UTC start: by default this computer's zone at the start, with its IANA name where the platform gives one, which Player::GetStartTimeZone() reads back. A recording made from material captured elsewhere (a file converted from another format) states the zone it was captured in instead. RecordingTimeZone::assumed and RecordingTimeZone::corrected are written as given; RecordingTimeZone::known false goes back to this computer's zone.

Same timing as SetStartTime(): before the header is written.

SetPreviewPalette

void SetPreviewPalette(std::vector< optris::sdk::Rgb24 > colors)

The colours behind a RenderMeta::palette of "custom".

The cover image (GlobalConfig::write_preview) is drawn with the palette the recording says it used, so that the thumbnail is the picture the operator was looking at rather than a default. A built-in palette is named in RenderMeta and looked up from its name; an application's own palette is not, because RenderMeta is written once per frame and a colour table is 720 bytes.

Usually there is nothing to hand over: Usually there is nothing to hand over FileMetadata::palette_colors carries those 240 colours once for the file, and the cover is drawn from that field when this one is unset. So setting the metadata is enough, and it is the better thing to set: the cover and the file then come from one value and cannot disagree. Handing the table over here and not putting it in the metadata is exactly the state that made a custom-palette recording render three different ways.

This remains for a caller that wants the cover drawn with something other than what the file says, and it wins where it is set.

Must be exactly optris::sdk::kPaletteColorCount entries, coldest first; anything else is ignored and the cover falls back to the default palette, saying so in its description. Setting it is only useful when the recording's RenderMeta reports "custom".

Set it before the first WriteFrame(); the cover is drawn as the file's header goes down. It applies to every segment.

WriteFrame

void WriteFrame(int stream_index, const optris::sdk::ThermalFrame &frame, const std::string &annotation={}, const std::optional< RenderMeta > &render={}, const std::optional< FlagPolicyMeta > &flag={}, const std::optional< RecordingGap > &gap={})

Write a thermal frame to a specific stream.

Copies the 16-bit pixel data from the SDK frame, serializes the embedded frame metadata as JSON, and encodes both into the MKV.

Parameters

Name Description
stream_index Stream index from AddVideoStream().
frame Thermal frame from the SDK callback.
annotation Optional JSON object, embedded verbatim under the per-frame regions key. This is how a recording captures measuring-area movement, readings and alarm state over time without the recorder knowing anything about regions. Malformed JSON is dropped rather than corrupting the frame record.
render What the colours meant for this frame. Pass what the display is actually set to on every frame; the recorder writes a per-frame block only on the frames where it differs from what SetFileMetadata() recorded, so a fixed-range recording costs nothing and one under a moving auto-scale records every step. Leave it empty and the file says nothing per frame, exactly as before.
flag Whether a due shutter correction was refused while this frame was captured, and the drift it was refused against. Pass it only on the frames where one actually was -- unlike render, this is not a per-frame restatement of a setting but a record of an event, and an empty optional is the complete and correct answer for a healthy frame.

Passing it is what keeps a suppressed recording honest. A recording stores finished temperatures, so drift the camera was not allowed to correct is in these pixels permanently and no reprocessing on replay removes it; without this the degraded stretch of a file is indistinguishable from the good one. See optris::sdk::FlagWhileRecording for what causes a refusal, and FlagPolicyMeta for the three places a file records one.

Parameters

Name Description
gap The hole in the recording this frame is on the far side of, if it is. Same rule as flag and for the same reason: a record of an event rather than a per-frame restatement of a setting, so pass it only on the one frame that arrived after the camera stopped delivering, and an empty optional is the complete and correct answer -- "the join here is sound" -- for every other frame.

Its presence is the fact a reader needs: the frames either side of that one are not contiguous. Without it the only clue in the file is a jump in the timestamps, which a reader has to notice and then interpret. See RecordingGap.

Exceptions

Name Description
InvalidStateException when a second thread is already inside a write; the Recorder is single-writer.
InvalidArgumentException for a stream index that is not this recorder's, or a frame that is not the size the stream was declared at.
IoException on a write failure.

WriteFrame

void WriteFrame(const optris::sdk::ThermalFrame &frame, const std::string &annotation={}, const std::optional< RenderMeta > &render={}, const std::optional< FlagPolicyMeta > &flag={}, const std::optional< RecordingGap > &gap={})

Write a frame to the default stream (index 0).

Parameters

Name Description
frame Thermal frame from the SDK callback.
annotation See the overload above.
render See the overload above.
flag See the overload above.
gap See the overload above.

Exceptions

Name Description
As the overload above.

WriteFrameAt

void WriteFrameAt(int stream_index, int64_t pts_us, const optris::sdk::ThermalFrame &frame, const std::string &annotation={}, const std::optional< RenderMeta > &render={}, const std::optional< FlagPolicyMeta > &flag={}, const std::optional< RecordingGap > &gap={})

Write a frame at a presentation time the caller chose.

The multi-camera entry point. WriteFrame() derives the PTS from the frame's own capture stamp, normalised against that stream's first frame -- so in a file with two streams each one starts at zero and the two are in step only by luck. Two cameras are never started in the same microsecond and rarely run at the same rate, so "by luck" means "no". This overload takes the number instead of deriving it, which is what lets one clock stamp every stream of a session.

The caller owes one property and it is the only one: pts_us must come from a clock that is the same for every stream of this file, and it must not go backwards on any one stream. A monotonic host clock is the obvious source -- see rec::SessionRecorder, which is this call with the clock, the threading and the per-source bookkeeping already done.

Every frame lands at a later time in the file than the one before it on its stream, and this overload makes that true the way WriteFrame() does. The file keeps whole milliseconds, so a PTS that would land on the same millisecond as the previous frame's, or before it, is moved to the first microsecond the file keeps as the next millisecond: less than one millisecond past the previous frame, and only for a frame that would otherwise share a time with it. A run of frames inside one millisecond is spread one millisecond apart until the given stamps overtake it; any other PTS is written as given. A marker written with WriteMarker() is kept clear of the frames' times by the same rule.

This used to be a one-microsecond nudge, which kept two stamps apart only until the file rounded both to the same millisecond. Two frames 0.4 ms apart then sat at one time, and a reader looking a frame up by its time could not tell them apart.

SessionRecorder's own count of stamps that did not advance (frames_pts_repaired) counts its microsecond repair, before this one; it is not kept here.

The frame's own timestamp_us is untouched and still travels in the per-frame telemetry, so a reader can still see what the camera said about itself alongside where the session put it.

Parameters

Name Description
stream_index Stream index from AddVideoStream().
pts_us Presentation time in microseconds from the start of this file. Negative values are clamped to zero.
frame Thermal frame from the SDK callback.
annotation See WriteFrame().
render See WriteFrame().
flag See WriteFrame().
gap See WriteFrame().

Exceptions

Name Description
As WriteFrame().

WriteColorFrameAt

void WriteColorFrameAt(int stream_index, int64_t pts_us, const optris::sdk::RgbFrame &frame, const std::string &annotation={})

Write a visual-light camera's picture at a chosen presentation time.

The colour counterpart of WriteFrameAt(), and it takes the same one obligation: pts_us must be on the clock every other stream of this file is on. The stream must have been added with StreamPixels::kColor8; a thermal stream refuses this call rather than reinterpreting the bytes, and a colour stream refuses WriteFrameAt() for the same reason.

What is written, and what is not: What is written, and what is not The pixels, losslessly, and a telemetry record carrying the session time. No radiometry, because there is none: a visual camera reports no flag, box or chip temperature and no measurement validity, and inventing zeroes for those fields would put a reading of 0.0 C into a file where a reader cannot tell it from a measurement. The telemetry record such a frame carries says only when it was taken.

Parameters

Name Description
stream_index Stream index from AddVideoStream().
pts_us Presentation time in microseconds from the start of this file. Negative values are clamped to zero.
frame Packed RGB24 pixels, at the size the stream was declared with.
annotation See WriteFrame().

Exceptions

Name Description
InvalidStateException when a second thread is already inside a write.
InvalidArgumentException for a thermal stream, a stream index that is not this recorder's, or a frame that is not the declared size.
IoException on a write failure.

WriteMarker

void WriteMarker(int stream_index, int64_t pts_us, const std::string &json_record)

Write a standalone JSON record into one stream's telemetry track, attached to no frame.

The frame tracks of a recording can only say what happened at a frame, so there is nowhere in them to record that a camera stopped sending -- which is the one thing a hole in a track cannot say for itself. A hole may be a disconnection, a shutter cycle, a disk that could not keep up, or a camera that was legitimately idle, and a reader looking at the gap alone cannot tell those apart. This is how a session writes the answer down at the moment it knows it.

Why this is on the telemetry track and not an attachment: Why this is on the telemetry track and not an attachment Because an attachment is declared in the Matroska header, and the header goes down on the first frame. Everything a recording learns after that -- which is everything about how it went -- cannot be an attachment. The telemetry track is the only place in the file that accepts a record at an arbitrary time.

The record is written at pts_us on that stream's telemetry track, where SessionPlayer's open-time scan finds it. Player::SetTelemetryCallback() and every existing reader match telemetry to frames by presentation time, so a record at a time no frame occupies is ignored by all of them rather than mistaken for one.

Parameters

Name Description
stream_index Stream index from AddVideoStream().
pts_us When it happened, on this file's clock.
json_record The record, as a JSON object. Written verbatim; not parsed and not validated.

Exceptions

Name Description
InvalidStateException when a second thread is already inside a write, or no file is open for a marker to go into.
InvalidArgumentException for a stream index that is not this recorder's, or an empty record.
IoException on a write failure.

OpenOutput

void OpenOutput()

Open the output file now.

Called for you by the first WriteFrame(), and the reason to call it yourself is to find out whether the file can be written at all while there is still a caller to tell. Until the file is opened, an unwritable path -- a directory that does not exist, a permission that was changed, a stick that is not mounted -- is indistinguishable from a good one. The file exists on disk, empty, from the moment this returns.

Every stream must be added and every header-time attachment attached before this, because both have to precede the header. Calling it a second time does nothing.

The cover image is not lost by calling this: The cover image is not lost by calling this It used to be. This call was the header write, and a Matroska header is where the attachments and the track layout are declared -- so opening the file before any frame had arrived meant a header with no picture to draw a cover from, no placard track, and no second chance at either. Every recording made through Imager had neither, because that is exactly what RecordingController does.

The two are now separate: this opens the file, and the header is written when the cover's look-ahead resolves -- on the first frame that is a usable subject, at six frames, at 400 ms, or on Stop(), whichever comes first. A recording that never receives a frame gets no header, because Stop() removes its file instead of finishing it -- see Stop(). So the file this call creates is not a file that is certain to still be there afterwards; it is there for as long as the recording is, which is what makes an unwritable path fail here rather than silently.

Warning: A file already at the path is destroyed by this call, not overwritten at the end. The output is opened with AVIO_FLAG_WRITE, which truncates: measured, a 48-byte file at the path was 0 bytes with the same inode immediately after this returned, and through a hard link to it as well. Nothing is reported, because truncating the output is not an error. Stop()'s deletion deliberately does not compound it -- a directory entry the SDK did not create is never removed -- but the bytes are already gone by then.

This is a rec::Recorder driven directly. A recording started through Imager does not reach it with an occupied path: RecordingController::StartRecording(path) refuses such a path with RecordError::kPathExists before anything is opened, naming the path. So the truncation above remains the contract of this call and of everything else that uses it -- rec::SessionRecorder, a segment rollover, the ravi converter -- and is no longer reachable from StartRecording. If you drive this class yourself and want the same protection, ask std::filesystem::exists() first; the SDK does not do it for you here, because OpenOutput() is also how a deliberate overwrite is expressed.

Exceptions

Name Description
IoException naming the reason the file could not be opened.
InvalidStateException when the header is already written.

GetBytesWritten

auto GetBytesWritten() const -> uint64_t

How many bytes this recording has written, across every segment including the one still open.

The size of the files, not something ahead of them. Every write ends in a flush, so read between two writes this is what the files hold. What it lags is frames_written, by up to one Matroska Cluster: the muxer assembles a Cluster in a buffer of its own and hands it over only when the Cluster closes, so this moves one Cluster at a time. 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, and under StreamConfig::all_intra at every frame.

It is therefore not the number to check a size limit against: see Impl::SegmentIsFullBySize(), which projects what the part will be rather than reading what it is.

Keeps its value after Stop(), and picks up the trailer and the Cues once the file is closed.

SetWriteInterposer

void SetWriteInterposer(WriteInterposer interposer)

Interpose on every write this recording makes to the operating system. A test hook.

Why this exists at all: Why this exists at all A slow USB stick can stall three cameras, and nothing in a test tree is a slow USB stick. Without a hook here the only way to assert "the frame thread does not wait for the drive" is to own the drive, which no CI has. With it, a 500 ms write is four lines of test and the assertion is about the SDK rather than about the hardware it happened to run on.

What it does to the file: What it does to the file Nothing. Installing an interposer chains an AVIOContext in front of the one avio_open() produced; every byte still goes through libavformat's file protocol, in order, to the same path. What changes is that the bytes reach the OS in buffer-sized blocks rather than in one call per flush, so the syscall pattern differs from production even though the file does not. Do not measure write counts through it and call them production's.

Nothing is chained when no interposer is set, which is every recording a product makes: the shipping path is avio_open()'s context untouched.

Must be called before OpenOutput(). A later call is ignored for the file that is already open and takes effect on the next segment.

GetWriteIoStats

auto GetWriteIoStats() const -> WriteIoStats

What the chained context measured. See WriteIoStats.

Not synchronised. The counters are written by whichever thread is inside WriteFrame(), with no lock, because adding one to the write path for the sake of a test hook would be paying production for a test. Read it when no write is in flight.

Stop

void Stop()

Flush encoder buffers and finalize the file.

Writes the MKV trailer. Called automatically by the destructor, but can be called explicitly for deterministic finalization.

The trailer can be refused, and this does not throw or report through a return value for it: read GetFinalizeError(), which is empty exactly when the file was finished.

A recording that captured no frames leaves no file: A recording that captured no frames leaves no file Its file is removed, and GetDiscardedPath() names it. There is no header, no trailer and nothing on disk afterwards, so a caller finds ENOENT where a previous version of this SDK left a small file nothing could open.

That small file is why: 707 bytes from a bare Recorder and 1,940 through Imager, which is every recording a product makes -- refused by this SDK's own Player and by ffprobe 7.1.5 with End of file, and worse than refused by VLC 3.0.23, which declined it in its Matroska demuxer, fell back to MPEG-PS, warned of "garbage at input", played nothing and exited 0. A Matroska Segment carrying Tracks, Info and the attachments and no Cluster is well-formed and unopenable, and since the file appeared immediately its size was how a caller answered "did the recording work?". It answered yes.

Anything an attachment provider supplied goes with the file. By the time this runs the provider has been asked and otc-meta.json, config.json and anything the application offered are in a header that is now never written. A provider is not told, and a caller that needs attachment data from a recording that captured nothing has to keep its own copy.

One frame is enough to keep the file. The threshold is frames somebody captured, not packets: a placard block and a telemetry record are packets and neither is a recording. A frame still held in the cover's look-ahead when this is called counts, because the look-ahead is resolved first.

A file already at the output path goes too, and the reason is that it has already gone. OpenOutput() truncated it -- measured, 48 bytes to 0 with the same inode, and through a hard link to it as well -- so by the time this runs there is nothing of the caller's left to protect, and declining to unlink the remains would preserve the unopenable file this issue is about and leave it unreported. The contract is therefore that starting a recording takes the output path over. See OpenOutput()'s warning.

A Recorder nobody opened a file for removes nothing and reports nothing. Only a path this Recorder itself passed to the operating system is ever unlinked, never one rebuilt from the configuration.

GetDiscardedPath

auto GetDiscardedPath() const -> const std::string &

The file Stop() removed because the recording captured no frame, or empty if it removed nothing.

The path as it was handed to the operating system, not one rebuilt from the configuration afterwards -- so an application can act on it without having to agree with the SDK about how a segment is named.

Non-empty exactly when a file was removed. The layers above turn this into RecordingPhase::kDiscarded, and that equivalence is the property worth relying on: there is no case in which a recording's file is deleted and nothing says so, which is what lets an application retire its own empty-recording cleanup.

Keeps its value after Stop(), like GetBytesWritten().

GetFinalizeError

auto GetFinalizeError() const -> const std::string &

Why Stop() could not finish the file, or empty when it did.

Writing the Matroska trailer can be refused -- a volume with no room left, a quota, a drive that went away -- and a file without its trailer has no Cues, no stated Segment length and no duration. Its frames are on disk and a repair tool can rebuild the index, but no reader will seek it and none will report its length, so it is not the standalone file this SDK otherwise promises.

That result was discarded, so the recording was announced as finished either way. The layers above turn a non-empty answer into RecordingPhase::kFailed naming this file, ahead of RecordingPhase::kStopped, so an application can tell the user which recording to distrust.

Empty for a recording whose file was removed: there is no file left to be suspect of, and GetDiscardedPath() is what answers for that case.

Keeps its value after Stop(), like GetDiscardedPath().