Skip to main content

Crate iroh_live

Crate iroh_live 

Source
Expand description

Live audio and video over iroh.

A Node publishes and subscribes to broadcasts at paths, over a direct session with a peer or an attached media relay. [node] re-exports iroh-live-node, the layer under the facade, and moq_net the moq-net it builds on. media and rooms gather the media and rooms crates, each behind its feature.

The moq crates are pinned to a git rev of moq-dev/moq main, so this crate is not on crates.io yet.

The node takes any path. iroh-live ships one convention, layout::LiveLayout, which publishes a peer’s broadcasts at <root>/<peer>/<name> (the root is live by default) and lets each peer publish only under its own id. An application with its own scheme passes its own paths and policy, see NodeConfig::with_policy.

A BroadcastTicket names a peer and the path it publishes at, whatever the layout. Node::subscribe_ticket grants the ticket’s publisher that one path while the subscription lives, so a viewer needs no layout. This publishes a test pattern and plays someone else’s broadcast:

use iroh::protocol::Router;
use iroh_live::{
    BroadcastTicket, EndpointConfig, Node,
    layout::LiveLayout,
    media::{
        LocalBroadcast, PlayerConfig, SubscriptionExt, VideoEncoding, VideoRendition,
        VideoSource, video,
    },
};

let layout = LiveLayout::default();
let endpoint = EndpointConfig::from_env()?.bind().await?;
let node = Node::new(endpoint.clone(), layout.config());
// Accepts the peers that read the broadcast. Keep the router alive.
let router = node.mount(Router::builder(endpoint)).spawn();

// Created in the node's route table: peers read it without a copy.
let broadcast: LocalBroadcast = layout.publish(&node, "studio")?;
let source = VideoSource::test_pattern(
    video::Size::new(1280, 720),
    video::FrameRate::new(30, 1).expect("a valid rate"),
)?;
broadcast.set_video(
    source,
    VideoEncoding::ladder([VideoRendition::p360(), VideoRendition::p720()]),
)?;
println!("share {}", layout.ticket(node.id(), "studio")?);

let subscription = node.subscribe_ticket(&ticket).await?;
let player = subscription.remote_broadcast().play(PlayerConfig::default())?;
let mut frames = player.video_frames();
while let Some(frame) = frames.next().await {
    // hand `frame` to a renderer
}

// Shuts the node down and every mounted service, then closes the endpoint.
router.shutdown().await?;

EndpointConfig::apply composes with your own endpoint builder, and calls::Calls places and answers one-to-one calls over a layout.

The main types:

The futures differ in what dropping them leaves behind:

FutureCancellation safeDropping it
EndpointConfig::bindyesnothing is bound
Node::subscribe, Node::subscribe_ticketyesabandons the wait, and a dial it started continues for other callers
calls::Calls::call, calls::Calls::answeryeshangs up
EndpointConfig::applyyesthe builder is lost, nothing is bound
Node::shutdownno, idempotentcall again to finish

Node::shutdown does not close the endpoint. Whoever binds it closes it, directly or through Router::shutdown.

media, [node] and rooms list their own futures. No public call takes a deadline. Bound a wait with tokio::time::timeout.

Each call returns the error of the crate that runs it: [node::Error] from the node and the layout, EndpointError from EndpointConfig, media::Error from sources, publishing and playback, rooms::Error from rooms, and calls::Error from calls. Each one converts into Error, so ? works in a function that returns it.

Only crypto-aws-lc-rs is on by default. crypto-rind, crypto-ring and crypto-aws-lc-rs pick the rustls backend that iroh and moq share, see crypto_provider. With more than one on, ring wins over aws-lc-rs and both over rind, so crypto-rind needs default features off. The default moves to crypto-rind once rind releases per-path QUIC keys.

player builds the receive side of media, publisher the send side, and media both. Device features turn on their side: capture, file and rpicam imply publisher, playback, render and record imply player. pipewire, pulseaudio and the hardware codecs apply to whichever side is on; pipewire with publisher also builds device capture. full is the usual app set, and rooms re-exports iroh-live-rooms and adds RoomsNode. Without a side the crate is the node, the layout, calls and endpoint setup.

Re-exports§

pub use iroh_live_node as node;
pub use iroh_live_node::moq_net;
pub use iroh_live_rooms as rooms;
pub use moq_json as json;

Modules§

calls
One-to-one calls over a layout’s call path.
layout
The <root>/<peer>/<name> path layout.
media
Sources, broadcasts and players, with the codec stacks they sit on.

Structs§

BroadcastTicket
A publisher’s endpoint id and the path of one of its broadcasts.
ConnectOptions
How to dial a peer with Node::connect_with.
EndpointConfig
An endpoint with MoqPreset, a key and mDNS.
Grant
What a session may subscribe to from this node, and publish into it.
MinimalPreset
An iroh preset that sets only the crypto provider.
MoqPreset
iroh’s N0 preset with BBR3 congestion control.
NetworkPath
One open network path of a Session, as returned by Session::network_paths.
NetworkSample
One reading of the link a broadcast arrives over.
Node
A MoQ node on an iroh endpoint.
NodeConfig
The configuration of a Node.
Publication
A published broadcast.
RelayConfig
How to attach to a media relay.
RelayLink
A media relay this node stays attached to.
RoomsNode
A node that serves both live broadcasts and rooms, with its router.
ServingLink
The link serving a subscription, and its latest reading.
Session
A direct session with a peer.
Subscription
A path resolved in a route table.
UnpublishOnDrop
A Publication that is unpublished when this guard drops.
ValueError
An error from a value track: a moq_json::Error that ? can convert.
ValueReader
A reader of a latest-value JSON track that follows its Subscription.
ValueWriter
Writes a latest-value JSON track, stamping each update with the time it is made.

Enums§

Congestion
A QUIC congestion controller.
EndpointError
An error from EndpointConfig::from_env or EndpointConfig::bind.
Error
An error from the node, the endpoint, rooms, calls, or the media.
LinkKind
What kind of link a session or a media relay attachment is.
Mdns
How an endpoint uses mDNS on the local network.
NetworkPathKind
The kind of address a NetworkPath goes to.
Reach
How Node::subscribe reaches a path the route table has no route to yet.
RelayStatus
The state of a relay link.

Functions§

crypto_provider
Returns the rustls crypto provider for iroh’s and moq’s TLS.
load_or_create_secret_key
Loads the secret key stored at path, or generates one and stores it there.

Type Aliases§

Audience
Who may see a publication.