Expand description
Recording NDI sources to disk and playing recordings back, through the NDI File library.
§Supported targets
Enabled by file-io, independently of the advanced Cargo feature. The
File ABI is included, so desktop and Android builds need no Advanced
headers or libclang. On Linux, macOS and Android, the 6.4.0.2 File
library imports the Advanced runtime’s entry points and is refused before
loading beside a Standard runtime. Select the runtime through
RuntimeOptions::edition. The Windows
File library ships for 64-bit Windows and supports either runtime edition.
Apple mobile targets link the File archive at build time.
The File library is a separate native library that accompanies the NDI
runtime. FileApi::new finds it when it is first needed; nothing else in
this crate depends on it, so its absence never affects sending or receiving.
FilePlayer::probereads a recording’s duration and track layout without advertising anything on the network.FilePlayer::newadvertises an NDI source and plays recordings through it; seeFilePlayer.FileRecorder::newrecords a source’s compressed essence exactly as it arrives; seeFileRecorder. The recorder is source-driven: it subscribes to an NDI source and does not accept frames from Rust.
§Where the File library is loaded from
An explicit FileApiOptions::library_path selects a single file. The default
search tries the selected NDI runtime’s directory first, followed by the
executable’s directory, the absolute NDI_RUNTIME_DIR_V6 and the platform
loader locations, in that order.
The runtime search policy also governs File library paths, platform locations, relative environment entries and dyld behavior. Use trusted libraries and dependencies.
When nothing is usable, Error::RuntimeLoadFailed carries a
crate::LoadFailure for crate::LibraryKind::File, with each attempted
location, origin and typed refusal. loaded_any() reports whether any
native code loaded before being refused. Display retains the diagnostic
text for each attempt, including the operating system’s reason. Like the NDI runtime, a
loaded File library stays selected and loaded for the life of the process.
A library that loads but cannot be used stays loaded. If the platform
loader’s own search then matches the library name to that module, it returns
it again instead of looking further; the error names the file, and the remedy
is to remove or fix it or to pass FileApiOptions::library_path.
The native borrowed source/path getters are deliberately not called: their
strings can be invalidated by the SDK’s recording thread. Use
FileRecorder::last_accepted_source for the last accepted source request
and FileRecorder::reported_current_file for the owned event view of the
file. These can lag or differ from the native state as their docs describe.
§What the File library provides
Its entry points come in FileFamily groups: playback, which also
probes recordings, and recording. A library is selected when it provides
at least one family completely. FileApi::status reports each family,
and an operation that needs a family the selected library lacks fails with
Error::UnsupportedCapability, naming the family and the first entry
point the library does not export.
§Finishing a recording
FileRecorder::finish requests a stop and waits for closure events. See
RecordingReport::closure_confirmed for what the SDK confirms and check
the report’s error counters. Drop and async close follow
FileRecorderOptions::drop_wait. When file tracking becomes incomplete,
follow StateConflict::IncompleteFileTracking before restarting.
§Limits of the NDI 6.4 File library
These limits apply to the versions and platforms named below. They lie inside the library and this crate cannot correct them.
- On Linux with the NDI 6.4 File library, a file reported closed is not
proof that its data was written. A
session’s report repeats what the library said: that it finalized each
file. When the disk fills while a session is being stopped, a write comes
up short, the library extends the file all the same and reports it closed
without an error, and
FilePlayer::probethen reports a final duration for a file whose data is not there.SessionEnd::Closedwith no errors therefore means that the container was finalized, not that every frame reached the disk. A recording that must be complete has to be checked by reading it back. - On Linux with the NDI 6.4 File library, the process does not survive a full disk during recording. When a write fails while a session is recording, the library queues a write-failed and an error event and then crashes in its own writer thread, which ends the process. Nothing this crate does can prevent it. Record only where enough space is certain.
- On Linux with the NDI 6.4 File library, a file can be closed with
nothing in it. The library opens a file as
soon as a session or a rollover starts, and reports it closed even if no
frame arrived: after a stop before the source delivered anything, a
switch to a source that is not there, or a rollover while the source is
lost.
RecordingReport::empty_filescounts confirmed empty files: exactly under confirmed closure, and as a lower bound after incomplete tracking. - On Linux with the NDI 6.4 File library, a rollover the library cannot
carry out ends the session. It accepts
the request, fails to open the new file, closes the old one and stops.
FileRecorder::rolloverpreflights the destination so a missing output directory, a directory-only path, an existing exact name or an indexed name that outgrows the filesystem limit can be refused while the session continues. SeeFileNamingfor the naming rules. - On every platform with the NDI 6.4 File library, recording paths must be absolute and reportable exactly. Start and rollover preflight the expanded path sent to the SDK. It must fit in 4094 UTF-8 bytes with the current SDK, reserving at least 20 digits per index token. This keeps closure events unambiguous.
§Threads
FilePlayer and FileRecorder are neither Send nor Sync: the SDK
documents no threading contract for them, so each stays on the thread that
created it. Every native call can block, including destruction; timeouts
bound event waits only. The values they return are owned and can be sent
anywhere. AsyncFilePlayer and AsyncFileRecorder keep each native
object on a dedicated thread and expose futures that work with any executor.
Those futures submit work on their first poll; FileOperation::submit
explicitly submits immediately. Submitted stop, finish, close and abandon operations
survive cancellation of their futures. Dropping the last async handle can
block; await its close() operation before dropping it on an executor.
§Examples
use std::time::{Duration, Instant};
use grafton_ndi::{
file::{
FileApi, FileApiOptions, FileRecorder, FileRecorderOptions, FinishStatus,
RecordingTarget, RecordingTimecode, SessionEnd, SourceSpec,
},
Ndi,
};
let ndi = Ndi::new()?;
let file = FileApi::new(&ndi, &FileApiOptions::default())?;
let options = FileRecorderOptions::new(SourceSpec::new("STUDIO (Camera 1)")?);
let mut recorder = FileRecorder::new(&file, &options)?;
recorder.start(&RecordingTarget::new("take")?, RecordingTimecode::Preserve)?;
let duration = Duration::from_secs(10);
let start = Instant::now();
while start.elapsed() < duration {
let wait = duration.saturating_sub(start.elapsed()).min(Duration::from_millis(250));
if let Some(event) = recorder.next_event(wait)? {
println!("{:?}", event.kind());
}
}
match recorder.finish(Duration::from_secs(5))? {
FinishStatus::Ended(SessionEnd::Closed(report)) => {
if report.error_events() != 0 || report.write_failures() != 0
|| report.empty_files() != 0 || report.stopped_by_sdk()
{
return Err(format!("recording incomplete: {report:?}").into());
}
println!("closed {} file(s)", report.closed_files());
}
other => return Err(format!("closure unconfirmed: {other:?}").into()),
}See file_record.rs for the complete recording workflow.
Structs§
- Async
File Options - The sizes of the queues between an async handle and its owner thread.
- Async
File Player - A
FilePlayeron a thread of its own, driven through futures. - Async
File Recorder - A
FileRecorderon a thread of its own, driven through futures. - Event
Text - Original SDK event bytes, retaining invalid UTF-8 and truncation evidence.
- FileApi
- The File library selected for this process.
- File
ApiOptions - How the File library is located. Creating this value loads nothing.
- File
Duration - A current duration that may still be growing.
- File
Event Future - The next event from a player or recorder, or
Nonewhen none arrives within the timeout. - File
Info - A non-advertising file probe result.
- File
Operation - The result of a command sent to a player’s or recorder’s thread.
- File
Player - An NDI source that plays recordings.
- File
Player Options - How a player advertises its NDI source. Creating this value advertises nothing.
- File
Position - Unsigned file-relative time in 100ns units, distinct from the editorial
Timecodethat frames carry. - File
Recorder - A recorder that writes one NDI source to disk.
- File
Recorder Options - Recorder configuration fixed when its native instance is created.
- Player
Event - An owned player event. Inline SDK strings are copied within their bounds.
- Player
Stats - Owned playback counters for the current or most recent file session.
- Recorder
Event - An owned recorder event, including original bounded diagnostic text.
- Recorder
Stats - Owned recorder telemetry. Counts refer to packets rather than decoded samples.
- Recording
Report - What the recorder’s events have shown about a session so far.
- Recording
Target - An owned absolute output prefix/path interpreted by the recorder’s naming policy.
- Session
Timecode - An explicit editorial timecode from which a recording session can advance.
- Source
Format - An owned layout snapshot containing no borrowed native memory.
- Source
Spec - An owned source name or direct URL used by a recorder.
- Video
Track - An owned description of one video track, not a decoded pixel layout.
Enums§
- File
Family - A family of the NDI File library’s entry points, which a library provides completely or not at all.
- File
Naming - How a recorder names the files of a session from its
RecordingTarget. - Finish
Status - The outcome of finishing a recording session.
- Player
Event Kind - Playback event kind; unknown native values remain observable.
- Recorder
Event Kind - Recorder event kind; a write failure is not necessarily fatal.
- Recorder
State - Where a recorder is in its session.
- Recording
Timecode - Timecode policy applied when a recording session starts.
- Session
End - The final outcome of a recording session.
- State
Conflict - Why an operation is not permitted in the current state, carried by
Error::InvalidState. - Stop
Request - What
FileRecorder::request_stopdid.