From a1efdf6b20f52312e2db8eabfd7f5f7b87d6a461 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 5 Dec 2018 10:46:00 -0500 Subject: [PATCH] TT#45472 support generating a=mid lines if not present closes #641 Change-Id: I849f0c73c5fdd575417a37a41d6701ea4454374b --- README.md | 4 ++++ daemon/call.c | 26 +++++++++++++++++--------- daemon/call_interfaces.c | 2 ++ include/call_interfaces.h | 1 + utils/rtpengine-ng-client | 3 ++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d8db1b2b5..332473743 100644 --- a/README.md +++ b/README.md @@ -1247,6 +1247,10 @@ Optionally included keys are: `=` characters used for padding should be omitted. With this flag set, these padding characters will be left in place. + - `generate mid` + + Add `a=mid` attributes to the outgoing SDP if they were not already present. + * `replace` Similar to the `flags` list. Controls which parts of the SDP body should be rewritten. diff --git a/daemon/call.c b/daemon/call.c index df3e4712d..0811222db 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1674,15 +1674,23 @@ static void __update_media_id(struct call_media *media, struct call_media *other { struct call *call = media->call; - if (!other_media->media_id.s) { - // incoming side: we copy what we received - if (sp->media_id.s) - call_str_cpy(call, &other_media->media_id, &sp->media_id); - } - if (!media->media_id.s) { - // outgoing side: we copy from the other side - if (other_media->media_id.s) - call_str_cpy(call, &media->media_id, &other_media->media_id); + if (flags && flags->opmode == OP_OFFER) { + if (!other_media->media_id.s) { + // incoming side: we copy what we received + if (sp->media_id.s) + call_str_cpy(call, &other_media->media_id, &sp->media_id); + } + if (!media->media_id.s) { + // outgoing side: we copy from the other side + if (other_media->media_id.s) + call_str_cpy(call, &media->media_id, &other_media->media_id); + else if (flags->generate_mid) { + // or generate one + char buf[64]; + snprintf(buf, sizeof(buf), "%u", other_media->index); + call_str_cpy_c(call, &media->media_id, buf); + } + } } } diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 9cf023b65..da2fde0ed 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -611,6 +611,8 @@ static void call_ng_flags_flags(struct sdp_ng_flags *out, str *s, void *dummy) { out->all = 1; else if (!str_cmp(s, "port-latching")) out->port_latching = 1; + else if (!str_cmp(s, "generate-mid")) + out->generate_mid = 1; else if (!str_cmp(s, "record-call")) out->record_call = 1; else if (!str_cmp(s, "no-rtcp-attribute")) diff --git a/include/call_interfaces.h b/include/call_interfaces.h index e87318a4b..b39a6e012 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -53,6 +53,7 @@ struct sdp_ng_flags { rtcp_mux_accept:1, rtcp_mux_reject:1, no_rtcp_attr:1, + generate_mid:1, strict_source:1, media_handover:1, dtls_passive:1, diff --git a/utils/rtpengine-ng-client b/utils/rtpengine-ng-client index 92d191528..f5dfb7f48 100755 --- a/utils/rtpengine-ng-client +++ b/utils/rtpengine-ng-client @@ -61,6 +61,7 @@ GetOptions( 'all' => \$options{'all'}, 'address=s' => \$options{'address'}, 'pad-crypto' => \$options{'pad crypto'}, + 'generate-mid' => \$options{'generate mid'}, ) or die; my $cmd = shift(@ARGV) or die; @@ -73,7 +74,7 @@ for my $x (split(/,/, 'from-tag,to-tag,call-id,transport protocol,media address, for my $x (split(/,/, 'TOS,delete-delay')) { defined($options{$x}) and $packet{$x} = $options{$x}; } -for my $x (split(/,/, 'trust address,symmetric,asymmetric,force,strict source,media handover,sip source address,reset,port latching,no rtcp attribute,loop protect,record call,always transcode,all,pad crypto')) { +for my $x (split(/,/, 'trust address,symmetric,asymmetric,force,strict source,media handover,sip source address,reset,port latching,no rtcp attribute,loop protect,record call,always transcode,all,pad crypto,generate mid')) { defined($options{$x}) and push(@{$packet{flags}}, $x); } for my $x (split(/,/, 'origin,session connection')) {