From ee8ea9275ffb0adf20faae2e8fce4bbad330e994 Mon Sep 17 00:00:00 2001
From: "Joshua C. Colp" <jcolp@sangoma.com>
Date: Wed, 17 Jun 2020 05:58:44 -0300
Subject: [PATCH] res_pjsip_session: Preserve label on incoming re-INVITE.

When a re-INVITE is received we create a new set of
streams that are then swapped in as the active streams.
We did not preserve the SDP label from the previous
streams, resulting in the label getting lost.

This change ensures that if an SDP label is present
on the previous stream then it is set on the new stream.

ASTERISK-28953

Change-Id: I9dd63b88b562fe96ce5c791a3dae5bcaca258445
---
 res/res_pjsip_session.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 67899e4180..621dd1676d 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -762,6 +762,14 @@ static int handle_incoming_sdp(struct ast_sip_session *session, const pjmedia_sd
 				ast_stream_free(stream);
 				return -1;
 			}
+			if (existing_stream) {
+				const char *stream_label = ast_stream_get_metadata(existing_stream, "SDP:LABEL");
+
+				if (!ast_strlen_zero(stream_label)) {
+					ast_stream_set_metadata(stream, "SDP:LABEL", stream_label);
+				}
+			}
+
 			/* For backwards compatibility with the core the default audio stream is always sendrecv */
 			if (!ast_sip_session_is_pending_stream_default(session, stream) || strcmp(media, "audio")) {
 				if (pjmedia_sdp_media_find_attr2(remote_stream, "sendonly", NULL)) {
@@ -1968,6 +1976,14 @@ static int sdp_requires_deferral(struct ast_sip_session *session, const pjmedia_
 			return -1;
 		}
 
+		if (existing_stream) {
+			const char *stream_label = ast_stream_get_metadata(existing_stream, "SDP:LABEL");
+
+			if (!ast_strlen_zero(stream_label)) {
+				ast_stream_set_metadata(stream, "SDP:LABEL", stream_label);
+			}
+		}
+
 		session_media = ast_sip_session_media_state_add(session, session->pending_media_state, ast_media_type_from_str(media), i);
 		if (!session_media) {
 			return -1;
-- 
GitLab