Browse Source

MT#60476 Move `call_subscribe_request_ng()` to `sdp_create()`

Move the `call_subscribe_request_ng()` fully to a usage
of the `sdp_create()` only.

Carry the origin IP and net family via flags
to the monologue, so can be reused later when creating SDP.

Always use given SDP session origin IP address and family
for the SDP being prepared, unless sdp origin replacement
is required via given flags (in this case just used
an advertised IP of rtpengine).

Additionally: fix unit tests for subscribe cases accordingly
to the policy.

Change-Id: Ib7697876ce45e01597edd27764d4147d12f738c8
rfuchs/gh1839
Donat Zenichev 1 year ago
parent
commit
e40af889d1
8 changed files with 51 additions and 56 deletions
  1. +15
    -0
      daemon/call.c
  2. +6
    -31
      daemon/call_interfaces.c
  3. +2
    -0
      daemon/janus.c
  4. +7
    -7
      daemon/sdp.c
  5. +6
    -3
      include/call.h
  6. +13
    -13
      t/auto-daemon-tests-pubsub.pl
  7. +1
    -1
      t/auto-daemon-tests-redis.pl
  8. +1
    -1
      t/auto-daemon-tests.pl

+ 15
- 0
daemon/call.c View File

@ -2630,11 +2630,26 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, sdp_ng_f
/* consume sdp session parts */ /* consume sdp session parts */
{ {
/* origin (name, version etc.) */ /* origin (name, version etc.) */
/* TODO: rework the whole SDP origin into one structure */
if (!ml->sdp_username && flags->session_sdp_orig.username.len) if (!ml->sdp_username && flags->session_sdp_orig.username.len)
{
ml->sdp_username = call_strdup_len(call, flags->session_sdp_orig.username.s, ml->sdp_username = call_strdup_len(call, flags->session_sdp_orig.username.s,
flags->session_sdp_orig.username.len); flags->session_sdp_orig.username.len);
}
if (!ml->sdp_session_id && flags->session_sdp_orig.session_id.len) if (!ml->sdp_session_id && flags->session_sdp_orig.session_id.len)
{
ml->sdp_session_id = str_to_ui(&flags->session_sdp_orig.session_id, 0); ml->sdp_session_id = str_to_ui(&flags->session_sdp_orig.session_id, 0);
}
if (!ml->sdp_origin_ip && flags->session_sdp_orig.address.address.len)
{
ml->sdp_origin_ip = call_strdup_len(call, flags->session_sdp_orig.address.address.s,
flags->session_sdp_orig.address.address.len);
}
if (!ml->sdp_origin_ip_family && flags->session_sdp_orig.address.address_type.len)
{
ml->sdp_origin_ip_family = call_strdup_len(call, flags->session_sdp_orig.address.address_type.s,
flags->session_sdp_orig.address.address_type.len);
}
ml->sdp_version = flags->session_sdp_orig.version_num; ml->sdp_version = flags->session_sdp_orig.version_num;
if (ml->sdp_version == ULLONG_MAX) if (ml->sdp_version == ULLONG_MAX)
ml->sdp_version = (unsigned int)ssl_random(); ml->sdp_version = (unsigned int)ssl_random();


+ 6
- 31
daemon/call_interfaces.c View File

@ -3728,17 +3728,6 @@ const char *call_subscribe_request_ng(bencode_item_t *input, bencode_item_t *out
if (!srms.length) if (!srms.length)
return "No call participants specified (no medias found)"; return "No call participants specified (no medias found)";
/* special case with just one source: we can use the original SDP
* TODO: deprecate it, since initially added for monologue subscriptions.
*/
struct call_monologue *sdp_ml = NULL;
if (srms.length == 1) {
struct media_subscription *ms = srms.head->data;
sdp_ml = ms->monologue;
if (!sdp_ml->last_in_sdp.len || !sdp_ml->last_in_sdp_parsed.length)
sdp_ml = NULL;
}
/* the `label=` option was possibly used above to select the from-tag -- /* the `label=` option was possibly used above to select the from-tag --
* switch it out with `to-label=` or `set-label=` for monologue_subscribe_request * switch it out with `to-label=` or `set-label=` for monologue_subscribe_request
* below which sets the label based on `label` for a newly created monologue */ * below which sets the label based on `label` for a newly created monologue */
@ -3752,34 +3741,20 @@ const char *call_subscribe_request_ng(bencode_item_t *input, bencode_item_t *out
flags.to_tag = STR_CONST_INIT(rand_buf); flags.to_tag = STR_CONST_INIT(rand_buf);
rand_hex_str(flags.to_tag.s, flags.to_tag.len / 2); rand_hex_str(flags.to_tag.s, flags.to_tag.len / 2);
} }
struct call_monologue *dest_ml = call_get_or_create_monologue(call, &flags.to_tag);
/* rewrite SDP, or create new? */
struct sdp_chopper *chopper = NULL;
if (sdp_ml) {
chopper = sdp_chopper_new(&sdp_ml->last_in_sdp);
bencode_buffer_destroy_add(output->buffer, (free_func_t) sdp_chopper_destroy, chopper);
}
struct call_monologue *dest_ml = call_get_or_create_monologue(call, &flags.to_tag);
int ret = monologue_subscribe_request(&srms, dest_ml, &flags); int ret = monologue_subscribe_request(&srms, dest_ml, &flags);
if (ret) if (ret)
return "Failed to request subscription"; return "Failed to request subscription";
if (chopper && sdp_ml) {
ret = sdp_replace(chopper, &sdp_ml->last_in_sdp_parsed, dest_ml, &flags);
if (ret)
return "Failed to rewrite SDP";
} else {
/* create new SDP */
ret = sdp_create(&sdp_out, dest_ml, &flags);
}
/* create new SDP */
ret = sdp_create(&sdp_out, dest_ml, &flags);
if (ret)
return "Failed to create SDP";
/* place return output SDP */ /* place return output SDP */
if (chopper) {
if (chopper->output->len)
bencode_dictionary_add_string_len(output, "sdp", chopper->output->str,
chopper->output->len);
} else if (sdp_out.len) {
if (sdp_out.len) {
bencode_buffer_destroy_add(output->buffer, g_free, sdp_out.s); bencode_buffer_destroy_add(output->buffer, g_free, sdp_out.s);
bencode_dictionary_add_str(output, "sdp", &sdp_out); bencode_dictionary_add_str(output, "sdp", &sdp_out);
sdp_out = STR_NULL; /* ownership passed to output */ sdp_out = STR_NULL; /* ownership passed to output */


+ 2
- 0
daemon/janus.c View File

@ -630,6 +630,7 @@ static const char *janus_videoroom_join(struct websocket_message *wm, struct jan
flags.generate_mid = 1; flags.generate_mid = 1;
flags.rtcp_mirror = 1; flags.rtcp_mirror = 1;
flags.replace_origin = 1;
if (!plain_offer) if (!plain_offer)
ng_flags_webrtc(&flags); ng_flags_webrtc(&flags);
@ -866,6 +867,7 @@ static const char *janus_videoroom_configure(struct websocket_message *wm, struc
// accept unsupported codecs if necessary // accept unsupported codecs if necessary
flags.accept_any = 1; flags.accept_any = 1;
flags.replace_origin = 1;
int ret = monologue_publish(ml, &streams, &flags); int ret = monologue_publish(ml, &streams, &flags);
if (ret) if (ret)


+ 7
- 7
daemon/sdp.c View File

@ -3413,14 +3413,14 @@ static void sdp_out_add_origin(GString *out, struct call_monologue *monologue,
if (ms && ms->monologue) { if (ms && ms->monologue) {
ml = ms->monologue; ml = ms->monologue;
if (flags->media_address.s && is_addr_unspecified(&flags->parsed_media_address))
__parse_address(&flags->parsed_media_address, NULL, NULL, &flags->media_address);
if (flags->session_sdp_orig.parsed &&
flags->replace_origin &&
flags->ice_option != ICE_FORCE_RELAY &&
!is_addr_unspecified(&flags->parsed_media_address))
/* by default set to what's parsed from SDP
* but only if a replacement of origin isn't requested */
if (!flags->replace_origin)
{ {
origin_address = sockaddr_print_buf(&flags->parsed_media_address);
if (ml->sdp_origin_ip)
origin_address = ml->sdp_origin_ip;
if (ml->sdp_origin_ip_family)
origin_address_type = ml->sdp_origin_ip_family;
} }
} }


+ 6
- 3
include/call.h View File

@ -604,14 +604,17 @@ struct call_monologue {
GHashTable *media_ids; GHashTable *media_ids;
struct media_player *player; struct media_player *player;
struct media_player *rec_player; struct media_player *rec_player;
unsigned long long sdp_session_id;
unsigned long long sdp_version;
/* TODO: cover all parts related to the SDP origin into one struct */
unsigned long long sdp_session_id; /* sdp origin session id */
unsigned long long sdp_version; /* sdp origin session ver */
int sdp_session_rr, sdp_session_rs; int sdp_session_rr, sdp_session_rs;
str last_in_sdp; str last_in_sdp;
sdp_sessions_q last_in_sdp_parsed; /* last parsed `sdp_session` */ sdp_sessions_q last_in_sdp_parsed; /* last parsed `sdp_session` */
sdp_streams_q last_in_sdp_streams; /* last parsed `stream_params` */ sdp_streams_q last_in_sdp_streams; /* last parsed `stream_params` */
GString *last_out_sdp; GString *last_out_sdp;
char *sdp_username;
char *sdp_username; /* sdp origin session name */
char *sdp_origin_ip; /* sdp origin ip */
char *sdp_origin_ip_family; /* sdp origin ip family */
char *sdp_session_name; char *sdp_session_name;
char *sdp_session_timing; char *sdp_session_timing;
struct ssrc_hash *ssrc_hash; struct ssrc_hash *ssrc_hash;


+ 13
- 13
t/auto-daemon-tests-pubsub.pl View File

@ -105,9 +105,9 @@ snd($sock_a, $port_b, rtp(0, 4000, 7000, 0x6543, "\x00" x 160));
rcv_no($sock_c); rcv_no($sock_c);
(undef, $ttr, undef, undef, undef, $port_c) = subscribe_request('SIPREC pause/resume', (undef, $ttr, undef, undef, undef, $port_c) = subscribe_request('SIPREC pause/resume',
{ 'from-tag' => ft(), flags => ['SIPREC'] }, <<SDP);
{ 'from-tag' => ft(), flags => ['SIPREC', 'replace-origin'] }, <<SDP);
v=0 v=0
o=- 1545997027 1 IN IP4 198.51.100.1
o=- 1545997027 1 IN IP4 203.0.113.1
s=tester s=tester
t=0 0 t=0 0
a=s-dummy a=s-dummy
@ -802,7 +802,7 @@ SDP
($ftr, $ttr, $fts, $tag_medias, $media_labels) = subscribe_request('SIPREC sub', ($ftr, $ttr, $fts, $tag_medias, $media_labels) = subscribe_request('SIPREC sub',
{ flags => ['all', 'SIPREC'] }, <<SDP);
{ flags => ['all', 'SIPREC', 'replace-origin'] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1 o=- SDP_VERSION IN IP4 203.0.113.1
s=tester s=tester
@ -912,7 +912,7 @@ SDP
($ftr, $ttr, $fts, $tag_medias, $media_labels) = subscribe_request('SIPREC sub', ($ftr, $ttr, $fts, $tag_medias, $media_labels) = subscribe_request('SIPREC sub',
{ flags => ['all', 'SIPREC'] }, <<SDP); { flags => ['all', 'SIPREC'] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.2
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 m=audio PORT RTP/AVP 0
@ -1033,7 +1033,7 @@ rcv($sock_b, $port_a, rtpm(0, 4000, 7000, 0x6543, "\x00" x 160));
($ftr, $ttr, $fts, undef, undef, $port_d, undef, $port_c) = subscribe_request('"all" sub', ($ftr, $ttr, $fts, undef, undef, $port_d, undef, $port_c) = subscribe_request('"all" sub',
{ 'flags' => ['all'] }, <<SDP); { 'flags' => ['all'] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 8 m=audio PORT RTP/AVP 0 8
@ -1166,7 +1166,7 @@ rcv($sock_b, $port_a, rtpm(0, 4000, 7000, 0x6543, "\x00" x 160));
($ftr, $ttr, $fts, undef, undef, $port_c, undef, $port_d) = subscribe_request('sub to multiple tags', ($ftr, $ttr, $fts, undef, undef, $port_c, undef, $port_d) = subscribe_request('sub to multiple tags',
{ 'from-tags' => [ft(), tt()] }, <<SDP); { 'from-tags' => [ft(), tt()] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 8 m=audio PORT RTP/AVP 0 8
@ -1272,7 +1272,7 @@ rcv($sock_b, $port_a, rtpm(0, 4000, 7000, 0x6543, "\x00" x 160));
($ftr, $ttr, $fts, undef, undef, $port_c, undef, $port_d) = subscribe_request('sub to multiple tags via flags', ($ftr, $ttr, $fts, undef, undef, $port_c, undef, $port_d) = subscribe_request('sub to multiple tags via flags',
{ flags => ['from-tags-' . ft(), 'from-tags-' . tt()] }, <<SDP); { flags => ['from-tags-' . ft(), 'from-tags-' . tt()] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 8 m=audio PORT RTP/AVP 0 8
@ -1372,7 +1372,7 @@ rcv($sock_b, $port_a, rtpm(0, 4000, 7000, 0x6543, "\x00" x 160));
($ftr, $ttr, $fts, undef, undef, $port_c, undef, $port_d) = subscribe_request('sub to multiple tags - reverse', ($ftr, $ttr, $fts, undef, undef, $port_c, undef, $port_d) = subscribe_request('sub to multiple tags - reverse',
{ 'from-tags' => [tt(), ft()] }, <<SDP); { 'from-tags' => [tt(), ft()] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 8 m=audio PORT RTP/AVP 0 8
@ -1703,7 +1703,7 @@ rcv($sock_b, $port_a, rtpm(0, 4000, 7000, 0x6543, "\x00" x 160));
(undef, $ttr, undef, undef, undef, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume', (undef, $ttr, undef, undef, undef, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume',
{ flags => ['all', 'SIPREC'] }, <<SDP); { flags => ['all', 'SIPREC'] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 m=audio PORT RTP/AVP 0
@ -1793,7 +1793,7 @@ SDP
(undef, undef, undef, $tag_medias, $media_labels, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume', (undef, undef, undef, $tag_medias, $media_labels, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume',
{ flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP); { flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 m=audio PORT RTP/AVP 0
@ -1914,7 +1914,7 @@ SDP
(undef, $ttr, undef, $tag_medias, $media_labels, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume', (undef, $ttr, undef, $tag_medias, $media_labels, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume',
{ flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP); { flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 m=audio PORT RTP/AVP 0
@ -2039,7 +2039,7 @@ SDP
(undef, undef, undef, $tag_medias, $media_labels, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume', (undef, undef, undef, $tag_medias, $media_labels, $port_d, undef, $port_c) = subscribe_request('SIPREC sub pause/resume',
{ flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP); { flags => ['all', 'SIPREC'], 'to-tag' => $ttr }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 m=audio PORT RTP/AVP 0
@ -3590,7 +3590,7 @@ $fts = ft();
subscribe_request('multi publish/subscribe', subscribe_request('multi publish/subscribe',
{ 'from-tags' => [ $ftr, $fts ] }, <<SDP); { 'from-tags' => [ $ftr, $fts ] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 m=audio PORT RTP/AVP 0


+ 1
- 1
t/auto-daemon-tests-redis.pl View File

@ -1571,7 +1571,7 @@ $json_exp = {
my ($ftr, $ttr, $fts) = subscribe_request('sub to multiple tags', my ($ftr, $ttr, $fts) = subscribe_request('sub to multiple tags',
{ 'from-tags' => [ft(), tt()] }, <<SDP); { 'from-tags' => [ft(), tt()] }, <<SDP);
v=0 v=0
o=- SDP_VERSION IN IP4 203.0.113.1
o=- SDP_VERSION IN IP4 198.51.100.1
s=tester s=tester
t=0 0 t=0 0
m=audio PORT RTP/AVP 0 8 m=audio PORT RTP/AVP 0 8


+ 1
- 1
t/auto-daemon-tests.pl View File

@ -1554,7 +1554,7 @@ SDP
subscribe_request('AMR asymmetric', {flags => [qw/SIPREC all/]}, <<SDP); subscribe_request('AMR asymmetric', {flags => [qw/SIPREC all/]}, <<SDP);
v=0 v=0
o=ccs-0-615-7 SDP_VERSION IN IP4 203.0.113.1
o=ccs-0-615-7 SDP_VERSION IN IP4 10.104.1.81
s=- s=-
t=0 0 t=0 0
m=audio PORT RTP/AVP 96 98 m=audio PORT RTP/AVP 96 98


Loading…
Cancel
Save