Skip to content

Commit cc5cca3

Browse files
nltd101ticpu
authored andcommitted
[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 0646de8 commit cc5cca3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/switch_core_media.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5512,6 +5512,9 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
55125512
}
55135513
}
55145514

5515+
if (fmtp_remote_codec_rate) {
5516+
remote_codec_rate = fmtp_remote_codec_rate;
5517+
}
55155518
for (i = 0; i < smh->mparams->num_codecs && i < total_codecs; i++) {
55165519
const switch_codec_implementation_t *imp = codec_array[i];
55175520
uint32_t bit_rate = imp->bits_per_second;
@@ -5533,10 +5536,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
55335536
} else {
55345537
match = (!strcasecmp(rm_encoding, imp->iananame) &&
55355538
((map->rm_pt < 96 && imp->ianacode < 96) || (map->rm_pt > 95 && imp->ianacode > 95)) &&
5536-
(remote_codec_rate == codec_rate || fmtp_remote_codec_rate == imp->actual_samples_per_second)) ? 1 : 0;
5537-
if (fmtp_remote_codec_rate) {
5538-
remote_codec_rate = fmtp_remote_codec_rate;
5539-
}
5539+
(remote_codec_rate == codec_rate || remote_codec_rate == imp->actual_samples_per_second)) ? 1 : 0;
55405540
}
55415541

55425542
if (match && bit_rate && map_bit_rate && map_bit_rate != bit_rate && strcasecmp(map->rm_encoding, "ilbc") &&

0 commit comments

Comments
 (0)