pub struct FileRecorder { /* private fields */ }Expand description
A recorder that writes one NDI source to disk.
The recorder subscribes to the source named in its options and stores the
compressed essence as it arrives; it takes no frames from Rust. A session
runs from start until its last file is closed, and may
span several files through rollover,
set_source and the SDK’s own rollovers.
§Finishing
finish requests a stop and waits for closure events. Check
RecordingReport::closure_confirmed and the report’s error counters.
Drop follows FileRecorderOptions::drop_wait; abandon
skips that wait. See StateConflict::IncompleteFileTracking for recovery.
§What a closed file means
A report of closure repeats what the SDK said: that it finalized the file. A closed file is not proof its data was written. Inspect the report and read back recordings whose completeness matters. See the module’s limits.
§Events
Events are taken with next_event, and
finish takes them itself while it waits; their effect on
the session is kept in the report either way. The SDK
discards events that are not taken promptly, and a session that lost
events can no longer be confirmed closed, so poll throughout a recording.
File bookkeeping retains at most 16,384 entries and 16 MiB, accounting for
entry storage and path capacity. Exceeding either private limit or failing
to reserve storage makes tracking incomplete without dropping delivered
events or changing the native dropped-event count.
A recorder belongs to the thread that created it, so it is neither
Send nor Sync: the File API documents no thread on which a
recorder may be used or destroyed, nor whether two calls on one recorder
may overlap. Methods that call into the SDK may block; cached state and
report snapshots do not call it.
AsyncFileRecorder offers the same operations
as futures.
Implementations§
Source§impl FileRecorder
impl FileRecorder
Sourcepub fn new(api: &FileApi, options: &FileRecorderOptions) -> Result<Self>
pub fn new(api: &FileApi, options: &FileRecorderOptions) -> Result<Self>
Create a recorder for the source named in options.
Nothing is written until FileRecorder::start. The options are only
read, so they stay with the caller whatever the outcome; the recorder
keeps its own copy of the source they name.
§Errors
Error::InvalidInput when the options are malformed or conflict:
an empty track selection, a drop wait beyond crate::MAX_TIMEOUT, a
malformed FileNaming::Pattern, or an exact file name
(FileNaming::Exact, or a pattern without {index}) with
format-change rollover switched on or a nonzero rollover size.
Error::InvalidCString when the filename pattern contains a NUL.
Error::NativeOperationFailed when the SDK cannot create the
recorder and Error::UnsupportedCapability when the library does not
provide FileFamily::Recording.
Sourcepub fn state(&self) -> RecorderState
pub fn state(&self) -> RecorderState
Where the recorder is in its session.
The state follows the events taken so far. A source that disconnects
leaves a session RecorderState::Recording; recording resumes when
it returns.
Sourcepub fn report(&self) -> RecordingReport
pub fn report(&self) -> RecordingReport
What the events taken so far have shown about the current session.
Sourcepub fn start(
&mut self,
target: &RecordingTarget,
timecode: RecordingTimecode,
) -> Result<u64>
pub fn start( &mut self, target: &RecordingTarget, timecode: RecordingTimecode, ) -> Result<u64>
Start a session writing to target, and return its number.
The recorder’s FileNaming turns the target into
file names. With the default indexed names the lowest unused index is
chosen; with an exact file name a file that already exists is refused.
The directory the naming leads to must exist. The check does not
reserve the file: a collision created afterwards reaches the SDK and
can cause a native open failure. Linux File SDK 6.4.0.2 uses exclusive
creation and preserves the colliding file; other platforms and SDK
releases have not been verified. Use a recorder-controlled directory
for uninterrupted recording and destination containment. Parent
directories are not pinned against replacement.
Queued events from an earlier session, including unreadable events,
are consumed and discarded before the native start. Poll them before
starting if their contents are needed. The asynchronous recorder instead
forwards these events through its next_event operation.
A restart checks for SDK event loss after draining the queue. A loss
visible at this check can require a reset without changing the previous
session’s final report. If the restart succeeds, the new session
accounts for loss after this check.
The target is only read, so it stays with the caller whatever the
outcome, for example to start again once a missing directory exists.
RecordingTimecode::GenerateFrom takes a validated
SessionTimecode, so the native start always
receives an explicit timecode rather than the send synthesize sentinel.
§Errors
Error::InvalidStatewithStateConflict::PreviousSessionOpenwhile an earlier session is recording, stopping, awaiting a known file’s closure under complete tracking; finish or poll it first.StateConflict::IncompleteFileTrackingafter a session ends with incomplete tracking.StateConflict::EarlierSessionEventswhen the SDK keeps reporting events of an earlier session.Error::InvalidInputwhen the expanded output path is relative, has no file name, or its longest form exceeds the recorder event’s exact path limit (4094 UTF-8 bytes with the current SDK), reserving at least 20 digits per index token. The SDK is not called.Error::Iowhen the directory of the file the pattern names does not exist or cannot be written to, the filesystem rejects the candidate path, or an exact file name exists (kindAlreadyExists). The SDK is not called. On Windows, also reports security queries that could not be completed.Error::NativeOperationFailedwhen the SDK cannot start the source or open the first file.Processing.NDI.Lib.File.Recorder.hspecifies an open-failed event for an output-file open failure; source-start failure need not queue one.next_eventcan return that event, counted in no session’s report. Retryingstartdiscards queued events before asking the SDK to start again.
Sourcepub fn request_stop(&mut self) -> StopRequest
pub fn request_stop(&mut self) -> StopRequest
Ask the SDK to stop the session. Idempotent.
The SDK then finalizes the open file and reports it closed; this call
alone does not show that it has. Use finish or
wait_for_finish to find out.
Sourcepub fn next_event(&mut self, timeout: Duration) -> Result<Option<RecorderEvent>>
pub fn next_event(&mut self, timeout: Duration) -> Result<Option<RecorderEvent>>
Take the next queued event, waiting up to timeout for one, or
None when none arrives in time.
The event’s effect on the session is recorded before it is returned, including when the event itself is malformed.
§Errors
Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT,
and Error::UnexpectedSdkResult when the SDK’s event does not match
this crate’s structure layout or its returned event type. An unreadable
format is withheld through RecorderEvent::source_format while the
rest of the event is delivered.
Sourcepub fn finish(&mut self, timeout: Duration) -> Result<FinishStatus>
pub fn finish(&mut self, timeout: Duration) -> Result<FinishStatus>
Stop the session and wait up to timeout for its last file to be
closed.
Events that arrive during the wait are consumed; their effect is in
the returned report. A malformed event is consumed too: what it showed
about the session is recorded as next_event
records it, and the wait goes on. One that could not be read at all
makes the outcome SessionEnd::Indeterminate rather than an error.
The wait starts once the stop has returned, and covers taking the
closure’s event, not the stop itself, which the SDK may carry out
before it returns. Events already queued are taken even when the wait
is over, so finish(Duration::ZERO) reports SessionEnd::Closed
when the SDK finalized the file during the stop.
§Errors
Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT,
without requesting the stop, and Error::InvalidState with
StateConflict::StopNotRequested when no session was started. Neither
is returned once the wait has begun: whatever the SDK’s events hold,
the outcome is a FinishStatus.
Sourcepub fn wait_for_finish(
&mut self,
timeout: Duration,
) -> Result<Option<SessionEnd>>
pub fn wait_for_finish( &mut self, timeout: Duration, ) -> Result<Option<SessionEnd>>
Wait up to timeout for a stopping session to end.
Returns None when the timeout expires, and Some with
SessionEnd::Closed or SessionEnd::Indeterminate when the
session ends. A timeout retains the session’s report in
report, and another wait can continue observing it.
Use this to keep waiting after finish returns FinishStatus::TimedOut.
Events already queued are taken even when timeout is over, so a closure
that has been reported is never missed. Malformed events are taken and
recorded as finish describes, without ending the
wait.
§Errors
Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT,
and Error::InvalidState with
StateConflict::StopNotRequested when no session was started or the
session has not been asked to stop. Neither is returned once the wait
has begun.
Sourcepub fn abandon(self) -> RecordingReport
pub fn abandon(self) -> RecordingReport
Stop and destroy the recorder at once, without waiting for the SDK to finalize an open file, and return what was known about the session.
The file of a session that had not ended may be left truncated.
Sourcepub fn reset(
&mut self,
options: &FileRecorderOptions,
) -> Result<RecordingReport>
pub fn reset( &mut self, options: &FileRecorderOptions, ) -> Result<RecordingReport>
Abandon this native recorder and replace it with a new idle recorder.
Use this after a finalization timeout when the SDK stopped producing
events, or to recover from StateConflict::IncompleteFileTracking.
The returned report preserves what was known about the old session.
An unfinished file can be left truncated.
The replacement has its own event queue, so delayed events from the old
session cannot affect a new recording. The last report is retained and
session numbers continue increasing across resets.
The replacement is created first. If creation fails, this recorder and
its report are kept and can still be polled or finalized. The options
are only read, as by FileRecorder::new.
§Errors
The errors of FileRecorder::new.
Sourcepub fn is_recording(&self) -> bool
pub fn is_recording(&self) -> bool
Whether the SDK is recording or waiting for frames. False once a stop has taken effect; this alone does not show that a file was finalized.
Sourcepub fn dropped_event_count(&self) -> u64
pub fn dropped_event_count(&self) -> u64
How many events the SDK has discarded since the recorder was created because they were not taken in time.
Sourcepub fn set_source(&mut self, source: &SourceSpec) -> Result<()>
pub fn set_source(&mut self, source: &SourceSpec) -> Result<()>
Switch to recording another source.
During a session the SDK starts the new source at once and rolls over
to a new file, named from the session’s current target. Before a
session, the source is used by the next start.
A recorder with an exact file name
(FileNaming::Exact, or a
FileNaming::Pattern without {index})
cannot roll over to a file of the same name, and the SDK would end the
session instead, so it refuses a change of source during a session
and the session goes on. Before a session the change works as for any
recorder.
The source stays with the caller; the recorder keeps a copy of it
when the SDK accepts it, for
last_accepted_source.
§Errors
Error::InvalidStatewithStateConflict::ExactFileNameduring a session, recording or stopping, of a recorder with an exact file name, and withStateConflict::Stoppingwhile any other recorder’s session is stopping. The SDK is not called.Error::NativeOperationFailedwhen the SDK cannot start the source. The SDK does not say which source is then in effect, solast_accepted_sourcereturnsNoneuntil a later change succeeds.
Sourcepub fn last_accepted_source(&self) -> Option<&SourceSpec>
pub fn last_accepted_source(&self) -> Option<&SourceSpec>
The source the SDK accepted last: the one given at creation, or by the
last successful set_source.
None after a rejected change, because the SDK does not say which
source is then in effect. This is what was requested, not a statement
that the source is connected.
Sourcepub fn reported_current_file(&self) -> Option<&EventText>
pub fn reported_current_file(&self) -> Option<&EventText>
The most recently opened file still retained in the file tracker.
The path is as the SDK gave it, and can lag events not yet taken. Once
tracking is incomplete, later opens are not retained; consume
next_event for their paths. None does not prove
that no files remain open.
Sourcepub fn rollover(&mut self, target: &RecordingTarget) -> Result<()>
pub fn rollover(&mut self, target: &RecordingTarget) -> Result<()>
Close the current file and continue the session in a new one named
from target.
For compressed video the SDK makes the cut at the next keyframe, so the new file starts decodable. A rollover that has not happened by the time the session stops is dropped.
The SDK accepts a rollover it then cannot carry out, and ends the
session when the new file cannot be opened: it reports open-failed,
closes the old file and reports an error. The file the pattern names
for the target is therefore checked first. Its directory must exist
and be writable, the filesystem must accept the candidate path, and
an exact file name must be available.
The usual mistakes then leave the session running, and the target,
which is only read, stays with the caller to correct and try again.
The preflight is not a reservation: a path created after it can make
the later native open fail and end the session even after this method
returns Ok(()). Observe open-failed/error events and the final
RecordingReport. The exclusive-creation behavior tested on Linux
File SDK 6.4.0.2 preserves colliding regular files and symlinks; other
platforms and SDK releases have not been verified. A
recorder-controlled output directory avoids this race with other writers.
§Errors
Error::InvalidStatewithStateConflict::NotRecordingunless a session is recording.Error::InvalidInputwhen the expanded output path is relative, has no file name, or its longest form exceeds the recorder event’s exact path limit (4094 UTF-8 bytes with the current SDK), reserving at least 20 digits per index token. The SDK is not called and the session goes on.Error::Iowhen the directory of the file the pattern names does not exist or cannot be written to, the filesystem rejects the candidate path, or an exact file name exists (kindAlreadyExists). The SDK is not called and the session goes on. On Windows, also reports security queries that could not be completed.Error::NativeOperationFailedwhen the SDK refuses the target.
Sourcepub fn inject_metadata<S: MetadataSource + ?Sized>(
&mut self,
metadata: &S,
) -> Result<()>
pub fn inject_metadata<S: MetadataSource + ?Sized>( &mut self, metadata: &S, ) -> Result<()>
Write a metadata frame into the recording at its current position.
The frame’s timecode is stored and re-published on playback; it does not move the frame on the file’s timeline. The frame’s text is handed to the SDK as it is, without a wrapper copy. Owned and captured metadata are accepted, and need only outlive this synchronous call.
§Errors
Error::InvalidState with StateConflict::NotRecording unless a
session is recording, and Error::NativeOperationFailed when the
SDK refuses it, for example because the metadata track is not being
recorded.
Sourcepub fn stats(&self) -> Result<Option<RecorderStats>>
pub fn stats(&self) -> Result<Option<RecorderStats>>
The recorder’s running counters, when the SDK has any. Interpret these with the recorder session state and events; they do not use receiver drop-percentage semantics.
§Errors
Error::UnexpectedSdkResult when the SDK’s structure does not match this
crate’s layout.
Sourcepub fn source_format(&self) -> Result<Option<SourceFormat>>
pub fn source_format(&self) -> Result<Option<SourceFormat>>
The format of the source, once the recorder has seen audio or video.
§Errors
Error::UnexpectedSdkResult when the SDK’s structure is malformed.