Skip to main content

RemoteBroadcast

Struct RemoteBroadcast 

pub struct RemoteBroadcast { /* private fields */ }
Expand description

A broadcast being read.

Cheap to clone. Holding it keeps the broadcast subscription open, and any number of Players and recordings can read it. Constructing one spawns a task, so it must happen inside a Tokio runtime.

Implementations§

§

impl RemoteBroadcast

pub fn from_consumer(broadcast: Consumer) -> RemoteBroadcast

Starts reading the catalog of broadcast.

The remote broadcast ends when broadcast ends. A broadcast published in the same process reads through from_local.

§Panics

Panics when called outside a Tokio runtime.

pub fn from_local(broadcast: &impl Consume<Consumer>) -> RemoteBroadcast

Starts reading the catalog of broadcast, published in this process.

Plays what an application sends, without a transport, such as a preview of its own camera with sound. Takes anything that hands out consumers of its broadcast, such as a LocalBroadcast of moq-ext-publisher. The remote broadcast ends when broadcast closes. The same as from_consumer with consume.

§Panics

Panics when called outside a Tokio runtime.

pub fn from_consumers( consumers: impl Stream<Item = Consumer> + Send + 'static, ) -> RemoteBroadcast

Reads each broadcast consumers yields, in turn.

Players switch to each new consumer as it arrives, and wait through the gap after one ends, so a transport can hand in what serves the broadcast now, such as a new subscription after a restarted publisher or a failed session. The remote broadcast closes once consumers ends.

§Panics

Panics when called outside a Tokio runtime.

pub fn from_resolved( origin: Consumer, path: Path, broadcast: Consumer, ) -> RemoteBroadcast

Follows path in a route table, starting from a resolved broadcast.

When a change of route ends the broadcast, it is requested again through the next route, and players see a switch instead of an end. closed explains when a publisher counts as gone. iroh-live uses this on subscribe.

§Panics

Panics when called outside a Tokio runtime.

pub fn set_network( &self, signals: impl Fn() -> NetworkSample + Send + Sync + 'static, )

Attaches network signals for automatic rendition selection.

signals returns the link as it is now. Players call it a few times a second and on every Player::stats, so it must not block. The signals belong to the broadcast: every clone sees them, and attaching again replaces them. Players started afterwards use them.

pub fn catalog(&self) -> Receiver<Option<Arc<Catalog>>>

Returns a receiver for the catalog, None until the first arrives.

A publisher may announce its broadcast before it creates the catalog track. The catalog is then asked for again, with a growing wait, until it appears or the broadcast closes.

A borrow of the receiver blocks the next catalog update, so keep it short.

pub fn catalog_missing(&self) -> Receiver<bool>

Returns a receiver that is true while the publisher answers that it has no catalog track.

Such a broadcast carries no media, for example one that holds only JSON values. The catalog is still asked for again, since a publisher may create the track after it announced the broadcast, and the receiver turns false once the track appears or another consumer takes the broadcast over.

pub async fn catalog_within( &self, timeout: Duration, ) -> Result<Arc<Catalog>, Error>

Waits for the first catalog, at most timeout.

Cancellation safe.

§Errors

Fails with Error::Closed if the broadcast closes first, and with Error::Catalog if no catalog this build can read arrives in time.

pub fn play(&self, config: PlayerConfig) -> Result<Player, Error>

Starts one playback of the broadcast.

§Errors

Fails for an invalid config: a latency whose minimum is above its maximum.

pub async fn mux_source(&self) -> Result<Source, Error>

Returns a moq_mux::Source of the current route, for a moq-mux export.

Waits until the broadcast has a route and a catalog, since an exporter’s catalog reader does not ask again for a catalog track that is not there yet. The source reads one route, so a change of route ends the exports that read it. One of a broadcast from from_resolved resolves sibling broadcasts through the route table.

Recording composes this with moq-mux’s fragmented MP4 or Matroska export, which remuxes without decoding:

use moq_mux::{catalog::Stream as _, container::fmp4};
use tokio::io::AsyncWriteExt as _;

let source = broadcast.mux_source().await?;
let catalog = moq_mux::catalog::Consumer::<()>::new(&source.broadcast(), Default::default())
    .await?
    .select(moq_mux::select::Broadcast::default());
let mut export = fmp4::Export::new(source, catalog);
let mut file = tokio::fs::File::create("out.mp4").await?;
while let Some(chunk) = export.next().await? {
    file.write_all(&chunk).await?;
}

Cancellation safe.

§Errors

Fails with Error::Closed if the broadcast closes first.

pub async fn closed(&self)

Waits until the broadcast has closed.

A broadcast read with from_consumer closes when its consumer does. One that follows a route table, from from_resolved, cannot tell a publisher that left from a change of route. It asks the table again and closes once no route has answered for three seconds. So a hang-up shows here about three seconds late.

Cancellation safe.

pub fn is_closed(&self) -> bool

Reports whether the broadcast has closed.

Lags a routed publisher’s hang-up by the same three seconds as closed.

Trait Implementations§

§

impl Clone for RemoteBroadcast

§

fn clone(&self) -> RemoteBroadcast

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for RemoteBroadcast

§

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

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more