RecordingFile
pub struct RecordingFile
A recording this SDK wrote, opened for the files it carries.
The no-camera, no-playback read. Opening one parses the container header and stops: no decoder is created, no playback thread is started and no frame is touched, so it costs the same on an hour-long take as on a one-second one. That is what makes listing a folder of recordings, or restoring the session that wrote them, affordable.
Closed when dropped; there is no manual close. Use
crate::Camera::attachment_count and its neighbours instead when
a recording is already open for playback; there is no reason to
read the file twice. The still-image counterpart is
crate::Snapshot.
Every file the recording carries, the SDK's own included. The
SDK writes otc-meta.json, device.json, config.json and, for a
multi-camera session file, otc-session.json; all of them are in
the enumeration at their container position, which is what the flat
C ABI and .NET both report. That is the opposite of
crate::Snapshot::attachments, which leaves three of the SDK's
own out, and both are deliberate: a snapshot's excluded files are
the measurement itself and the calibration behind it, reached
through crate::Snapshot::load_thermal and
Camera::open_still, while a recording's are documents nothing
else can hand back. Telling your files from the SDK's is a
comparison on AttachmentInfo::name.
Examples
# fn main() -> optris_sdk::Result<()> {
let carried = optris_sdk::RecordingFile::open("session.mkv")?;
for one in carried.attachments()? {
println!("{} ({} bytes)", one.name, one.size);
}
# Ok(())
# }
RecordingFile — methods
pub fn open(path: &str) -> Result<Self>
Open a recording and read what it carries into memory.
Works on anything this SDK writes as Matroska: a plain
recording, one segment of a segmented one, and a multi-camera
session file, whose own otc-session.json comes back as one of
the attachments, so a session can be recognised without decoding
it.
Errors
Returns Status::Io when the file cannot be opened or is not
a container this SDK can read, and
Status::InvalidArgument if path contains an interior NUL
byte.
pub fn attachment_count(&self) -> Result<usize>
How many files are carried inside this recording.
Errors
Returns Status::InvalidHandle if the recording is not valid.
pub fn attachment_info(&self, index: usize) -> Result<AttachmentInfo>
Describe one carried file by index, from 0, in container order.
Errors
Returns Status::InvalidArgument for an index past the end.
pub fn attachments(&self) -> Result<Vec<AttachmentInfo>>
Describe every carried file, in container order.
The index only: reading a payload is
RecordingFile::read_attachment, so listing a folder of
recordings costs no payload at all.
Errors
As RecordingFile::attachment_count.
pub fn read_attachment(&self, index: usize) -> Result<Vec<u8>>
Copy one carried file's bytes out.
Errors
Returns Status::InvalidArgument for an index past the end.
pub fn attach_files(path: &str, files: &[FileToAttach<'_>]) -> Result<()>
Add files to a recording that has already been written, replacing it with the rewritten one.
The counterpart to Camera::set_attachment_provider, 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 a log, a report or a per-widget history, which only exist
once the recording has ended, can never travel inside the file
through it. This is how they get there.
Nothing distinguishes what this adds from what a provider added:
the files come back through RecordingFile::attachments and
through a playback handle's reads in the same enumeration, at
the same place in it, with the same digest recorded in the
recording's own otc-meta.json.
This rewrites the file
Matroska keeps its attachments in the Segment header, ahead of the first Cluster, so adding one to a finished recording means writing the whole container out again. On a 5 GB recording that is 5 GB read, 5 GB written and 5 GB of free space while it runs, measured at 10.2 s on a workstation SSD and 443.2 s, seven and a half minutes at 9.7 MB/s, on a USB stick, to add 8,729 bytes. The call blocks for all of it with no progress and no way to cancel. Pass every file in one call rather than calling once per file.
It cannot cost you the recording
The source is opened for reading only. The result is written to a temporary beside it, flushed, 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 is one atomic operation on both Linux and Windows. A crash, a power cut, a full disk or a muxer failure at any point before that rename costs the temporary and nothing else.
On Windows the final rename fails when the recording is open in
another program, and this returns Status::Io with the
original intact. On Linux it succeeds, and a reader that already
has the file open keeps reading the bytes it opened until it
reopens the path.
Errors
Returns Status::InvalidArgument for an empty list
(rewriting a container to add nothing is an expensive no-op, so
it is reported rather than performed), for an unusable name, or
for a file that is not Matroska; Status::Io when the
recording cannot be read, the disk has not the room, or the
rewrite cannot be put in place; and Status::OutOfRange when
the result would be larger than one file may be on the
destination's file system. That one is deliberately not
Status::Io: more free space does not help, and the fix is a
different destination or less to attach.
Examples
# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{FileToAttach, RecordingFile};
let csv = b"t,c\n0.0,20.1\n0.1,20.4\n";
RecordingFile::attach_files(
"/data/run.mkv",
&[FileToAttach::with_mime("widget-7-history.csv", "text/csv", csv)],
)?;
# Ok(())
# }
pub fn attach_files_to_copy(
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. RecordingFile::attach_files 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. destination is overwritten if it exists, and only by a
rename of a verified temporary, so a failure leaves no
half-written file there either.
Errors
As RecordingFile::attach_files, plus
Status::InvalidArgument when destination names the same
file as source; use RecordingFile::attach_files for
that, which does it safely.