From 138ba8c178f99cc14275ac57a0020d8de8ccd4a9 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Wed, 8 May 2024 16:59:46 +0200 Subject: [PATCH] MT#56465 sdp_create(), set the actual sdp session name Always ensure to set the actual sdp session name when creating SDP using `sdp_create()`. A new dedicated func `sdp_out_add_session_name()` introduced for that. Additionally: fix auto-daemon-tests-websocket and auto-daemon-tests-pubsub accordingly. Change-Id: Ie62573149ef9ae226dc8c955dcb2cfaaa4d3ae87 --- daemon/call.c | 11 ++++++++- daemon/sdp.c | 38 ++++++++++++++++++++++++++++++-- include/call_interfaces.h | 1 + t/auto-daemon-tests-pubsub.pl | 22 +++++++++--------- t/auto-daemon-tests-redis.pl | 2 +- t/auto-daemon-tests-websocket.py | 10 ++++----- t/auto-daemon-tests.pl | 2 +- 7 files changed, 65 insertions(+), 21 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index a27bfc7dcf..46d1b309fe 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2638,8 +2638,9 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, sdp_ng_f ml->sdp_attributes = flags->session_attributes; t_queue_init(&flags->session_attributes); - /* consume sdp session origin parts (name, version etc.) */ + /* consume sdp session parts */ { + /* origin (name, version etc.) */ if (!ml->sdp_username && flags->session_sdp_orig.username.len) ml->sdp_username = call_strdup_len(call, flags->session_sdp_orig.username.s, flags->session_sdp_orig.username.len); @@ -2649,6 +2650,14 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, sdp_ng_f ml->sdp_version = flags->session_sdp_orig.version_num; if (ml->sdp_version == ULLONG_MAX) ml->sdp_version = (unsigned int)ssl_random(); + /* sdp session name */ + if (flags->session_sdp_name.len && + (!ml->sdp_session_name || /* if not set yet */ + (ml->sdp_session_name && !flags->replace_sess_name))) /* replace_sess_name = do not replace if possible*/ + { + ml->sdp_session_name = call_strdup_len(call, flags->session_sdp_name.s, + flags->session_sdp_name.len); + } } // reset offer ipv4/ipv6/mixed media stats diff --git a/daemon/sdp.c b/daemon/sdp.c index 074d30b657..795510a0ab 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1788,8 +1788,12 @@ int sdp_streams(const sdp_sessions_q *sessions, sdp_streams_q *streams, sdp_ng_f for (auto_iter(l, sessions->head); l; l = l->next) { session = l->data; + /* carry some of session level attributes for a later usage, using flags + * e.g. usage in `__call_monologue_init_from_flags()` + */ sdp_attr_append_other(&flags->session_attributes, &session->attributes); flags->session_sdp_orig = session->origin; + flags->session_sdp_name = session->session_name; for (__auto_type k = session->media_streams.head; k; k = k->next) { media = k->data; @@ -3403,7 +3407,34 @@ static void sdp_out_add_origin(GString *out, struct call_monologue *monologue, origin_address); } -int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags) { +static void sdp_out_add_session_name(GString *out, struct call_monologue *monologue, + enum call_opmode opmode) +{ + /* PUBLISH exceptionally doesn't include sdp session name from SDP. + * The session name and other values should be copied only from a source SDP, + * if that is also a media source. For a publish request that's not the case. */ + const char * sdp_session_name = rtpe_config.software_id; + + /* for the offer/answer model or subscribe don't use the given monologues SDP, + * but try the one of the subscription, because the given monologue itself + * has likely no session attributes set yet */ + struct media_subscription *ms = call_get_top_media_subscription(monologue); + if (ms && ms->monologue && ms->monologue->sdp_session_name) + sdp_session_name = ms->monologue->sdp_session_name; + + g_string_append_printf(out, "s=%s\r\n", sdp_session_name); +} + +/** + * For the offer/answer model, SDP create will be triggered for the B monologue, + * which likely has empty paramaters (such as sdp origin, session name etc.), hence + * such parameters have to be taken from the A monologue (so from the subscription). + * + * For the rest of cases (publish, subscribe, janus etc.) this works as usual: + * given monologue is a monologue which is being processed. + */ +int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags) +{ const char *err = NULL; GString *s = NULL; @@ -3427,7 +3458,10 @@ int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags) /* add origin including name and version */ sdp_out_add_origin(s, monologue, first_ps, flags); - g_string_append_printf(s, "s=%s\r\n", rtpe_config.software_id); + /* add an actual sdp session name */ + sdp_out_add_session_name(s, monologue, flags->opmode); + + /* set timing to always be: 0 0 */ g_string_append(s, "t=0 0\r\n"); monologue->sdp_attr_print(s, monologue, flags); diff --git a/include/call_interfaces.h b/include/call_interfaces.h index eef21b0588..7a9d679ca2 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -72,6 +72,7 @@ struct sdp_ng_flags { /* keep session level attributes for internal proper parsing */ sdp_attr_q session_attributes; // top-level (not part of an m= section) SDP session attributes struct sdp_origin session_sdp_orig; + str session_sdp_name; /* commands to manipulate attr lines in SDP */ struct sdp_manipulations * sdp_manipulations[__MT_MAX]; diff --git a/t/auto-daemon-tests-pubsub.pl b/t/auto-daemon-tests-pubsub.pl index 77ce371833..91a961d3c9 100755 --- a/t/auto-daemon-tests-pubsub.pl +++ b/t/auto-daemon-tests-pubsub.pl @@ -805,7 +805,7 @@ { flags => ['all', 'SIPREC'] }, < ['all', 'SIPREC'] }, < ['all'] }, < [ft(), tt()] }, < ['from-tags-' . ft(), 'from-tags-' . tt()] }, < [tt(), ft()] }, < ['all', 'SIPREC'] }, < ['all', 'SIPREC'], 'to-tag' => $ttr }, < ['all', 'SIPREC'], 'to-tag' => $ttr }, < ['all', 'SIPREC'], 'to-tag' => $ttr }, < [ $ftr, $fts ] }, < [ft(), tt()] }, < [qw/SIPREC all/]}, <