From 09e87f5a15f7c2bbdfb1d206c5cc66936333a9eb Mon Sep 17 00:00:00 2001 From: Mike Bradeen Date: Mon, 23 Feb 2026 16:10:46 -0700 Subject: [PATCH] res_rtp_asterisk: use correct sample rate lookup to account for g722 Swap out ast_rtp_get_rate for ast_format_get_sample_rate when looking at the paired audio codec rate to account for g722 oddness. Resolves: #1657 --- res/res_rtp_asterisk.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 586845cabc..5f63eb0737 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -4391,15 +4391,19 @@ static int ast_rtp_dtmf_begin(struct ast_rtp_instance *instance, char digit) return -1; } + + /* g722 is a 16K codec that masquerades as an 8K codec within RTP. ast_rtp_get_rate was written specifically to + handle this. If we use the actual sample rate of g722 in this scenario and there is a 16K telephone-event on + offer, we will end up using that instead of the 8K rate telephone-event that is expected with g722. */ if (rtp->lasttxformat == ast_format_none) { /* No audio frames have been written yet so we have to lookup both the preferred payload type and bitrate. */ payload_format = ast_rtp_codecs_get_preferred_format(ast_rtp_instance_get_codecs(instance)); if (payload_format) { /* If we have a preferred type, use that. Otherwise default to 8K. */ - sample_rate = ast_format_get_sample_rate(payload_format); + sample_rate = ast_rtp_get_rate(payload_format); } } else { - sample_rate = ast_format_get_sample_rate(rtp->lasttxformat); + sample_rate = ast_rtp_get_rate(rtp->lasttxformat); } if (sample_rate != -1) {