Skip to main content

RecvListener

Struct RecvListener 

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

Lists the receivers registered with a Discovery Server, reports their events, and asks them to change source. Remote control is always an explicit call.

§Connection

A listener connects in the background and keeps trying for as long as it lives. It is created whether or not its server can be reached; until the server answers, which can take several seconds after it appears, is_connected is false and snapshots are empty.

§Threading

A listener is Send but not Sync: it may be moved to another thread, and is used by one thread at a time. is_connected and server_url take a shared reference, and the SDK documents neither as safe to call on one listener from several threads at once; it forbids overlapping membership queries on one listener. Snapshots and events are plain owned data and can be shared freely.

Implementations§

Source§

impl RecvListener

Source

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

Create a listener for the Discovery Server options name.

Success does not mean the server was reached; see Connection.

§Errors

Returns Error::UnsupportedCapability when the selected runtime cannot provide receiver discovery, which needs NDI 6.4.0 or later, or the options carry an Advanced configuration that the runtime or this build cannot take; Error::InvalidCString when the endpoint contains a NUL byte; and Error::InvalidInput when the endpoint is empty, the options name multiple endpoints, or the SDK creates no listener. Without an explicit server the SDK uses its configuration; creation fails when it names no server or one the SDK cannot use. An explicit address the SDK cannot parse is also refused.

Source

pub fn is_connected(&self) -> bool

Whether the listener is connected to its Discovery Server right now. A listener that is not connected keeps trying. This reports registry connectivity, not progress of any receiver media.

Source

pub fn server_url(&self) -> Option<String>

The Discovery Server endpoint the listener uses, when the SDK reports one.

None when the SDK reports none, and also when what it reports is no string of less than 4 MiB, the most this crate reads from one SDK string. No endpoint is that long, and the value is for display only: the listener does not depend on it and the crate never passes it back to the SDK. So a value that cannot be read is reported as no value, rather than as an error that every caller of this getter would have to handle. Bytes that are not UTF-8 are replaced with U+FFFD, as in the other text a listener reports.

Source

pub fn wait_for_change(&mut self, timeout: Duration) -> Result<bool>

Wait for the advertised membership to change; a zero timeout polls.

§Errors

Returns Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT.

Source

pub fn subscribe(&mut self, id: &ReceiverId)

Ask to receive the events of the peer id names. The next snapshot reports whether the subscription is active.

The listener keeps its own copy of the identifier until unsubscribe returns or the listener is dropped.

Source

pub fn unsubscribe(&mut self, id: &ReceiverId)

Ask to stop receiving the events of the peer id names.

With the NDI 6.3.2 and 6.4.0.2 runtimes, unsubscribing from a receiver can permanently block that receiver’s connect, in this process or another, when it connects at the same moment: an SDK defect the crate cannot prevent. Dropping the listener ends its subscriptions without that risk. See the module documentation.

Source

pub fn next_events( &mut self, timeout: Duration, ) -> Result<Vec<ListenerEvent<ReceiverId>>>

Take the events that arrived since the last call, in arrival order, waiting up to timeout for the first one. An empty batch means none arrived in time; a zero timeout polls.

An event with a string of 4 MiB or longer is omitted; its scan still spends the shared budget. Other events remain in order.

§Errors

Returns Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT, Error::ResourceLimit when copying the batch would exceed its 16 MiB budget, and Error::UnexpectedSdkResult when the top-level batch array is malformed, or Error::AllocationFailed when storage cannot be reserved. The SDK has already handed a rejected batch over, so it is freed and its events are lost.

Source

pub fn current_receivers(&mut self) -> Result<Vec<AdvertisedReceiver>>

Copy the receivers currently advertised. The list is empty while the listener is not connected.

An entry with a string of 4 MiB or longer, or a malformed nested array, is omitted. Its scans still spend the shared budget. Text that is not valid UTF-8 is decoded lossily; see the module documentation.

§Errors

Returns Error::ResourceLimit when copying would exceed the 16 MiB budget, and Error::UnexpectedSdkResult when the top-level snapshot array is malformed. Error::AllocationFailed when storage cannot be reserved.

Source

pub fn request_connect( &mut self, id: &ReceiverId, source_name: &str, ) -> Result<()>

Ask the receiver id names to connect to the NDI source called source_name.

The request checks the listener’s current borrowed membership, comparing exact identifiers and reading only the matched receiver’s commands. It is sent only when that receiver advertises ReceiverCommand::Connect. Malformed names, input groups, addresses or streams do not prevent a request. Success means it was sent, not that the receiver acted on it.

§Errors

Returns Error::InvalidInput when source_name is empty, and Error::InvalidCString when it contains a NUL byte, before reading listener membership. For this error, NulError::into_vec returns the bytes through the first NUL.

Returns Error::ReceiverRequestNotAccepted when no receiver the listener lists has this identifier (advertised is false: the listener may not have connected yet, the receiver may not be registered, or its entry may have an unreadable identifier; a later request can succeed) or the receiver does not accept connection requests (advertised is true, including a malformed command array); Error::NativeOperationFailed when the SDK cannot send the request; Error::UnexpectedSdkResult for a malformed top-level membership array; and Error::ResourceLimit when that array and the target’s commands exceed the 16 MiB inspection budget. Unrelated fields are neither scanned nor copied and cannot spend that budget.

Source

pub fn request_disconnect(&mut self, id: &ReceiverId) -> Result<()>

Ask the receiver id names to disconnect from its current source.

This is the connection request without a source, so it too is sent only to a receiver that advertises ReceiverCommand::Connect. It compares exact identifiers and reads only the matched command array; unrelated fields are neither scanned nor copied.

§Errors

As for Self::request_connect, without source-name validation.

Trait Implementations§

Source§

impl Debug for RecvListener

Source§

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

Formats the value using the given formatter. 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.