Skip to main content

send_loop

Function send_loop 

Source
pub async fn send_loop(
    socket: Arc<UdpSocket>,
    remote: SocketAddr,
    config: RtpSendConfig,
    payloads: Receiver<Vec<u8>>,
    cancel: CancellationToken,
)
Expand description

Forward pre-encoded payloads out as RTP packets.

Each payload received on payloads becomes one RTP packet sent to remote. Sequence and timestamp counters advance by 1 and samples_per_frame respectively per packet; SSRC and payload type stay fixed for the lifetime of the loop.

Pacing is the caller’s job. This loop sends as soon as a payload arrives; if the consumer pushes 20 ms G.711 frames as fast as it can encode them, the remote will hear chipmunk audio. Push at the codec’s packetization cadence (a tokio::time::interval ticking the encoder is the usual shape).

socket is Arc-shared so the receive side can keep using the same bound port — RFC 3550 expects RTP send and receive to share a 5-tuple.

The loop exits when cancel is triggered, when payloads closes, or when a send fails (typically a closed socket).