Skip to main content

RemoteBroadcast

Struct RemoteBroadcast 

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

Source§

impl RemoteBroadcast

Source

pub fn from_consumer(broadcast: Consumer) -> Self

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.

Source

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

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.

Source

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

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.

Source

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

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for RemoteBroadcast

Source§

fn clone(&self) -> Self

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

impl Debug for RemoteBroadcast

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<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<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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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