From 3385191049d3291c82eb8e30152d85b4b51ff4b0 Mon Sep 17 00:00:00 2001
From: Richard Fuchs <rfuchs@sipwise.com>
Date: Mon, 10 Mar 2025 09:51:42 -0400
Subject: [PATCH] MT#55283 fix u= etc support

Use the correct media object (the source media) to obtain media-level i=
lines from. Adapt OSRTP output function to do the same.

Change-Id: I9ba4db286cf9d822b8986a7da2cb4f4aa1c69646
---
 daemon/sdp.c           |  8 +++---
 t/auto-daemon-tests.pl | 61 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/daemon/sdp.c b/daemon/sdp.c
index 9bebd3d2b..af6a0a7a6 100644
--- a/daemon/sdp.c
+++ b/daemon/sdp.c
@@ -2697,7 +2697,8 @@ static void print_sdp_media_section(GString *s, struct call_media *media,
 		return;
 	}
 
-	sdp_out_print_information(s, &media->sdp_information);
+	if (source_media)
+		sdp_out_print_information(s, &source_media->sdp_information);
 
 	/* add actual media connection
 	 * print zeroed address for the non accepted media, see RFC 3264 */
@@ -3009,6 +3010,7 @@ static bool sdp_out_add_media(GString *out, struct call_media *media,
 }
 
 static void sdp_out_handle_osrtp1(GString *out, struct call_media *media,
+		struct call_media *source_media,
 		const endpoint_t *address, const struct transport_protocol *prtp,
 		struct packet_stream *rtp_ps, packet_stream_list *rtp_ps_link,
 		sdp_ng_flags *flags)
@@ -3025,7 +3027,7 @@ static void sdp_out_handle_osrtp1(GString *out, struct call_media *media,
 
 		sdp_out_add_osrtp_media(out, media, prtp, address);
 		/* print media level attributes */
-		print_sdp_media_section(out, media, address, NULL, NULL, rtp_ps, rtp_ps_link, flags);
+		print_sdp_media_section(out, media, address, NULL, source_media, rtp_ps, rtp_ps_link, flags);
 
 		media->protocol = proto;
 	}
@@ -3211,7 +3213,7 @@ int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags)
 			prtp = &transport_protocols[media->protocol->rtp_proto];
 
 		/* handle first OSRTP part */
-		sdp_out_handle_osrtp1(s, media, &sdp_address, prtp, rtp_ps, rtp_ps_link, flags);
+		sdp_out_handle_osrtp1(s, media, source_media, &sdp_address, prtp, rtp_ps, rtp_ps_link, flags);
 
 		/* set: media type, port, protocol (e.g. RTP/SAVP) */
 		err = "Unknown media protocol";
diff --git a/t/auto-daemon-tests.pl b/t/auto-daemon-tests.pl
index a5f777350..fcbe8ac4a 100755
--- a/t/auto-daemon-tests.pl
+++ b/t/auto-daemon-tests.pl
@@ -84,6 +84,67 @@ sub stun_succ {
 
 
 
+new_call;
+
+offer('i= etc lines', {}, <<SDP);
+v=0
+o=- 1545997027 1 IN IP4 198.51.100.11
+s=tester
+i=info1
+u=uri
+e=email
+p=hone
+c=IN IP4 198.51.100.50
+t=0 0
+m=audio 3000 RTP/AVP 8
+i=info2
+a=sendrecv
+m=audio 3000 RTP/AVP 8
+i=info3
+a=sendrecv
+m=video 3000 RTP/AVP 96
+i=info4
+a=sendrecv
+a=rtpmap:96 VP8/90000
+m=video 3000 RTP/AVP 96
+i=info5
+a=sendrecv
+a=rtpmap:96 VP8/90000
+-----------------------------------------------
+v=0
+o=- 1545997027 1 IN IP4 198.51.100.11
+s=tester
+i=info1
+u=uri
+e=email
+p=hone
+t=0 0
+m=audio PORT RTP/AVP 8
+i=info2
+c=IN IP4 203.0.113.1
+a=rtpmap:8 PCMA/8000
+a=sendrecv
+a=rtcp:PORT
+m=audio PORT RTP/AVP 8
+i=info3
+c=IN IP4 203.0.113.1
+a=rtpmap:8 PCMA/8000
+a=sendrecv
+a=rtcp:PORT
+m=video PORT RTP/AVP 96
+i=info4
+c=IN IP4 203.0.113.1
+a=rtpmap:96 VP8/90000
+a=sendrecv
+a=rtcp:PORT
+m=video PORT RTP/AVP 96
+i=info5
+c=IN IP4 203.0.113.1
+a=rtpmap:96 VP8/90000
+a=sendrecv
+a=rtcp:PORT
+SDP
+
 new_call;
 
 offer('branched offer with strip', { 'via-branch' => 'a' }, <<SDP);