Octoroom.Outlet (octoroom v0.1.0)

Copy Markdown View Source

One worker output track. Paces audio to real time and sends it, Opus encoded, through the worker's peer connection: Cloudflare forwards whatever it is sent, so anything sent early would still play after a barge-in.

Workers queue room PCM (48 kHz stereo s16le) with play/3. Every 20 ms the outlet sends the next whole frame and sends nothing when the queue is empty. flush/2 empties the queue, so at most one frame plus the network is already on its way, and says how much audio it dropped: what was queued minus that is what listeners heard. Audio played before the track is pushed and its connection is up is dropped as it comes due, as a live stream would be.

Once its connection is up, the outlet sends one frame of silence, so Cloudflare keeps the track however long the worker stays quiet. The first frame sent tells the room server the track is live, so listeners can pull it. The outlet is separate from its worker: if the worker crashes, the track stays published.

Summary

Functions

Returns a specification to start this module under a supervisor.

Drops an output track's queued, unplayed audio. Returns how many ms of audio it dropped, or nil if the outlet isn't running.

Queues room PCM on an output track. A no-op if the outlet isn't running.

%{queued_ms, sent, dropped, underruns, connected, live} for an output track, or nil if it isn't running. underruns counts the times the queue ran dry while playing.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush(room_id, name)

Drops an output track's queued, unplayed audio. Returns how many ms of audio it dropped, or nil if the outlet isn't running.

play(room_id, name, pcm)

Queues room PCM on an output track. A no-op if the outlet isn't running.

start_link(opts)

stats(room_id, name)

%{queued_ms, sent, dropped, underruns, connected, live} for an output track, or nil if it isn't running. underruns counts the times the queue ran dry while playing.

via(room_id, name)

whereis(room_id, name)