Skip to content

Commit f3f32f9

Browse files
authored
Fix SortMediaCapability offerer-priority track inversion (#1558)
The ternary in SetRemoteDescription selecting the priority-order key is flipped relative to the comment above it ("The offerer gets to set the codec priority"). The current code picks the answerer's track on both branches: - Receiving offer: uses LocalTrack (receiver is local; offerer is REMOTE) - Receiving answer: uses RemoteTrack (answerer is remote; offerer is LOCAL) Flipping the branches aligns behavior with the comment. Symptom: two peers with identical multi-codec audio Capabilities [Opus, PCMU, PCMA, G722] exchange offer/answer. OnAudioFormatsNegotiated fires with PCMU 8kHz mono on the offerer and OPUS 48kHz stereo on the answerer from the same negotiation. With this fix both land on Opus.
1 parent 1080fa9 commit f3f32f9

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/SIPSorcery/net/RTP/RTPSession.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,10 @@ public virtual SetDescriptionResultEnum SetRemoteDescription(SdpType sdpType, SD
12181218
capabilities = SDPAudioVideoMediaFormat.GetCompatibleFormats(currentMediaStream.RemoteTrack?.Capabilities, currentMediaStream.LocalTrack?.Capabilities);
12191219

12201220
// The offerer gets to set the codec priority.
1221+
// When receiving an offer: the REMOTE party is the offerer, so their Capabilities are the priority key.
1222+
// When receiving an answer: LOCAL is the offerer (we sent the offer), so our Capabilities are the priority key.
12211223
SDPAudioVideoMediaFormat.SortMediaCapability(capabilities,
1222-
sdpType == SdpType.offer ? currentMediaStream.LocalTrack?.Capabilities : currentMediaStream.RemoteTrack?.Capabilities);
1224+
sdpType == SdpType.offer ? currentMediaStream.RemoteTrack?.Capabilities : currentMediaStream.LocalTrack?.Capabilities);
12231225

12241226
currentMediaStream.LocalTrack.Capabilities = capabilities;
12251227
currentMediaStream.RemoteTrack.Capabilities = capabilities;

0 commit comments

Comments
 (0)