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
impl RemoteBroadcast
Sourcepub fn from_consumer(broadcast: Consumer) -> Self
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.
Sourcepub fn from_local(broadcast: &impl Consume<Consumer>) -> Self
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.
Sourcepub fn from_consumers(
consumers: impl Stream<Item = Consumer> + Send + 'static,
) -> Self
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.
Sourcepub fn from_resolved(origin: Consumer, path: Path, broadcast: Consumer) -> Self
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.
Sourcepub fn set_network(
&self,
signals: impl Fn() -> NetworkSample + Send + Sync + 'static,
)
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.
Sourcepub fn catalog(&self) -> Receiver<Option<Arc<Catalog>>>
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.
Sourcepub fn catalog_missing(&self) -> Receiver<bool>
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.
Sourcepub async fn catalog_within(
&self,
timeout: Duration,
) -> Result<Arc<Catalog>, Error>
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.
Sourcepub fn play(&self, config: PlayerConfig) -> Result<Player, Error>
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.
Sourcepub async fn mux_source(&self) -> Result<Source, Error>
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.
Sourcepub async fn closed(&self)
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.