optris::sdk::rec::ContinuousRecorder
Always-on recording with a retention window, and clips cut from it.
Public types
WriteInterposer
std::function< void(size_t bytes)> WriteInterposer
What a test puts between the muxer and the operating system. The same type as rec::Recorder::WriteInterposer, which is where its contract is written down.
Public static functions
Create
static auto Create(const ContinuousConfig &config) -> std::unique_ptr< ContinuousRecorder >
Open a continuous recording on a directory.
Adopts whatever segments the directory already holds, so the timeline a previous run left is still there to cut from and still counts against the retention policy. ContinuousStats:: segments_adopted reports how many.
What is checked here, while there is a caller to tell: What is checked here, while there is a caller to tell The directory is created and written to, and the volume is measured. A path that cannot be written, or a volume that is already below RetentionPolicy::min_free_bytes plus one segment, is refused now -- rather than at three in the morning on the first frame, where the only place to report it is a log. This is the same reasoning as Recorder::OpenOutput().
Parameters
| Name | Description |
|---|---|
config |
Directory, segmentation and retention. |
Returns: The recorder.
Exceptions
| Name | Description |
|---|---|
InvalidArgumentException |
for an empty directory or a retention policy with no bound at all. |
IoException |
when the directory cannot be used or the volume is already short. |
ExtractClipFrom
static auto ExtractClipFrom(const std::string &directory, uint64_t from_us, uint64_t to_us, const std::string &output_path) -> ClipResult
Cut a file out of a history nothing is recording into.
The same operation against a directory on disk, for the cases where there is no live recorder to ask: a clip wanted after the application restarted, a history copied off a machine, an investigation a week later. The directory is scanned, which costs one pass over each segment's packet headers.
Parameters
| Name | Description |
|---|---|
directory |
A directory a ContinuousRecorder wrote. |
from_us |
In point, on the camera clock. |
to_us |
Out point. |
output_path |
Where the clip goes. |
Returns: As ExtractClip().
Exceptions
| Name | Description |
|---|---|
As |
ExtractClip(). |
ScanDirectory
static auto ScanDirectory(const std::string &directory) -> std::vector< TimelineSpan >
What history a directory holds, without opening a recorder on it.
For an application showing a timeline of what is available before deciding whether to record into it, and for the recovery case: a directory whose catalog did not survive a crash is described from the segment files themselves.
Parameters
| Name | Description |
|---|---|
directory |
The directory to scan. |
Returns: The spans, oldest first. An empty vector for a directory with no segments in it, which is not an error.
Exceptions
| Name | Description |
|---|---|
InvalidArgumentException |
for an empty directory name. |
IoException |
when the directory cannot be read. |
Public functions
~ContinuousRecorder
~ContinuousRecorder()
ContinuousRecorder
ContinuousRecorder(const ContinuousRecorder &)=delete
operator=
auto operator=(const ContinuousRecorder &) -> ContinuousRecorder &=delete
AddVideoStream
auto AddVideoStream(const StreamConfig &config) -> int
Declare the camera whose frames this will take.
As Recorder::AddVideoStream(), with one field taken out of the caller's hands: StreamConfig::all_intra is set from ContinuousConfig::all_intra, which defaults to true. Every segment of one history is then written the same way, which is what lets ClipResult::snapped_by_us be a property of the history rather than of whichever segment a clip happened to start in.
Must be called before the first WriteFrame().
Parameters
| Name | Description |
|---|---|
config |
Dimensions, rate, and the lossy settings if any. |
Returns: Stream index.
Exceptions
| Name | Description |
|---|---|
As |
Recorder::AddVideoStream(). |
SetFileMetadata
void SetFileMetadata(FileMetadata metadata)
Describe the recording. Written into every segment, and inherited by every clip. See Recorder::SetFileMetadata().
SetAttachmentProvider
void SetAttachmentProvider(AttachmentProvider provider)
Supply the application's attachments, pulled once per segment. See Recorder::SetAttachmentProvider().
Asked once a minute for as long as the camera runs, which is the one thing worth knowing that an ordinary recording does not make obvious: a provider that reads a file or queries a device is doing it on every rotation.
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 one frame into the history.
Rolls the segment over, catalogues the finished one and prunes when the policy says to -- all inline, on the calling thread. Deleting a file is a handful of microseconds; opening the next segment is the same cost an ordinary segmented recording already pays at a rotation.
Not the frame thread when a camera drives this. The pruner was documented as running on the frame thread and did, because this call did; RecordingController now calls it from a writer thread of its own, so a remove() on a slow filesystem cannot reach the camera at all. The reasoning for keeping the prune inline is unchanged and only gets safer.
A write that fails does not throw and does not stop the camera. It is counted in ContinuousStats::frames, the reason is in ContinuousStats::last_error, and RecordingPhase::kFailed is raised once.
Parameters
| Name | Description |
|---|---|
frame |
The frame, from the SDK's thermal callback. |
annotation |
Per-frame region record; see Recorder::WriteFrame(). |
render |
What the colours meant for this frame. |
flag |
Whether a due shutter correction was refused. |
gap |
The hole in the history this frame is on the far side of, if it is. Carried here as well as on Recorder::WriteFrame() because a rolling history is written by a different object and would otherwise be the one recording that loses the marker. |
Exceptions
| Name | Description |
|---|---|
InvalidStateException |
when the recording has stopped. |
IoException, InsufficientSpaceException |
or InvalidArgumentException as Recorder::WriteFrame() does. |
Stop
void Stop()
Finish the open segment and stop taking frames.
The segments stay on disk and stay cuttable -- that is the difference from Recorder::Stop(), which finishes one file. A clip can still be extracted from a stopped recorder, and the next run adopts what this one leaves.
Called by the destructor. Safe from any thread, any number of times.
SetWriteInterposer
void SetWriteInterposer(WriteInterposer interposer)
Interpose on every write this history makes to the operating system. A test hook. See rec::Recorder::SetWriteInterposer().
Applies to every segment: a continuous recording rolls one Recorder over rather than opening a new one.
Parameters
| Name | Description |
|---|---|
interposer |
Called on the writing thread before each block of container bytes goes out, with the size of that block. An empty function removes the hook. |
ReportBacklogDrop
void ReportBacklogDrop()
Record that a frame meant for this history was dropped before it ever reached WriteFrame().
For a caller that queues frames for this recorder rather than handing them over one at a time -- which is what RecordingController does, so that a slow volume cannot stall the camera. When its queue is full the newest frame is dropped, and the drop belongs in this recorder's accounting rather than nowhere: counted in ContinuousStats::frames as RecordingStats::frames_dropped_backlog.
Safe from any thread. Counts and nothing else -- no file is touched and no event is raised, because a backlog is a rate problem an application reads out of the statistics rather than an episode.
IsRecording
auto IsRecording() const -> bool
Whether frames are still being written.
GetTimeline
auto GetTimeline() const -> std::vector< TimelineSpan >
Every span of history on disk, oldest first.
The open segment is included, with its TimelineSpan::to_us at the last frame written -- so a timeline widget can draw right up to the present rather than stopping a minute short.
GetStats
auto GetStats() const -> ContinuousStats
What this recording has done. See ContinuousStats.
SetEventCallback
void SetEventCallback(std::function< void(const RecordingEvent &)> callback)
Be told that a segment closed, that one was pruned, that a write failed, or that the retention window could not be honoured.
The same seam an ordinary recording uses -- see RecordingController::SetRecordingCallback() -- with RecordingPhase::kSegmentPruned and RecordingPhase::kRetentionShortened added for the two things only a continuous recording can do.
Fired on the thread that reached the phase, which for a rotation and a prune is whichever thread called WriteFrame() -- the controller's writer thread when a camera drives this, never the camera's own. Never with a lock held; it should still return promptly.
ExtractClip
auto ExtractClip(uint64_t from_us, uint64_t to_us, const std::string &output_path) -> ClipResult
Cut a file out of the history.
What this costs: What this costs A container copy. Packets are read and written; no frame is decoded and none is re-encoded, so the clip's pixels are the segments' pixels bit for bit, and the work is proportional to the bytes of the window rather than to its pixels. The frames are found through FrameIndex, which reads packet headers only.
The clip is an ordinary recording: one file, the metadata and attachments of the segment the window starts in, the thermal track, the telemetry track and the viewable track. A window that spans several segments produces one file, with the presentation times made continuous across the joins.
What a cut cannot do: What a cut cannot do Start between frames. The clip starts at the first frame at or after from_us, unless the history is not all-intra, in which case it starts at the seek anchor at or before it and ClipResult::snapped_by_us says how far back that was.
It also cannot reach footage that has been pruned. A window whose in point is older than the oldest segment is clamped, and ClipResult::incomplete says so.
Parameters
| Name | Description |
|---|---|
from_us |
In point, on the camera clock -- the domain of TimelineSpan. |
to_us |
Out point. Must be after from_us. |
output_path |
Where the clip goes. An existing file is overwritten only once the clip has been written and verified; a failure leaves whatever was there alone. |
Returns: What was produced.
Exceptions
| Name | Description |
|---|---|
InvalidArgumentException |
for a reversed window. |
InvalidStateException |
when the history holds no frame in range at all. |
IoException |
when the clip cannot be written. |