Skip to content

Commit 52b19f4

Browse files
committed
MT#55283 decouple SDP origin settings
Move o= replacement logic into sdp_out_add_origin. Copy fields from input source ML if present, or keep unchanged. Generate if not present. Change-Id: Ieea5abea05bf076262248639118e9e9192f77e1c
1 parent e948e5a commit 52b19f4

5 files changed

Lines changed: 117 additions & 112 deletions

File tree

daemon/redis.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,6 @@ static int redis_tags(call_t *c, struct redis_list *tags, parser_arg arg) {
15891589
ml->sdp_orig_in.username = call_str_cpy(&s);
15901590
if (!redis_hash_get_str(&s, rh, "sdp_orig_session_id"))
15911591
ml->sdp_orig_in.session_id = call_str_cpy(&s);
1592-
if (!redis_hash_get_str(&s, rh, "sdp_orig_version_str"))
1593-
ml->sdp_orig_in.version_str = call_str_cpy(&s);
15941592
if (!redis_hash_get_str(&s, rh, "sdp_orig_address_network_type"))
15951593
ml->sdp_orig_in.address.network_type = call_str_cpy(&s);
15961594
if (!redis_hash_get_str(&s, rh, "sdp_orig_address_address_type"))
@@ -1606,8 +1604,6 @@ static int redis_tags(call_t *c, struct redis_list *tags, parser_arg arg) {
16061604
ml->sdp_orig_out.username = call_str_cpy(&s);
16071605
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_session_id"))
16081606
ml->sdp_orig_out.session_id = call_str_cpy(&s);
1609-
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_version_str"))
1610-
ml->sdp_orig_out.version_str = call_str_cpy(&s);
16111607
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_address_network_type"))
16121608
ml->sdp_orig_out.address.network_type = call_str_cpy(&s);
16131609
if (!redis_hash_get_str(&s, rh, "last_sdp_orig_address_address_type"))
@@ -2652,7 +2648,6 @@ static str redis_encode_json(ng_parser_ctx_t *ctx, call_t *c, void **to_free) {
26522648
if (ml->sdp_orig_in.parsed) {
26532649
JSON_SET_SIMPLE_STR("sdp_orig_username", &ml->sdp_orig_in.username);
26542650
JSON_SET_SIMPLE_STR("sdp_orig_session_id", &ml->sdp_orig_in.session_id);
2655-
JSON_SET_SIMPLE_STR("sdp_orig_version_str", &ml->sdp_orig_in.version_str);
26562651
JSON_SET_SIMPLE("sdp_orig_version_num", "%llu", ml->sdp_orig_in.version_num);
26572652
JSON_SET_SIMPLE("sdp_orig_parsed", "%u", ml->sdp_orig_in.parsed);
26582653
JSON_SET_SIMPLE_STR("sdp_orig_address_network_type", &ml->sdp_orig_in.address.network_type);
@@ -2662,7 +2657,6 @@ static str redis_encode_json(ng_parser_ctx_t *ctx, call_t *c, void **to_free) {
26622657
if (ml->sdp_orig_out.parsed) {
26632658
JSON_SET_SIMPLE_STR("last_sdp_orig_username", &ml->sdp_orig_out.username);
26642659
JSON_SET_SIMPLE_STR("last_sdp_orig_session_id", &ml->sdp_orig_out.session_id);
2665-
JSON_SET_SIMPLE_STR("last_sdp_orig_version_str", &ml->sdp_orig_out.version_str);
26662660
JSON_SET_SIMPLE("last_sdp_orig_version_num", "%llu", ml->sdp_orig_out.version_num);
26672661
JSON_SET_SIMPLE("last_sdp_orig_parsed", "%u", ml->sdp_orig_out.parsed);
26682662
JSON_SET_SIMPLE_STR("last_sdp_orig_address_network_type", &ml->sdp_orig_out.address.network_type);

daemon/sdp.c

Lines changed: 83 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,6 @@ sdp_origin sdp_orig_dup(const sdp_origin *orig) {
19051905
sdp_origin copy = {};
19061906
copy.username = call_str_cpy(&orig->username);
19071907
copy.session_id = call_str_cpy(&orig->session_id);
1908-
copy.version_str = call_str_cpy(&orig->version_str);
19091908
copy.version_num = orig->version_num;
19101909
copy.version_output_pos = orig->version_output_pos;
19111910
copy.parsed = orig->parsed;
@@ -2706,70 +2705,48 @@ static void insert_rtcp_attr(GString *s, struct packet_stream *ps, const sdp_ng_
27062705
/**
27072706
* Handle sdp version replacements.
27082707
*/
2709-
static void sdp_version_replace(GString *s, sdp_origin *src_orig, sdp_origin *other_orig)
2708+
static void sdp_version_increase(GString *s, sdp_origin *origin)
27102709
{
27112710
char version_str[64];
2712-
snprintf(version_str, sizeof(version_str), "%llu", src_orig->version_num);
2713-
size_t version_len = strlen(version_str);
2711+
snprintf(version_str, sizeof(version_str), "%llu", origin->version_num);
2712+
size_t old_version_len = strlen(version_str);
27142713

2715-
if (!other_orig)
2716-
return;
2714+
origin->version_num++;
2715+
2716+
snprintf(version_str, sizeof(version_str), "%llu", origin->version_num);
2717+
size_t version_len = strlen(version_str);
27172718

2718-
other_orig->version_num = src_orig->version_num;
27192719
/* is our new value longer? */
2720-
if (version_len > other_orig->version_str.len) {
2720+
if (version_len > old_version_len) {
27212721
/* overwrite + insert */
2722-
g_string_overwrite_len(s, other_orig->version_output_pos, version_str, other_orig->version_str.len);
2723-
g_string_insert(s, other_orig->version_output_pos + other_orig->version_str.len, version_str + other_orig->version_str.len);
2724-
other_orig->version_str.len = version_len;
2722+
g_string_overwrite_len(s, origin->version_output_pos, version_str, old_version_len);
2723+
g_string_insert(s, origin->version_output_pos + old_version_len, version_str + old_version_len);
27252724
}
27262725
else {
27272726
/* overwrite + optional erase */
2728-
g_string_overwrite(s, other_orig->version_output_pos, version_str);
2729-
if (version_len < other_orig->version_str.len) {
2730-
g_string_erase(s, other_orig->version_output_pos + version_len, other_orig->version_str.len - version_len);
2731-
other_orig->version_str.len = version_len;
2727+
g_string_overwrite(s, origin->version_output_pos, version_str);
2728+
if (version_len < old_version_len) {
2729+
g_string_erase(s, origin->version_output_pos + version_len, old_version_len - version_len);
27322730
}
27332731
}
27342732
}
27352733

27362734
/**
27372735
* SDP session version manipulations.
27382736
*/
2739-
static void sdp_version_check(GString *s, struct call_monologue *monologue,
2740-
struct call_monologue *source_ml,
2741-
bool force_increase)
2742-
{
2737+
static void sdp_version_check(GString *s, struct call_monologue *monologue) {
27432738
if (!monologue->sdp_orig_out.parsed)
27442739
return;
27452740

27462741
sdp_origin *origin = &monologue->sdp_orig_out;
2747-
sdp_origin *other_origin = NULL;
2748-
2749-
if (source_ml && source_ml->sdp_orig_in.parsed)
2750-
other_origin = &source_ml->sdp_orig_in;
2751-
2752-
/* We really expect only a single session here, but we treat all the same regardless,
2753-
* and use the same version number on all of them */
2754-
2755-
/* First update all versions to match our single version */
2756-
sdp_version_replace(s, origin, other_origin);
2757-
2758-
/* Now check if we need to change the version actually.
2759-
* The version change will be forced with the 'force_increase',
2760-
* and it gets incremented, regardless whether:
2761-
* - we have no previously stored SDP,
2762-
* - we have previous SDP and it's equal to the current one */
2763-
if (!force_increase) {
2764-
if (!monologue->last_out_sdp)
2765-
goto dup;
2766-
if (g_string_equal(monologue->last_out_sdp, s))
2767-
return;
2768-
}
2742+
2743+
if (!monologue->last_out_sdp)
2744+
goto dup;
2745+
if (g_string_equal(monologue->last_out_sdp, s))
2746+
return;
27692747

27702748
/* mismatch detected. increment version, update again, and store copy */
2771-
origin->version_num++;
2772-
sdp_version_replace(s, origin, other_origin);
2749+
sdp_version_increase(s, origin);
27732750
if (monologue->last_out_sdp)
27742751
g_string_free(monologue->last_out_sdp, TRUE);
27752752
dup:
@@ -3006,56 +2983,81 @@ static void sdp_out_add_origin(GString *out, struct call_monologue *monologue,
30062983
struct call_monologue *source_ml,
30072984
struct packet_stream *first_ps, sdp_ng_flags *flags)
30082985
{
3009-
__auto_type ml = source_ml;
3010-
if (!ml)
3011-
ml = monologue;
3012-
3013-
/* orig username
3014-
* session_last_sdp_orig is stored on the other media always,
3015-
* so if origin is meant for the A media, then it is stored on the B one */
3016-
str * orig_username = (monologue->sdp_orig_out.parsed &&
3017-
(flags->replace_username || flags->replace_origin_full)) ?
3018-
&monologue->sdp_orig_out.username : &ml->sdp_orig_in.username;
3019-
3020-
/* orig session id */
3021-
str * orig_session_id = (monologue->sdp_orig_out.parsed && flags->replace_origin_full) ?
3022-
&monologue->sdp_orig_out.session_id : &ml->sdp_orig_in.session_id;
3023-
3024-
/* orig session ver
3025-
* replacement is handled later in sdp_create() based on SDP changes */
3026-
unsigned long long orig_session_version = ml->sdp_orig_in.version_num;
2986+
/* origin username */
2987+
str username = STR_NULL;
2988+
if (source_ml && !(flags->replace_username || flags->replace_origin_full))
2989+
username = source_ml->sdp_orig_in.username;
2990+
if (!username.len && monologue->sdp_orig_out.parsed)
2991+
username = monologue->sdp_orig_out.username;
2992+
if (!username.len && source_ml)
2993+
username = source_ml->sdp_orig_in.username;
2994+
if (!username.len)
2995+
username = STR("-");
2996+
2997+
/* origin session id */
2998+
str session_id = STR_NULL;
2999+
char id_buf[64];
3000+
if (source_ml && !flags->replace_origin_full)
3001+
session_id = source_ml->sdp_orig_in.session_id;
3002+
if (!session_id.len && monologue->sdp_orig_out.parsed)
3003+
session_id = monologue->sdp_orig_out.session_id;
3004+
if (!session_id.len && source_ml)
3005+
session_id = source_ml->sdp_orig_in.session_id;
3006+
if (!session_id.len) {
3007+
snprintf(id_buf, sizeof(id_buf), "%" PRId64, (rtpe_now & 0xfffffffL) + 1);
3008+
session_id = STR(id_buf);
3009+
}
3010+
3011+
/* origin session ver */
3012+
unsigned long long session_version;
3013+
if (monologue->sdp_orig_out.parsed && flags->force_inc_sdp_ver)
3014+
session_version = monologue->sdp_orig_out.version_num + 1;
3015+
else if (monologue->sdp_orig_out.parsed
3016+
&& (flags->replace_sdp_version || flags->replace_origin_full))
3017+
session_version = monologue->sdp_orig_out.version_num;
3018+
else if (source_ml)
3019+
session_version = source_ml->sdp_orig_in.version_num;
3020+
else if (monologue->sdp_orig_out.parsed)
3021+
session_version = monologue->sdp_orig_out.version_num;
3022+
else
3023+
session_version = (ssl_random() & 0xfffffffL) + 1;
3024+
30273025
/* record origin version position for replacements
30283026
* + 4 - means: `o=` + 2 spaces between username and version / version and id */
3029-
ml->sdp_orig_in.version_output_pos = out->len + orig_username->len + orig_session_id->len + 4;
3027+
size_t version_output_pos = out->len + username.len + session_id.len + 4;
30303028

30313029
/* orig IP family and address */
30323030
str orig_address_type;
30333031
str orig_address;
3034-
if (!source_ml || flags->replace_origin || flags->replace_origin_full) {
3035-
/* replacing flags or PUBLISH */
3032+
if (source_ml && !(flags->replace_origin || flags->replace_origin_full)) {
3033+
orig_address_type = source_ml->sdp_orig_in.address.address_type;
3034+
orig_address = source_ml->sdp_orig_in.address.address;
3035+
}
3036+
else if (monologue->sdp_orig_out.parsed) {
3037+
orig_address_type = monologue->sdp_orig_out.address.address_type;
3038+
orig_address = monologue->sdp_orig_out.address.address;
3039+
}
3040+
else {
30363041
orig_address_type = STR(first_ps->selected_sfd->local_intf->advertised_address.addr.family->rfc_name);
30373042
orig_address = STR(sockaddr_print_buf(&first_ps->selected_sfd->local_intf->advertised_address.addr));
3038-
} else {
3039-
orig_address_type = ml->sdp_orig_in.address.address_type;
3040-
orig_address = ml->sdp_orig_in.address.address;
30413043
}
30423044

3043-
if (!monologue->sdp_orig_out.parsed)
3044-
monologue->sdp_orig_out = sdp_orig_dup(&(sdp_origin) {
3045-
.username = *orig_username,
3046-
.session_id = *orig_session_id,
3047-
.version_num = orig_session_version,
3048-
.address.address_type = orig_address_type,
3049-
.address.address = orig_address,
3050-
.parsed = 1,
3051-
});
3045+
monologue->sdp_orig_out = sdp_orig_dup(&(sdp_origin) {
3046+
.username = username,
3047+
.session_id = session_id,
3048+
.version_num = session_version,
3049+
.address.address_type = orig_address_type,
3050+
.address.address = orig_address,
3051+
.version_output_pos = version_output_pos,
3052+
.parsed = 1,
3053+
});
30523054

30533055
/* print it to the output sdp */
30543056
g_string_append_printf(out,
30553057
"o="STR_FORMAT" "STR_FORMAT" %llu IN "STR_FORMAT" "STR_FORMAT"\r\n",
3056-
STR_FMT(orig_username),
3057-
STR_FMT(orig_session_id),
3058-
orig_session_version,
3058+
STR_FMT(&username),
3059+
STR_FMT(&session_id),
3060+
session_version,
30593061
STR_FMT(&orig_address_type),
30603062
STR_FMT(&orig_address));
30613063
}
@@ -3551,13 +3553,8 @@ bool sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags)
35513553
sdp_manipulations_add(s, sdp_manipulations);
35523554
}
35533555

3554-
/* The SDP version gets increased in case:
3555-
* - if replace_sdp_version (sdp-version) or replace_origin_full flag is set and SDP information has been updated, or
3556-
* - if the force_inc_sdp_ver (force-increment-sdp-ver) flag is set additionally to replace_sdp_version,
3557-
* which forces version increase regardless changes in the SDP information.
3558-
*/
3559-
if (flags->force_inc_sdp_ver || flags->replace_sdp_version || flags->replace_origin_full)
3560-
sdp_version_check(s, monologue, source_ml, !!flags->force_inc_sdp_ver);
3556+
if (flags->replace_sdp_version || flags->replace_origin_full)
3557+
sdp_version_check(s, monologue);
35613558

35623559
out->len = s->len;
35633560
out->s = g_string_free(s, FALSE);

t/auto-daemon-tests-config-file.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
m=audio 6000 RTP/AVP 0 8
120120
----------------------------------
121121
v=0
122-
o=- 1545997027 1 IN IP4 203.0.113.6
122+
o=- SDP_VERSION IN IP4 203.0.113.6
123123
s=RTPE_VERSION
124124
t=0 0
125125
m=audio PORT RTP/AVP 0
@@ -147,7 +147,7 @@
147147
m=audio 6000 RTP/AVP 0 8
148148
----------------------------------
149149
v=0
150-
o=- 1545997027 1 IN IP4 203.0.113.6
150+
o=- SDP_VERSION IN IP4 203.0.113.6
151151
s=RTPE_VERSION
152152
t=0 0
153153
m=audio PORT RTP/AVP 0
@@ -176,7 +176,7 @@
176176
m=audio 6000 RTP/AVP 0 8
177177
----------------------------------
178178
v=0
179-
o=- 1545997027 1 IN IP4 203.0.113.6
179+
o=- SDP_VERSION IN IP4 203.0.113.6
180180
s=RTPE_VERSION
181181
t=0 0
182182
m=audio PORT RTP/AVP 0
@@ -206,7 +206,7 @@
206206
m=audio 6000 RTP/AVP 0 8
207207
----------------------------------
208208
v=0
209-
o=- 1545997027 1 IN IP4 203.0.113.6
209+
o=- SDP_VERSION IN IP4 203.0.113.6
210210
s=RTPE_VERSION
211211
t=0 0
212212
m=audio PORT RTP/AVP 0

t/auto-daemon-tests-sdp-orig-replacements.pl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137

138138
new_call;
139139

140-
# there is no 'monologue->last_out_sdp', but the version still gets increased
141140
offer('SDP version force increase', { replace => ['force-increment-sdp-ver'] }, <<SDP);
142141
v=0
143142
o=- 1545997027 1 IN IP4 198.51.100.1
@@ -147,7 +146,7 @@
147146
c=IN IP4 198.51.100.1
148147
----------------------------
149148
v=0
150-
o=- 1545997027 2 IN IP4 198.51.100.1
149+
o=- 1545997027 1 IN IP4 198.51.100.1
151150
s=tester
152151
t=0 0
153152
m=audio PORT RTP/AVP 0
@@ -157,8 +156,6 @@
157156
a=rtcp:PORT
158157
SDP
159158

160-
# there is 'monologue->last_out_sdp' and it's equal to the newly given SDP,
161-
# but the version still gets increased
162159
offer('SDP version force increase', { replace => ['force-increment-sdp-ver'] }, <<SDP);
163160
v=0
164161
o=- 1545997027 2 IN IP4 198.51.100.1
@@ -168,6 +165,25 @@
168165
c=IN IP4 198.51.100.1
169166
----------------------------
170167
v=0
168+
o=- 1545997027 2 IN IP4 198.51.100.1
169+
s=tester
170+
t=0 0
171+
m=audio PORT RTP/AVP 0
172+
c=IN IP4 203.0.113.1
173+
a=rtpmap:0 PCMU/8000
174+
a=sendrecv
175+
a=rtcp:PORT
176+
SDP
177+
178+
offer('SDP version force increase', { replace => ['force-increment-sdp-ver'] }, <<SDP);
179+
v=0
180+
o=- 1545997027 3 IN IP4 198.51.100.1
181+
s=tester
182+
t=0 0
183+
m=audio 2002 RTP/AVP 0
184+
c=IN IP4 198.51.100.1
185+
----------------------------
186+
v=0
171187
o=- 1545997027 3 IN IP4 198.51.100.1
172188
s=tester
173189
t=0 0
@@ -178,8 +194,6 @@
178194
a=rtcp:PORT
179195
SDP
180196

181-
# there is 'monologue->last_out_sdp' and it's not equal to the newly given SDP,
182-
# and the version gets increased, as if that would be increased with 'sdp-version'.
183197
offer('SDP version force increase', { replace => ['force-increment-sdp-ver'] }, <<SDP);
184198
v=0
185199
o=- 1545997027 3 IN IP4 198.51.100.1

0 commit comments

Comments
 (0)