Skip to content

Commit

Permalink
MT#56465 sdp_create(), set the actual sdp session name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zenichev committed May 23, 2024
1 parent 4dfd949 commit 138ba8c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
11 changes: 10 additions & 1 deletion daemon/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
38 changes: 36 additions & 2 deletions daemon/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/call_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
22 changes: 11 additions & 11 deletions t/auto-daemon-tests-pubsub.pl
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@
{ flags => ['all', 'SIPREC'] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -913,7 +913,7 @@
{ flags => ['all', 'SIPREC'] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1034,7 +1034,7 @@
{ 'flags' => ['all'] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1167,7 +1167,7 @@
{ 'from-tags' => [ft(), tt()] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1273,7 +1273,7 @@
{ flags => ['from-tags-' . ft(), 'from-tags-' . tt()] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1373,7 +1373,7 @@
{ 'from-tags' => [tt(), ft()] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1704,7 +1704,7 @@
{ flags => ['all', 'SIPREC'] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1794,7 +1794,7 @@
{ flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -1915,7 +1915,7 @@
{ flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -2040,7 +2040,7 @@
{ flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down Expand Up @@ -3591,7 +3591,7 @@
{ 'from-tags' => [ $ftr, $fts ] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
Expand Down
2 changes: 1 addition & 1 deletion t/auto-daemon-tests-redis.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ sub redis_io {
{ 'from-tags' => [ft(), tt()] }, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
Expand Down
10 changes: 5 additions & 5 deletions t/auto-daemon-tests-websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def testVideoroomWebRTC(self):
re.compile(
"^v=0\r\n"
"o=- \d+ \d+ IN IP4 203.0.113.1\r\n"
"s=rtpengine.*?\r\n"
"s=foobar\r\n"
"t=0 0\r\n"
"m=audio \d+ UDP/TLS/RTP/SAVPF 8\r\n"
"c=IN IP4 203.0.113.1\r\n"
Expand Down Expand Up @@ -902,7 +902,7 @@ def testVideoroomWebRTCAlt(self):
re.compile(
"^v=0\r\n"
"o=- \d+ \d+ IN IP4 203.0.113.1\r\n"
"s=rtpengine.*?\r\n"
"s=foobar\r\n"
"t=0 0\r\n"
"m=audio \d+ UDP/TLS/RTP/SAVPF 8\r\n"
"c=IN IP4 203.0.113.1\r\n"
Expand Down Expand Up @@ -1753,7 +1753,7 @@ def testVideoroomWebRTCVideo(self):
re.compile(
"^v=0\r\n"
"o=- \d+ \d+ IN IP4 203.0.113.1\r\n"
"s=rtpengine.*?\r\n"
"s=-\r\n"
"t=0 0\r\n"
"a=extmap-allow-mixed\r\n"
"a=msid-semantic: WMS hJifdaJwqEqHxSG0pVbs1DrLAwiHqz7fKlqC\r\n"
Expand Down Expand Up @@ -2020,7 +2020,7 @@ def testVideoroomICE(self):
re.compile(
"^v=0\r\n"
"o=- \d+ \d+ IN IP4 203.0.113.1\r\n"
"s=rtpengine.*?\r\n"
"s=foobar\r\n"
"t=0 0\r\n"
"m=audio \d+ UDP/TLS/RTP/SAVPF 8\r\n"
"c=IN IP4 203.0.113.1\r\n"
Expand Down Expand Up @@ -3153,7 +3153,7 @@ def testVideoroomMute(self):
match_re = re.compile(
"^v=0\r\n"
"o=- \d+ \d+ IN IP4 203.0.113.1\r\n"
"s=rtpengine.*?\r\n"
"s=foobar\r\n"
"t=0 0\r\n"
"m=audio (\d+) RTP/AVP 96\r\n"
"c=IN IP4 203.0.113.1\r\n"
Expand Down
2 changes: 1 addition & 1 deletion t/auto-daemon-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ sub stun_succ {
subscribe_request('AMR asymmetric', {flags => [qw/SIPREC all/]}, <<SDP);
v=0
o=- SDP_VERSION IN IP4 203.0.113.1
s=RTPE_VERSION
s=-
t=0 0
m=audio PORT RTP/AVP 96 98
c=IN IP4 203.0.113.1
Expand Down

0 comments on commit 138ba8c

Please sign in to comment.