Commit d3b0e76
[core/media] update remote_codec_rate before codec comparison
When the configured candidates are OPUS 48kHz, PCMA,..., the negotiation
unexpectedly matches OPUS 16k with OPUS 48kHz. This occurs because the
implementation updates the remote sample rate after the initial media
negotiation (cooperation loop), leading to incorrect matching.
Before:
```
2025-07-04 15:56:19.826475 96.27% [DEBUG] sofia.c:7586 Remote SDP:
v=0
o=- 3960604579 3960604579 IN IP4 52.76.213.59
s=pjmedia
b=AS:50
t=0 0
a=X-nat:0
m=audio 24598 RTP/AVP 96 120
c=IN IP4 52.76.213.59
b=TIAS:32000
a=rtpmap:96 opus/48000/2
a=fmtp:96 useinbandfec=1;maxplaybackrate=16000;sprop-maxcapturerate=16000
a=rtpmap:120 telephone-event/48000
a=fmtp:120 0-16
a=ssrc:184830022 cname:742327632f371b3d
a=rtcp:24599
switch_core_media.c:5526 Audio Codec Compare [opus:96:48000:20:0:1]/[opus:116:48000:20:0:1]
switch_core_media.c:5569 Audio Codec Compare [opus:116:48000:20:0:1] is saved as a near-match
switch_core_media.c:5526 Audio Codec Compare [opus:96:16000:20:0:1]/[PCMU:0:8000:20:64000:1]
switch_core_media.c:5526 Audio Codec Compare [opus:96:16000:20:0:1]/[G729:18:8000:20:8000:1]
switch_core_media.c:5526 Audio Codec Compare [opus:96:16000:20:0:1]/[GSM:3:8000:20:13200:1]
```
As shown in the log above, the sample rate compared with the first supported
codec is 48kHz. It should be 16kHz as configured by `sprop-maxcapturerate`.
After this patch, the sample rate is updated to 16kHz before comparison:
```
2025-07-04 17:24:02.999514 97.50% [DEBUG] sofia.c:7586 Remote SDP:
v=0
o=- 3960609842 3960609842 IN IP4 52.76.213.59
s=pjmedia
b=AS:50
t=0 0
a=X-nat:0
m=audio 19208 RTP/AVP 96 120
c=IN IP4 52.76.213.59
b=TIAS:32000
a=rtpmap:96 opus/48000/2
a=fmtp:96 useinbandfec=1;maxplaybackrate=16000;sprop-maxcapturerate=16000
a=rtpmap:120 telephone-event/48000
a=fmtp:120 0-16
a=ssrc:17356830 cname:4cb67c6474c259d7
a=rtcp:19209
switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[opus:116:48000:20:0:1]
switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[PCMU:0:8000:20:64000:1]
switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[G729:18:8000:20:8000:1]
switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[GSM:3:8000:20:13200:1]
```
Tested-By: Jérôme Poulin <jeromepoulin@gmail.com>1 parent c53cf00 commit d3b0e76
1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5512 | 5512 | | |
5513 | 5513 | | |
5514 | 5514 | | |
| 5515 | + | |
| 5516 | + | |
| 5517 | + | |
5515 | 5518 | | |
5516 | 5519 | | |
5517 | 5520 | | |
| |||
5533 | 5536 | | |
5534 | 5537 | | |
5535 | 5538 | | |
5536 | | - | |
5537 | | - | |
5538 | | - | |
5539 | | - | |
| 5539 | + | |
5540 | 5540 | | |
5541 | 5541 | | |
5542 | 5542 | | |
| |||
0 commit comments