Skip to content

[mod_opus] Fix to allow transcoding between different rates #2832

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 2 commits into
base: master
Choose a base branch
from

Conversation

ticpu
Copy link

@ticpu ticpu commented Jul 2, 2025

This is in relation to #2226 and its discussions.

It includes a comprehensive list of patches that were suggested in isolation but that work better as a whole.

Thanks to @celliso1, @shaunjstokes, @magiclin99 and all others who have contributed to fixing this issue.

Obsoletes: #2582, #2623.
Fixes: #2226

@celliso1
Copy link

celliso1 commented Jul 2, 2025

The commit shows redundant use of actual_samples_per_second:

				uint32_t codec_rate = imp->actual_samples_per_second;

				if (!strcasecmp(map->rm_encoding, "opus")) {
					codec_rate = imp->actual_samples_per_second;
				}`

Did you mean this instead ? So only opus is affected:

				uint32_t codec_rate = imp->samples_per_second;

				if (!strcasecmp(map->rm_encoding, "opus")) {
					codec_rate = imp->actual_samples_per_second;
				}`

See #2582 (comment) regarding #2623.

@ticpu
Copy link
Author

ticpu commented Jul 3, 2025

@celliso1 oh.. my bad. True, it does affect recordings in an unpredictable way like this. I will correct this, thank you.

shaunjstokes and others added 2 commits July 3, 2025 11:59
In vars.xml , when you use codec settings like this:
`<X-PRE-PROCESS cmd="set" data="internal_codec_prefs=OPUS@16000h@1c,PCMU"/>`

The switch_core_media.c line 5520 only takes the OPUS default rate (48k)
instead of 16k in the config.

Because of this, FS won't be able to choose opus if your client asks for 16k
opus. You will see same log symptom as signalwire#2226

We've found that the patch signalwire#2582 has the side effect of causing calls that
fail to negotiate the same codec as Leg A for Leg B to fail with SIP
488 INCOMPATIBLE_DESTINATION. That's not an option for us, we need backwards
compatibility with other codecs.

Rather than apply this for all codecs it should only apply for Opus. Now
calls using Opus and other codecs establish correctly on both legs, and there
are no issues with codec negotiation when the codecs on Leg A and Leg B don't
match.

Tested-by: Jérôme Poulin <[email protected]>
Co-authored-by: magiclin99 <[email protected]>
Allow transcoding between different rate without messing up the
RTP timestamps after transcoding kicks-in.

@celliso1: It appears this PR (signalwire#2623) has revealed a bug in the opus encoder affecting the timestamp increment. The RFC 7587 states opus always increments at 48kHz regardless of the payload sample rate, but mod_opus.c is using 16 kHz or 8kHz samples per packet.

Co-authored-by: celliso1 <[email protected]>
Tested-by: Jérôme Poulin <[email protected]>
@ticpu ticpu force-pushed the mod_opus_transcoding_fixes branch from ad06e74 to 8cd8876 Compare July 3, 2025 16:01
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.

Incorrect OPUS negotiation
3 participants