From ae41b9656e97b150c11e53ff90d347494ad8c7b4 Mon Sep 17 00:00:00 2001
From: Grzegorz Sluja <grzegorz.sluja@iopsys.eu>
Date: Fri, 3 Nov 2023 08:42:34 +0000
Subject: [PATCH] Fix sequence number used by asterisk for outgoing RTP packets

There was no audio for 3-way conference when sRTP is used.
For 2-way calls frame->seqno is taken from DSP and is used by asterisk for the sequence number
in RTP headers. However for 3-way conference the sequence number is generated by asterisk and
it has to be greater than the previous value, otherwise libsrtp refuses to forward 'too old'
RTP packets.
---
 res/res_rtp_asterisk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 0412fd9bd4..a16057ae57 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -5047,7 +5047,12 @@ static int rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame *fr
 			rtp->ssrc = frame->ssrc;
 		}
 
-		put_unaligned_uint32(rtpheader, htonl((2 << 30) | (ext << 28) | (codec << 16) | (frame->seqno ? frame->seqno : seqno) | (mark << 23)));
+		if (frame->seqno)
+			rtp->seqno = frame->seqno;
+		else
+			rtp->seqno++;
+
+		put_unaligned_uint32(rtpheader, htonl((2 << 30) | (ext << 28) | (codec << 16) | (rtp->seqno) | (mark << 23)));
 		put_unaligned_uint32(rtpheader + 4, htonl(frame->ts ? frame->ts : rtp->lastts));
 		put_unaligned_uint32(rtpheader + 8, htonl(rtp->ssrc));
 
-- 
GitLab