Skip to content

Update remote_codec_rate before codec comparison #2833

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nltd101
Copy link

@nltd101 nltd101 commented Jul 4, 2025

Issue:

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.

Solution:

Move the sample rate update to occur before negotiation loop, ensuring sample rate is updated from the beginning.

Freeswitch log:

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

2025-07-04 15:56:19.826475 96.27% [DEBUG] switch_core_media.c:5526 Audio Codec Compare [opus:96:48000:20:0:1]/[opus:116:48000:20:0:1]
2025-07-04 15:56:19.826475 96.27% [DEBUG] switch_core_media.c:5569 Audio Codec Compare [opus:116:48000:20:0:1] is saved as a near-match
2025-07-04 15:56:19.826475 96.27% [DEBUG] switch_core_media.c:5526 Audio Codec Compare [opus:96:16000:20:0:1]/[PCMU:0:8000:20:64000:1]
2025-07-04 15:56:19.826475 96.27% [DEBUG] switch_core_media.c:5526 Audio Codec Compare [opus:96:16000:20:0:1]/[G729:18:8000:20:8000:1]
2025-07-04 15:56:19.826475 96.27% [DEBUG] switch_core_media.c:5526 Audio Codec Compare [opus:96:16000:20:0:1]/[GSM:3:8000:20:13200:1]

As above log, the sample rate compared with the first supported codec is 48kHz. It should have been 16khz as configured by sprop-maxcapturerate

After patching, that should be expected. The sample rate is updated to be 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

2025-07-04 17:24:02.999514 97.50% [DEBUG] switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[opus:116:48000:20:0:1]
2025-07-04 17:24:02.999514 97.50% [DEBUG] switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[PCMU:0:8000:20:64000:1]
2025-07-04 17:24:02.999514 97.50% [DEBUG] switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[G729:18:8000:20:8000:1]
2025-07-04 17:24:02.999514 97.50% [DEBUG] switch_core_media.c:5529 Audio Codec Compare [opus:96:16000:20:0:1]/[GSM:3:8000:20:13200:1]

@nltd101 nltd101 marked this pull request as ready for review July 4, 2025 09:30
@nltd101 nltd101 changed the title Update remote_codec_rate before codec comparation Update remote_codec_rate before codec comparition Jul 4, 2025
@nltd101 nltd101 changed the title Update remote_codec_rate before codec comparition Update remote_codec_rate before codec comparison Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant