Answer a streamer's new offer on the running connection

Watching a stream from the official client failed. Its log shows why:
after our answer it decided our codec choice did not suit it ("remote peer
is using unsupported codec, realign") and sent a new offer on the same
connection, a renegotiation. Voelin answered every offer with a new peer:
new ICE credentials, new DTLS fingerprint (the official client logged both
answers, they differ), so the connection the official client kept using
was gone and no picture came.

- `Peer::renegotiate` answers a new offer on the running peer (str0m
  `accept_offer` on the same Rtc): same ICE credentials and fingerprint.
- The viewer uses it for an `offer` signal while it has a connection; a
  `reconnectOffer` still starts a new one.
- str0m answers a renegotiation in the codec order the connection was
  built with, so a streamer re-offering another codec first kept sending
  the old one; `order_like_offer` puts the answer's payload types in the
  new offer's order.

Tests: a unit test (a str0m offerer adds audio in a new offer; same ICE
credentials and fingerprint, audio answered) and the order helper; the
browser interop test `browser_renegotiates_with_rust` (Chromium streams
VP8, re-offers VP9 on the same connection, VP9 frames arrive), passing
with Chromium 152.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 22:13:31 +03:00
1 parent 5592a3ce1a
commit 5019bed324
6 files changed
+174

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ TeamSpeak server is involved.
| `browser_streams_to_rust` | Chromium offers a canvas `captureStream` and an oscillator with VP8, VP9, H264 and AV1 preferred in turn (codecs the browser cannot send are skipped); our viewer `Peer::answer` must receive frames of that codec and Opus, over `AES_CM_128_HMAC_SHA1_80`. VP8 also uses trickled browser candidates and checks that a PLI brings a keyframe |
| `real_encoders_decode_in_browser` (voelin-core) | Every encoder this machine has (`Codecs::encoders()`), as a share uses it: the 1280x720 test pattern through the `Streamer`, VA-API encoders also from DMA-BUFs as the ScreenCast portal hands over the screen; our streamer peer offers that codec alone (H.264 as Constrained Baseline, see below); the browser must decode at least 60 frames at 1280x720 in 3 s. Codecs the browser does not answer (HEVC, H.264 in Playwright's Chromium) are skipped |
| `share_offer_picks_a_codec_every_client_decodes` (voelin-core) | The offer a share makes on this machine (`preferred_codec`, `peer_config`): the browser, answering with the first codec of the offer it lists as the official client does, must pick one every TeamSpeak client decodes (`decoded_everywhere`), and decode it |
| `browser_renegotiates_with_rust` | Chromium streams VP8, then sends a new offer on the same connection with VP9 first (as the official client re-offers when it does not encode the codec we chose); `Peer::renegotiate` answers on the same peer, in the new offer's codec order; VP9 frames must arrive |
| `trickled_candidates_reach_browser` | A server-reflexive candidate (from a fake STUN server) as our sessions trickle it (`iceCandidate` signal with the peer's mid) is accepted by `addIceCandidate` |
## Running
+15
View File
@@ -7,6 +7,8 @@
// offer {codec, trickle} send canvas video + oscillator audio; offer with
// `codec` preferred -> {sdp} or {unsupported};
// with `trickle` the SDP has no candidates
// reoffer {codec} a new offer on the running connection with `codec`
// preferred (a renegotiation) -> {sdp} or {unsupported}
// candidates candidates gathered so far -> {candidates: [{candidate, sdpMid, sdpMLineIndex}]}
// accept {sdp} apply the answer to our offer
// candidate {candidate, sdpMid, sdpMLineIndex} add a remote candidate
@@ -123,6 +125,19 @@ window.peer = {
return { sdp };
},
// A new offer on the running connection with the codec preferred, as the
// official client sends when it re-aligns its codec.
async reoffer({ codec }) {
const pc = this.pc;
const transceiver = pc.getTransceivers().find((t) => t.sender.track && t.sender.track.kind === 'video');
const all = RTCRtpSender.getCapabilities('video').codecs;
const wanted = all.filter((c) => c.mimeType.toLowerCase() === 'video/' + codec.toLowerCase());
if (wanted.length === 0) return { unsupported: codec };
transceiver.setCodecPreferences([...wanted, ...all.filter((c) => !wanted.includes(c))]);
await pc.setLocalDescription(await pc.createOffer());
return { sdp: pc.localDescription.sdp };
},
async candidates() {
await gathered(this.pc, 3000);
return { candidates: this.localCandidates };