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:
1 parent
5592a3ce1a
commit
5019bed324
6 files changed
+174
No files matched your search
@@ -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 };
|
||||
|
||||
Reference in new issue
Block a user