-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codec renegotiation #620
Comments
Formatting the offers to understand the problem:
|
@alexlapa is this really "renegotiation"? If I recall correctly, the SDP is not actually committed to the let pc = new RTCPeerConnection();
await pc.setRemoteDescription({ … });
let vp9_answer = (await pc.createAnswer()).sdp;
pc.setLocalDescription(vp9_answer); // missing this?!
await pc.setRemoteDescription({ ... });
let vp8_answer = (await pc.createAnswer()).sdp;
pc.setLocalDescription(vp8_answer); // missing this?! |
Well thats a simplified example. Here is full if you want to try it yourself: let pc1 = new RTCPeerConnection();
let pc2 = new RTCPeerConnection();
let track = (await navigator.mediaDevices.getUserMedia({video:true})).getTracks()[0];
let tr = pc1.addTransceiver(track);
pc1.onicecandidate = event => {
if (event.candidate) {
pc2.addIceCandidate(event.candidate);
}
};
pc2.onicecandidate = event => {
if (event.candidate) {
pc1.addIceCandidate(event.candidate);
}
};
tr.setCodecPreferences(RTCRtpSender.getCapabilities("video").codecs.filter(codec => codec.mimeType === "video/VP9"));
await pc1.setLocalDescription();
await pc2.setRemoteDescription(pc1.localDescription);
await pc2.setLocalDescription();
await pc1.setRemoteDescription(pc2.localDescription);
await new Promise(resolve => setTimeout(resolve, 5000));
tr.setCodecPreferences(RTCRtpSender.getCapabilities("video").codecs.filter(codec => codec.mimeType === "video/VP8"));
await pc1.setLocalDescription();
await pc2.setRemoteDescription(pc1.localDescription);
await pc2.setLocalDescription();
await pc1.setRemoteDescription(pc2.localDescription); Or this snippet right here https://webrtc.github.io/samples/src/content/peerconnection/pc1/: pc1.getTransceivers()[1].setCodecPreferences(RTCRtpSender.getCapabilities("video").codecs.filter(codec => codec.mimeType === "video/H264"));
await pc1.setLocalDescription();
await pc2.setRemoteDescription(pc1.localDescription);
await pc2.setLocalDescription();
await pc1.setRemoteDescription(pc2.localDescription); It will work like this: Screencast.from.2025-02-03.15-42-34.webmNotice codec changes in webrtc-internals after renegotiation. |
I am curious why you need to renegotiate codecs? |
@alexlapa interesting! ok. today i learn. thanks! I'd like to think of the SDP/session state as something that is incrementally added to. It's like a delicate stack of cards, where we can't change around the foundations. Inside str0m fixing this could be a bit messy. I'm not sure the upheaval would be worth it. The most important renegotiation is to support changing send/recv/sendrecv/inactive – which I believe we handle correctly already. I don't know whether this is a particularly important use case. Though, I'm happy to be convinced/proven otherwise. |
So right now str0m cannot change negotiated codec for a media line. Meaning that in the following example final assert will panic cause str0m wont't change mline from VP9 to VP8.
Renegotiating used codecs is perfectly fine and works via web API, i.e. this js snippet:
So is this a bug or working as intended? Do you want this changed? I need to be able to change used codecs, but Im not sure whether to implement this in str0m or just remove old media lines and add new ones.
The text was updated successfully, but these errors were encountered: