From 2651d69a16e84c83c59d2f4ed15e0d8316091adb Mon Sep 17 00:00:00 2001
From: Grzegorz Sluja <grzegorz.sluja@sigma.se>
Date: Fri, 13 Oct 2023 12:19:55 +0200
Subject: [PATCH] Use the same header for RTP/RTCP packets in DSP and Asterisk

---
 include/asterisk/frame.h | 2 ++
 main/frame.c             | 1 +
 res/res_rtp_asterisk.c   | 7 ++++---
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index 398a105343..3d004158c5 100644
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -191,6 +191,8 @@ struct ast_frame {
 	long ts;
 	/*! Length in milliseconds */
 	long len;
+	/*! SSRC */
+	long ssrc;
 	/*! Sequence number */
 	int seqno;
 	/*! Stream number the frame originated from */
diff --git a/main/frame.c b/main/frame.c
index f5e7ad038e..a0e41bf6d2 100644
--- a/main/frame.c
+++ b/main/frame.c
@@ -389,6 +389,7 @@ struct ast_frame *__ast_frdup(const struct ast_frame *f, const char *file, int l
 	out->ts = f->ts;
 	out->len = f->len;
 	out->seqno = f->seqno;
+	out->ssrc = f->ssrc;
 	out->stream_num = f->stream_num;
 	return out;
 }
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index c245064bac..6580b0d00e 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -5118,9 +5118,9 @@ static int rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame *fr
 		packet_len = frame->datalen + hdrlen;
 		rtpheader = (unsigned char *)(frame->data.ptr - hdrlen);
 
-		put_unaligned_uint32(rtpheader, htonl((2 << 30) | (ext << 28) | (codec << 16) | (seqno) | (mark << 23)));
-		put_unaligned_uint32(rtpheader + 4, htonl(rtp->lastts));
-		put_unaligned_uint32(rtpheader + 8, htonl(rtp->ssrc));
+		put_unaligned_uint32(rtpheader, htonl((2 << 30) | (ext << 28) | (codec << 16) | (frame->seqno ? frame->seqno : seqno) | (mark << 23)));
+		put_unaligned_uint32(rtpheader + 4, htonl(frame->ts ? frame->ts : rtp->lastts));
+		put_unaligned_uint32(rtpheader + 8, htonl(frame->ssrc ? frame->ssrc : rtp->ssrc));
 
 		/* We assume right now that we will only ever have the abs-send-time extension in the packet
 		 * which simplifies things a bit.
@@ -7866,6 +7866,7 @@ static struct ast_frame *ast_rtp_interpret(struct ast_rtp_instance *instance, st
 	rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET;
 	ast_set_flag(&rtp->f, AST_FRFLAG_HAS_SEQUENCE_NUMBER);
 	rtp->f.seqno = seqno;
+	rtp->f.ssrc = ssrc;
 	rtp->f.stream_num = rtp->stream_num;
 
 	if ((ast_format_cmp(rtp->f.subclass.format, ast_format_t140) == AST_FORMAT_CMP_EQUAL)
-- 
GitLab