From bc8de2ba3a85f48cd3b43abf75b96ababd0756ae Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 12 Sep 2024 10:22:58 +0200 Subject: [PATCH] MT#60476 sdp_create: add `sdp_out_add_media()` Move handling of the usual `m=` line, so printing of: media type, port, protocol (e.g. RTP/SAVP), to a separate function to make the `sdp_create()` implementation be more laconic for reading. This function is a default alternative for the `sdp_out_add_osrtp_media()`. No functional changes. Change-Id: I469abbbf6e203d2cc655a26bbf44ff3c7a66b1df --- daemon/sdp.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index bea48b465..77bee7663 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -3665,6 +3665,9 @@ static void sdp_out_add_media_connection(GString *out, struct call_media *media, media_conn_address); } +/** + * Add OSRTP related media line. + */ static void sdp_out_add_osrtp_media(GString *out, struct call_media *media, const struct transport_protocol *prtp, unsigned int port) { @@ -3678,6 +3681,32 @@ static void sdp_out_add_osrtp_media(GString *out, struct call_media *media, g_string_append_printf(out, "\r\n"); } +/** + * Add media line. + */ +static bool sdp_out_add_media(GString *out, struct call_media *media, + unsigned int port) +{ + if (media->protocol) + g_string_append_printf(out, "m=" STR_FORMAT " %i %s ", + STR_FMT(&media->type), + port, + media->protocol->name); + else if (media->protocol_str.s) + g_string_append_printf(out, "m=" STR_FORMAT " %i " STR_FORMAT " ", + STR_FMT(&media->type), + port, + STR_FMT(&media->protocol_str)); + else + return false; + + /* print codecs and add newline */ + print_codec_list(out, media); + g_string_append_printf(out, "\r\n"); + + return true; +} + static void sdp_out_handle_osrtp1(GString *out, struct call_media *media, unsigned int port, const struct transport_protocol *prtp, struct packet_stream *rtp_ps, packet_stream_list *rtp_ps_link, @@ -3817,23 +3846,9 @@ int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags) /* set: media type, port, protocol (e.g. RTP/SAVP) */ err = "Unknown media protocol"; - if (media->protocol) - g_string_append_printf(s, "m=" STR_FORMAT " %i %s ", - STR_FMT(&media->type), - port, - media->protocol->name); - else if (media->protocol_str.s) - g_string_append_printf(s, "m=" STR_FORMAT " %i " STR_FORMAT " ", - STR_FMT(&media->type), - port, - STR_FMT(&media->protocol_str)); - else + if (!sdp_out_add_media(s, media, port)) goto err; - /* print codecs and add newline */ - print_codec_list(s, media); - g_string_append_printf(s, "\r\n"); - /* add attributes and connection information */ handle_sdp_media_attributes(s, media, port, rtp_ps, rtp_ps_link, flags);