Skip to content

Audio RTP on the data channel peer (Opus, BUNDLE) - #17

Merged
stasadance merged 2 commits into
mainfrom
audio-rtp
Nov 24, 2026
Merged

stasadance merged 2 commits into
mainfrom
audio-rtp

Conversation

@stasadance

@stasadance stasadance commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Server-side voice forwarding (SFU, no encoding) on the same peer, port and DTLS session as the data channels.

API

const acc = await server.accept(offer, ip, port, {
  audio: {
    fmtp: 'minptime=10;useinbandfec=1;stereo=0;maxaveragebitrate=32000', // default 'minptime=10;useinbandfec=1'
    send: [{ ssrc: 1000, streamId: 'germs', trackId: 'voice0' }, ...],     // mid? = next browser-recvonly m-line
  },
});
acc.audio // { pt, recv: ['0'], send: [{ mid: '1', ssrc: 1000 }, ...] }

server.on('rtp', ({ peer, mid, data }) => ...)  // decrypted RTP, header + payload; never RTCP
server.on('rtpopen', ({ peer, mid }) => ...)    // DTLS-SRTP up for that mid
server.sendRtp(peer, mid, packet)               // false until rtpopen; no gate / pacer / egress cap
server.stats(peer).audioBytesIn / audioBytesOut / audioPacketsIn / audioPacketsOut
  • Opus answered at the payload type the browser offered, with our fmtp.
  • Browser sendonly/sendrecv m-lines are receive m-lines. Each send slot takes a browser recvonly m-line and its SSRC goes in the answer (a=ssrc:<ssrc> cname:<streamId>, msid:<streamId> <trackId>). Recvonly m-lines without a slot are answered inactive.
  • rtc does SRTCP plus sender/receiver reports. NACK/TWCC are not registered.
  • Without audio, audio m-lines are rejected (port 0), same as before.

rtc bump (stasadance/rtc lagless, 9e4c4bf -> ad5eeb0)

  • add_track_to_transceiver: an answerer's add_track always grabs the first free audio m-line, which is the mic.
  • Local ICE candidates go on the first accepted m-line. Before this, an offer with leading audio m-lines and no audio option (Chrome puts the application m-line last) got its candidates on rejected mid 0 and never connected. Germs hit this on main.

Tests

  • test/audio.test.mts, against headless Chromium, Firefox and WebKit. Shape: mic + 4 slots + 2 DCs. Mic RTP goes in, gets echoed to slot 0 with the slot's SSRC/PT, and the browser's inbound-rtp count on slot 0 is checked; other slots get nothing and the DCs work on the same peer. A second case sends the same offer without audio and checks that it connects.
  • CI's test job installs the three Playwright browsers and sets LAGLESS_REQUIRE_BROWSERS=1. Elsewhere, browsers that aren't installed are skipped.

accept() takes { audio: { fmtp?, send: [{ ssrc, mid?, streamId?, trackId? }] } }
and answers the offer's Opus audio m-lines on the same peer, port and DTLS
session as the data channels, at the payload type the browser offered and
with our fmtp. Browser sendonly m-lines are received (rtp events with the
decrypted RTP and its mid); each send slot takes a browser recvonly m-line
and puts its SSRC, cname and msid in the answer. sendRtp() SRTP-encrypts a
finished packet and sends it at once, outside the gate, pacer and egress
cap. rtpopen fires per audio mid once DTLS-SRTP is up. rtc handles SRTCP
and sender/receiver reports; RTCP never reaches JS. stats() gains audio
bytes and packets in/out.

Without the option, audio m-lines are rejected as before. The rtc bump
also fixes that case: candidates landed on the first (rejected) m-line,
so an offer with leading audio m-lines never connected.

Tested end to end against headless Chromium, Firefox and WebKit.
…rowsers elsewhere

The test job installs Chromium, Firefox and WebKit and sets
LAGLESS_REQUIRE_BROWSERS=1 so a launch failure fails the run. Other
platforms skip browsers Playwright doesn't have.
@stasadance
stasadance merged commit a64f760 into main Nov 24, 2026
@stasadance
stasadance deleted the audio-rtp branch November 24, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant