Skip to content

Conversation

shaunjstokes
Copy link
Contributor

@shaunjstokes shaunjstokes commented Oct 14, 2024

We've found that the patch #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.

@celliso1
Copy link

It appears this PR 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. See comments in #2226 (comment).

I can't say if this has any other impact, but it does fix the timestamp increment:

diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c
index 96933e6ea5..5f7972724a 100644
--- a/src/mod/codecs/mod_opus/mod_opus.c
+++ b/src/mod/codecs/mod_opus/mod_opus.c
@@ -1487,7 +1487,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
        }

        /* 16 khz */
-       samples = 160;
+       samples = 480; /* Increment RTP timestamp as if 48 kHz */
        bytes = 320;
        mss = 10000;
        rate = 16000;
@@ -1584,7 +1584,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
        }

        /* 8 khz */
-       samples = 80;
+       samples = 480; /* Increment RTP timestamp as if 48 kHz */
        bytes = 160;
        mss = 10000;
        rate = 8000;

ticpu added a commit to ticpu/freeswitch that referenced this pull request Jul 2, 2025
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 added a commit to ticpu/freeswitch that referenced this pull request Jul 3, 2025
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]>
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.

2 participants