diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index d9c3319a821cde236594bdd21e0439874f866361..c23f972b96919b7f55e69bd31a6f788fd0ce0ea7 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -5066,9 +5066,17 @@ 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);
 
+		if (frame->ssrc && frame->ssrc != rtp->ssrc) {
+			struct ast_srtp *srtp = ast_rtp_instance_get_srtp(instance, 0);
+			if (srtp) {
+				res_srtp->change_source(srtp, rtp->ssrc, frame->ssrc);
+			}
+			rtp->ssrc = frame->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));
+		put_unaligned_uint32(rtpheader + 8, htonl(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.