Skip to main content

FilePlayer

Struct FilePlayer 

Source
pub struct FilePlayer { /* private fields */ }
Expand description

An NDI source that plays recordings.

The source is advertised from creation until the player is dropped, whether or not a file is playing; stop ends the current file only, so receivers stay connected between files. Dropping the player stops playback and removes the source.

A player belongs to the thread that created it, so it is neither Send nor Sync: the File API documents no thread on which a player may be used or destroyed, nor whether two calls on one player may overlap. Every method calls into the SDK and may block. AsyncFilePlayer offers the same operations as futures.

Implementations§

Source§

impl FilePlayer

Source

pub fn new(api: &FileApi, options: &FilePlayerOptions) -> Result<Self>

Create a player and advertise its NDI source.

The source is advertised from this call until the player is dropped, whether or not a file is playing. The options are only read, so they stay with the caller whatever the outcome.

§Errors

Error::InvalidInput when the player’s name or group list is empty, or a group is empty or contains a comma or NUL. Error::InvalidCString when the player’s name contains a NUL. Error::NativeOperationFailed when the SDK cannot create the player and Error::UnsupportedCapability when the library does not provide FileFamily::Playback.

Source

pub fn probe(api: &FileApi, path: impl AsRef<Path>) -> Result<FileInfo>

Read a recording’s duration and track layout.

Nothing is played and no NDI source is advertised. An unreadable format payload does not discard the other information; FileInfo::source_format reports the typed cause instead.

§Errors

Error::NativeOperationFailed when the SDK cannot read the file, Error::InvalidInput when the path is empty or is not UTF-8, Error::InvalidCString when it contains a NUL, Error::Io when a relative path cannot be resolved because the current directory is unavailable, and Error::UnsupportedCapability when the library does not provide FileFamily::Playback. Error::UnexpectedSdkResult when the library’s file information does not match this crate’s structure layout.

Source

pub fn start(&mut self, path: impl AsRef<Path>) -> Result<()>

Play a file through the advertised source.

A file already playing is closed first. Playback always begins unpaused and uses the player’s looping setting. As specified by Processing.NDI.Lib.File.Player.h, only the player’s first start may wait up to about half a second, and only for a GOP-compressed file with a receiver that has just connected, so it gets the opening keyframe. There is no wait without a connected receiver, and later starts on the same player never wait.

§Errors

Error::NativeOperationFailed when the SDK cannot open the file, Error::InvalidInput when the path is empty or is not UTF-8, Error::InvalidCString when it contains a NUL, and Error::Io when a relative path cannot be resolved because the current directory is unavailable.

Source

pub fn stop(&mut self)

Stop the current file. The source stays advertised.

Source

pub fn is_running(&self) -> bool

Whether a file is playing. False after stop and once playback reaches the end of a file that does not loop.

Source

pub fn next_event(&mut self, timeout: Duration) -> Result<Option<PlayerEvent>>

Take the next queued event, waiting up to timeout for one, or None when none arrives in time. An unreadable format is withheld through PlayerEvent::source_format while the rest of the event is delivered.

§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.

Source

pub fn dropped_event_count(&self) -> u64

How many events the SDK has discarded since the player was created because they were not taken in time.

Source

pub fn stats(&self) -> Result<Option<PlayerStats>>

Counters for the current or most recent file, when the SDK has any. Interpret them alongside playback session state and events, rather than as receiver-media progress.

§Errors

Error::UnexpectedSdkResult when the SDK’s structure does not match this crate’s layout.

Source

pub fn seek(&mut self, position: FilePosition) -> Result<()>

Seek to a position on the file’s timeline, where zero is its first frame.

GOP-compressed video resumes at the keyframe at or before the position; intra-only video resumes at the first frame at or after it.

§Errors

Error::NativeOperationFailed when the SDK refuses the seek.

Source

pub fn seek_frame_approximate(&mut self, frame: u64) -> Result<()>

Seek to a frame index.

The SDK converts the index to a time through the video frame rate, so the result is approximate for fractional rates.

§Errors

Error::NativeOperationFailed when the SDK refuses the seek.

Source

pub fn set_paused(&mut self, paused: bool)

Pause or resume the current file. Has no effect when no file is open.

Source

pub fn is_paused(&self) -> bool

Whether the current file is paused. Every start resets this to false.

Source

pub fn set_looping(&mut self, looping: bool)

Set whether playback restarts at the end of a file.

Looping belongs to the player, not the file: it is kept across start and stop. A looping file never raises PlayerEventKind::Ended.

Source

pub fn is_looping(&self) -> bool

Whether playback restarts at the end of a file.

Source

pub fn duration(&self) -> Option<FileDuration>

The current file’s best-known duration, and whether it is final.

A file that is still being recorded reports a provisional duration.

Source

pub fn position(&self) -> Option<FilePosition>

The position of the frame sent last: the main video track’s, or the audio track’s in a file without video.

Source

pub fn source_timecode(&self) -> Option<Timecode>

The recorded source timecode of the frame sent last. Unlike the position it is editorial and need not increase.

Source

pub fn source_format(&self) -> Result<Option<SourceFormat>>

The track layout of the current file, once one with audio or video is open. A known layout alone does not establish current playback progress; inspect the player state and events as well.

§Errors

Error::UnexpectedSdkResult when the SDK’s structure is malformed.

Source

pub fn advertised_source(&self) -> Result<Source>

The NDI source this player advertises, for example to connect a Receiver to it.

§Errors

Error::NativeOperationFailed when the SDK returns no source, or one that names neither a source nor an address, and Error::UnexpectedSdkResult when its name or address is longer than the 4 MiB available for one SDK string, including its terminator. Error::InvalidUtf8 reports an invalid name or address. Error::AllocationFailed reports a failed text buffer reservation. See crate::Finder::current_sources for allocation behavior of shared source owners.

Source

pub fn close(self)

Stop playback and remove the advertised source.

Equivalent to dropping the player; provided so the intent is visible at the call site.

Trait Implementations§

Source§

impl Debug for FilePlayer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for FilePlayer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.