Skip to main content

Finder

Struct Finder 

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

Discovers NDI sources on the network.

Finder provides methods to discover and monitor NDI sources. It maintains a background thread that continuously updates the list of available sources. Concurrent lookups share native change reports: every waiting lookup is notified when the source list changes, then takes its own owned snapshot.

§Examples

let ndi = Ndi::new()?;
let finder = Finder::new(&ndi, &FinderOptions::new())?;

// Wait for initial discovery
let mut watch = finder.watch();
if watch.wait_for_change(Duration::from_secs(5))? {
    let sources = watch.current_sources()?;
    for source in sources {
        println!("Found: {}", source);
    }
}

Implementations§

Source§

impl Finder

Source

pub fn new(ndi: &Ndi, options: &FinderOptions) -> Result<Self>

Creates a new source finder with the specified settings.

§Arguments
  • ndi - The NDI instance (cloned internally to keep the runtime alive)
  • options - Configuration for source discovery
§Errors

Returns Error::InvalidInput when either list is empty or a group or extra address is empty or contains a comma or NUL, Error::UnsupportedCapability when the options carry an Advanced configuration that the runtime or this build cannot take, and Error::NativeOperationFailed when the SDK creates no finder.

Source

pub fn watch(&self) -> SourceWatch<'_>

Monitor this finder’s source list with a cursor for one consumer.

Every consumer needs its own watch. Reports observed by a concurrent lookup remain visible to this watch until it snapshots or waits again. Creating a watch records the current generation without allocating.

Source

pub fn current_sources(&self) -> Result<Vec<Source>>

Returns the current list of discovered sources (snapshot).

This method uses NDIlib_find_get_current_sources which provides a snapshot of the current source list without any additional network discovery. Concurrent snapshots on this finder are serialized until all source names and addresses have been copied into owned Rust values.

Each snapshot permits at most 16,384 descriptors and 16 MiB total native descriptors, result storage, scanned string bytes (including rejected entries) and owned source text with its shared storage overhead. Exceeding either budget returns Error::ResourceLimit. Each SDK string is also limited to 4 MiB including its terminator. An isolated malformed descriptor within the snapshot budgets is skipped, including one whose name or address fails UTF-8 validation.

§Allocation behavior

Failed reservations for the result vector or copied text return Error::AllocationFailed. The same applies to the result and deduplication containers in Self::find_sources. Creating a shared owner for copied source text uses the global allocator’s allocation failure handler, which can terminate the process. This also applies to single-source getters that copy an SDK descriptor, such as crate::Sender::source.

§Returns

A vector of currently known sources. May be empty if no sources are found.

§Errors

Returns Error::UnexpectedSdkResult with crate::SdkResultDefect::MalformedDiscoveryData for a malformed top-level descriptor array, Error::AllocationFailed for failed result or text reservations, or Error::ResourceLimit when a snapshot exceeds its copy budgets. An isolated malformed descriptor is skipped.

§Examples
// Get current snapshot of sources
let sources = finder.current_sources()?;

for source in sources {
    println!("Current source: {}", source);
}
Source

pub fn find_source( &self, timeout: Duration, select: impl FnMut(&Source) -> bool, ) -> Result<Option<Source>>

Wait until a source satisfies select, using this finder’s discovery scope.

Attempts a current snapshot immediately, then waits for source-list changes within one total wait budget, including snapshot-lock contention. Duration::ZERO makes one non-waiting snapshot attempt; a busy snapshot lock returns None. Returns the first matching complete descriptor in a snapshot, or None when the budget expires without a match. Predicates run after releasing the snapshot lock, may inspect name and address together, and may call this finder’s snapshot APIs. No source’s continued availability is guaranteed.

This blocks the calling thread and allocates bounded owned snapshots as Self::current_sources describes. It retains this finder’s groups, IP hints, local-source policy, configuration and runtime; it creates no finder. Concurrent selection operations can use the same finder. Native snapshot execution, bounded descriptor copies, and caller predicates cannot be interrupted and may finish after the wait budget; current_sources itself keeps its ordinary blocking snapshot-lock behavior.

§Errors

Returns Error::InvalidInput for a timeout above crate::MAX_TIMEOUT, including immediate matches, and snapshot errors such as Error::ResourceLimit. A panic in select propagates outside SDK locks.

Source

pub fn find_source_by_name( &self, name: &str, timeout: Duration, ) -> Result<Option<Source>>

Wait for an exact, case-sensitive complete NDI source name.

Names normally look like "STUDIO (Camera 2)". Duplicate names at different addresses select the first match in the current snapshot; use Self::find_source with an address predicate to disambiguate them. Timeout, concurrency and error behavior match that method. Only the first matching descriptor is copied from each bounded snapshot.

§Errors

An empty name returns Error::InvalidInput. A name containing a NUL returns Error::InvalidCString, whose NulError::into_vec returns the bytes through the first NUL. The name is checked before the timeout, including in async lookups. Other errors match Self::find_source.

Source

pub fn find_sources(&self, timeout: Duration) -> Result<Vec<Source>>

Discovers sources for up to timeout, returning the complete set.

This honors the full timeout window and returns every source observed within it. Unlike a single SourceWatch::wait_for_change followed by a snapshot — which returns on the first source-list change and so can miss responders that announce late on staggered or unicast (IP-hint-only) networks — enumeration here retains each source observed during the window.

For an immediate, non-blocking snapshot of already-known sources use current_sources; to resolve a single specific feed use Self::find_source or Self::find_source_by_name.

§Arguments
  • timeout - Discovery window, including waits for the snapshot lock. Duration::ZERO makes one non-waiting snapshot attempt, returning no sources if the lock is busy. Must not exceed crate::MAX_TIMEOUT (~49.7 days). Native snapshot execution and descriptor copies can finish after the wait budget; lock contention returns the results observed so far.
§Returns

Every source observed within the window, in first-observed order. Identity includes the name and the complete address text; a changed descriptor is returned as a distinct source. Network discovery cannot guarantee observation of every source. May be empty if none appear.

§Errors

Returns Error::InvalidInput if timeout exceeds crate::MAX_TIMEOUT. Returns Error::ResourceLimit if a snapshot exceeds the limits of Self::current_sources, or distinct results retained across the whole window exceed 16,384 entries or 16 MiB. The retained byte budget counts shared source strings once, plus the storage of both the result vector and the deduplication set, including container capacity. Returns Error::UnexpectedSdkResult for a malformed top-level snapshot array, or Error::AllocationFailed for failed result, deduplication or text reservations. See Self::current_sources for allocation behavior of shared source owners. An isolated malformed descriptor is skipped.

§Examples
// Discover for up to 5 seconds, then list everything found
let sources = finder.find_sources(Duration::from_secs(5))?;

for source in sources {
    println!("Found: {}", source);
}
Source§

impl Finder

Source

pub fn current_sources_with_metadata(&self) -> Result<Vec<ExtendedSource>>

The sources currently known, each with the metadata it advertises.

This is current_sources with metadata: a snapshot, copied before the SDK can replace it.

§Errors

Error::UnsupportedCapability without an Advanced runtime. crate::Error::ResourceLimit when the descriptor count or total work exceeds the limits of Self::current_sources. Advertised metadata is included in that same byte budget, including lossy UTF-8 expansion. crate::Error::UnexpectedSdkResult with crate::SdkResultDefect::MalformedDiscoveryData for a malformed top-level descriptor array, or crate::Error::AllocationFailed for failed result or text reservations. See Self::current_sources for allocation behavior of shared source owners. An isolated malformed descriptor is skipped.

Trait Implementations§

Source§

impl Debug for Finder

Source§

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

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

impl Drop for Finder

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

impl RefUnwindSafe for Finder

Source§

impl SourceDiscovery for Finder

Auto Trait Implementations§

§

impl !Freeze for Finder

§

impl Send for Finder

§

impl Sync for Finder

§

impl Unpin for Finder

§

impl UnsafeUnpin for Finder

§

impl UnwindSafe for Finder

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.