OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Rust API referencev12.0

SessionRecorder

pub struct SessionRecorder

A recording session under construction or running.

Stopped and freed when dropped. SessionRecorder::stop is worth calling anyway when the file matters, because it returns a Result and a drop cannot.

Threading

SessionRecorder is Send and Sync, which makes it the only handle in this crate that is. The C says optris_sdk_session_recorder_write_frame is "safe to call from several threads at once; it has to be, because N cameras deliver on N callback threads", and that is precisely what Sync means. The write calls therefore take &self rather than &mut self, so an Arc<SessionRecorder> can be handed to every camera's callback.

The calls that are not safe that way (adding a source, opening, stopping, registering the event callback) take &mut self, so the borrow checker keeps them off a shared recorder. That split is the whole reason this type can be Sync at all.

SessionRecorder — methods

pub fn create(path: &str, options: &SessionOptions) -> Result<Self>

Create a session. Add sources next, then open it.

path is where the file goes; .mkv recommended.

Errors

Returns Status::InvalidArgument if path contains an interior NUL byte or the options are not a set the SDK can honour.

pub fn add_source(&mut self, source: &SessionSource<'_>) -> Result<i32>

Add one camera to the session, and take the index every other call about it needs.

Must be called before SessionRecorder::open and before the first frame. Every track of a Matroska file is declared in its header, so a camera that joins after the header is down cannot be added to this file; it is refused rather than quietly dropped.

Errors

Returns Status::InvalidState once the session is open, and Status::InvalidArgument for a geometry the SDK will not take or a string with an interior NUL byte.

pub fn open(&mut self) -> Result<()>

Open the output file and write its header now.

Worth calling rather than letting the first frame do it: until the file is opened an unwritable path is indistinguishable from a good one, and by the first frame the caller who could have been told is gone. Calling it twice does nothing.

The session clock's origin is taken here, so session time means "since the file opened".

Errors

Returns Status::Io if the file cannot be created.

pub fn write_frame(

Write one thermal camera's frame into the session.

Stamps the frame with the session clock now, on this thread, then hands it to the session's writer. The frame is copied, so it may be reused or dropped the moment this returns.

Takes &self deliberately, see this type's threading note.

annotation is a per-frame region record as JSON, or None.

Errors

The reason the frame is not in the file: an unknown source, a dimension mismatch, a full queue, a source of the wrong kind, or a session that has been stopped. A write failure that happens later, on the writer thread, cannot be returned here; it lands in SessionRecorder::statistics and in the event callback.

pub fn write_color_frame(

Write one visual camera's picture into the session.

Identical to SessionRecorder::write_frame in every respect that matters: the same session clock, stamped on this thread, the same queue, the same statistics. A visual camera recorded this way is in step with the thermal ones because it is on the same clock, not because anything aligned it afterwards.

The source must have been declared with SessionSource::color.

rgb is packed RGB24, row-major from the top-left, three bytes a pixel and no row padding.

Errors

Returns Status::InvalidArgument if rgb is not exactly width * height * 3 bytes.

Why the length is not re-checked here

The ABI already checks it exhaustively, and better. Measured at 0, 1, n - 1, n + 1 and n bytes: it refuses every wrong length with Status::InvalidArgument and a message naming both the size given and the size wanted: "This buffer is 9215 bytes, but a 64x48 packed RGB24 picture is exactly 9216." An earlier version of this method compared the length itself and claimed to be what prevented an overread. It was not: removing it left every case in tests/session.rs green, including one written specifically to catch its removal. A check no test can distinguish from its own absence is the defect class this repo produces most, so it is gone rather than kept as decoration.

What is checked here is the multiplication: `width * height

  • 3` is computed in C as well, and a geometry that overflows gives the ABI a size that is not the one it was asked about. That is refused before the call, and it is the one thing a slice's own length cannot tell the C.

The ABI is handed rgb.len() rather than a number the caller computed, which is what rules out the C caller's route to a short read regardless of either check.

pub fn mark_source_lost(&mut self, source: i32, reason: Option<&str>) -> Result<()>

This camera has dropped out. Keep its track open and record the outage.

Lost is a hole: the source stays open, its track is not closed, and the moment frames arrive again they continue that same track at wherever the session clock has got to. Nothing is padded and no frame is invented. Compare SessionRecorder::end_source, which is final.

A record goes into the file saying the source was lost and why, which is what lets a player show a disconnected picture across the span instead of holding the last frame. A held last frame reads as a live scene.

Calling it for a source already lost does nothing.

Errors

Returns Status::NotFound for an unknown source.

pub fn mark_source_resumed(&mut self, source: i32) -> Result<()>

This camera is back. Its track continues where the session clock now is.

Optional: the first frame after an outage resumes the source by itself. Calling it is how an application that knows the transport reconnected says so before the first frame, so the outage recorded in the file ends at the reconnection rather than most of a shutter cycle later.

Does nothing for a source that is not lost.

Errors

Returns Status::NotFound for an unknown source.

pub fn end_source(&mut self, source: i32, reason: Option<&str>) -> Result<()>

This camera is finished; the rest of the session carries on without it.

The track ends where the camera stopped: nothing is padded, no frame is invented, and the other cameras are not slowed to it or stopped with it. Frames written for an ended source afterwards are refused. Use SessionRecorder::mark_source_lost for a camera that may come back.

Errors

Returns Status::NotFound for an unknown source.

pub fn source_count(&self) -> Result<i32>

How many sources this session has.

Errors

Returns Status::InvalidHandle if the session has been closed.

pub fn source_state(&self, source: i32) -> Result<SessionSourceState>

What one source is doing right now.

Errors

Returns Status::NotFound for an unknown source.

pub fn statistics(&self, source: i32) -> Result<SessionSourceStats>

What one source has done.

Errors

Returns Status::NotFound for an unknown source.

pub fn elapsed_us(&self) -> Result<u64>

Session time now, in microseconds since the session opened.

Zero before that. Monotonic: a stopwatch, not a date.

Errors

Returns Status::InvalidHandle if the session has been closed.

pub fn started_at_us(&self) -> Result<Option<u64>>

When the session started, as a date: microseconds since the Unix epoch. None before the session opens.

Read once, when the session opened, in the same breath as the monotonic origin. Neither is derived from the other, and this one is not monotonic: NTP can step it. Use SessionRecorder::elapsed_us to measure and this to say when.

Errors

Returns Status::InvalidHandle if the session has been closed.

pub fn bytes_written(&self) -> Result<u64>

Total bytes the session has written, across every segment.

Errors

Returns Status::InvalidHandle if the session has been closed.

pub fn clear_event_callback(&mut self) -> Result<()>

Stop delivering session events.

Errors

Returns Status::InvalidHandle if the session has been closed.

pub fn stop(&mut self) -> Result<()>

Finish the session: drain the queue, flush every encoder, write the trailer and close the file.

When this returns the file is complete on disk. Done for you on drop; calling it twice is harmless.

Errors

Returns Status::Io if the trailer could not be written.