Share between streams
Send a port's messages to a MoQ relay with the tatolab-moq nodes, and read them in another stream, another project or on another machine.
A stream doesn’t have to do everything itself. One stream can open the camera and send it, encoded, to a MoQ relay, and a detector, a recorder and a dashboard can each read it there from streams of their own, which you start, stop and change independently. The stream that sends doesn’t know who reads.
Nothing leaves a stream unless its graph says so. Streams reach each other only through a relay, using four nodes from the tatolab-moq module. Add it to a project from File › Marketplace… in Tato Studio, or from a terminal:
uv add tatolab-moq| Node | What it does |
|---|---|
MoqGateway |
Holds one connection to a relay and publishes one broadcast there, served as <broadcast>.hang |
MoqTrack |
Declares one track of a gateway’s broadcast. It has no ports. |
MoqTrackSend |
Writes each message of its content input to the track it names |
MoqTrackReceive |
Reads one track of any broadcast at the relay its gateway dials, and writes it on content |
Only the gateway’s process touches the network. The track, send and receive nodes reach their gateway over shared memory.
Run a relay
Section titled “Run a relay”Any MoQ relay works. For streams on one machine, or machines on one network, run the open-source moq-relay, the version the tatolab-moq tests run against:
cargo install moq-relay --version "=0.17.7" --locked[listen]bind = "127.0.0.1:4443"
[listen.tls]generate = ["localhost"]
[web.http]listen = "127.0.0.1:4443"
[auth]public = ["**"]moq-relay moq-relay.tomlThis relay listens on loopback, makes its own certificate, and lets anyone publish and read. Bind another address to reach it from other machines, and see Across machines for hosted relays and credentials.
Send a track
Section titled “Send a track”Here’s a stream that encodes the camera and sends it as the track video of the broadcast desk-camera:
camera (CameraSource) ── video ──▶ encoder (H264Encoder) ── encoded_video ──▶ send (MoqTrackSend)
gateway (MoqGateway) kind moq-relay, relay_url http://127.0.0.1:4443, broadcast desk-cameravideo-track (MoqTrack) gateway → gateway, track videosend track → video-trackIn Tato Studio that’s five nodes and two links: set each node’s inputs on it. In the graph document, the references to other nodes are {"node": "<name>"}:
{ "asset": "3ab2bafe-d590-40cc-b51e-1c20a455efef", "display_name": "camera", "nodes": [ { "id": "043b0c3a-b408-4845-b1b5-3b391caa5d80", "name": "camera", "type": "tatolab.camera:CameraSource" }, { "id": "fb9679fc-d88c-425e-aa1b-92df0fad6365", "name": "encoder", "type": "tatolab.h264:H264Encoder" }, { "id": "a8c55cac-41ab-4b5b-9d7e-3e06a17113a9", "name": "gateway", "type": "tatolab.moq:MoqGateway", "input_values": { "kind": "moq-relay", "relay_url": "http://127.0.0.1:4443", "broadcast": "desk-camera" } }, { "id": "7f2efe41-ed73-4761-92b9-e204b721b687", "name": "video-track", "type": "tatolab.moq:MoqTrack", "input_values": { "gateway": { "node": "gateway" }, "track": "video" } }, { "id": "7b44d276-d39c-4e56-9389-70d243f916e2", "name": "send", "type": "tatolab.moq:MoqTrackSend", "input_values": { "track": { "node": "video-track" } } } ], "links": [ { "source": { "node": "043b0c3a-b408-4845-b1b5-3b391caa5d80", "port": "video" }, "target": { "node": "fb9679fc-d88c-425e-aa1b-92df0fad6365", "port": "video" } }, { "source": { "node": "fb9679fc-d88c-425e-aa1b-92df0fad6365", "port": "encoded_video" }, "target": { "node": "7b44d276-d39c-4e56-9389-70d243f916e2", "port": "content" } } ]}One gateway carries as many tracks as you give it: add a MoqTrack and a MoqTrackSend for each port you send, such as an OpusEncoder’s audio or a detector’s Records. Each track has exactly one send; a second send naming the same track is refused when the project loads.
The gateway writes the broadcast’s catalog too, built from the stream facts of each port feeding a send, so a reader knows each track’s codec, size or channel count before its first frame.
Read a track
Section titled “Read a track”Another stream, in the same project or any other, reads the track through a gateway of its own:
gateway (MoqGateway) kind moq-relay, relay_url http://127.0.0.1:4443, broadcast desk-motionreceive (MoqTrackReceive) gateway → gateway, broadcast desk-camera.hang, track video, family packets, codec h264receive ── content ──▶ decoder (H264Decoder) ── video ──▶ detector (nodes.motion_detector:MotionDetector){ "id": "0b078685-9960-40c9-b7f9-203c11cf1675", "name": "receive", "type": "tatolab.moq:MoqTrackReceive", "input_values": { "gateway": { "node": "gateway" }, "broadcast": "desk-camera.hang", "track": "video", "family": "packets", "codec": "h264" }}| Setting | |
|---|---|
gateway |
The gateway whose connection reads the track |
broadcast |
The broadcast’s path at the relay, exactly as its publisher wrote it. A MoqGateway’s is <broadcast>.hang. |
track |
The track’s name in that broadcast |
family |
packets for encoded media, with a codec such as h264 or opus; records for Records |
max_age |
How far newer content may run past a missing group, in milliseconds of the track’s own time, before the group is given up. Default 100. |
Every stream needs a gateway of its own to read, even one that sends nothing, because a gateway is that stream’s connection. Its broadcast names what it would publish; give each gateway a different one.
A third stream, one that keeps a recording, can read desk-camera.hang too, and the camera is still opened only once. Stop the motion stream’s project, change it and play it again: the camera stream never notices.
The rules
Section titled “The rules”- Send pictures encoded. A picture’s message only names memory on the GPU, so
MoqTrackSendrefuses anImage. Encode it and decode it in the reader. Records, Packets, Channels and CPU-resident Arrays are sent as written. - A reader can’t slow the sender. Under backpressure the send drops the rest of a group and starts the next one clean, and a reader joins at a group start: a keyframe, for video.
- Each message keeps its time. A send stamps each object with its message’s timestamp, and the receive writes it at that time, on its own machine’s clock. Records from a detector line up with the frames they came from.
- A link can’t name another stream. Inside one graph document, links join that stream’s nodes. Between streams there’s only the relay.
- The relay decides who reads. The
authsection ofmoq-relay.toml, or a hosted relay’s tokens, decide who may publish and read each broadcast. See Across machines.
Every name is made URL-safe: lowercased, accents dropped, and anything other than letters, digits, -, ., _ and ~ turned into -. A broadcast you call Front Camera is served as front-camera.hang. Name tracks for what they carry, video, audio, motion: a reader types them.
Check what’s on the relay
Section titled “Check what’s on the relay”tatolab graph --stream <ID> shows the gateway, track and send nodes with their states and counters, and a gateway that can’t reach its relay says why in the log:
tatolab logs --dir ~/cameras --level warnCredentials
Section titled “Credentials”A hosted relay’s token is a secret, and the graph document is kept in the project’s history. Don’t write it there: hand it to the gateway on its settings input instead. A Records message there replaces the config’s values, so a node of your own that reads a secret store, or the runtime’s environment, can write {"token": ...} to it when the stream starts.