From 3c50130c7bfb214bfa45eb44eebf917784e37c96 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 5 Dec 2018 08:43:13 -0500 Subject: [PATCH] TT#45472 process and retain media ID strings (a=mid) Change-Id: Icf7219f407ed660c009ffde838c942e13aad40ce --- daemon/call.c | 18 ++++++++++++++++++ daemon/sdp.c | 23 +++++++++++++---------- include/call.h | 2 ++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index ee92a2d54..df3e4712d 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1669,6 +1669,23 @@ static void __endpoint_loop_protect(struct stream_params *sp, struct call_media MEDIA_SET(media, LOOP_CHECK); } +static void __update_media_id(struct call_media *media, struct call_media *other_media, + struct stream_params *sp, const struct sdp_ng_flags *flags) +{ + 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); + } +} + /* called with call->master_lock held in W */ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, const struct sdp_ng_flags *flags) @@ -1741,6 +1758,7 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, && other_media->protocol && other_media->protocol->rtp) media->protocol = flags->transport_protocol; + __update_media_id(media, other_media, sp, flags); __endpoint_loop_protect(sp, other_media); if (sp->rtp_endpoint.port) { diff --git a/daemon/sdp.c b/daemon/sdp.c index 3d68682b1..43a0c4a59 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -169,7 +169,7 @@ struct attribute_fmtp { unsigned int payload_type; }; -struct sdp_attribute { +struct sdp_attribute { /* example: a=rtpmap:8 PCMA/8000 */ str full_line, /* including a= and \r\n */ line_value, /* without a= and without \r\n */ name, /* just "rtpmap" */ @@ -1323,6 +1323,11 @@ int sdp_streams(const GQueue *sessions, GQueue *streams, struct sdp_ng_flags *fl sp->fingerprint.hash_func->num_bytes); } + // a=mid + attr = attr_get_by_id(&media->attributes, ATTR_MID); + if (attr) + sp->media_id = attr->value; + __sdp_ice(sp, media); /* determine RTCP endpoint */ @@ -1697,6 +1702,7 @@ static int process_media_attributes(struct sdp_chopper *chop, struct sdp_media * case ATTR_SENDRECV: case ATTR_IGNORE: case ATTR_END_OF_CANDIDATES: // we strip it here and re-insert it later + case ATTR_MID: goto strip; case ATTR_RTPMAP: @@ -1714,15 +1720,6 @@ static int process_media_attributes(struct sdp_chopper *chop, struct sdp_media * break; goto strip; - case ATTR_MID: - if (MEDIA_ISSET(media, PASSTHRU)) - break; -// a = attr_get_by_id(&sdp->session->attributes, ATTR_GROUP); -// if (a && a->u.group.semantics == GROUP_BUNDLE) -// goto strip; - goto strip; // hack/workaround: always remove a=mid - break; - default: break; } @@ -2063,6 +2060,12 @@ int sdp_replace(struct sdp_chopper *chop, GQueue *sessions, struct call_monologu copy_up_to_end_of(chop, &sdp_media->s); + if (call_media->media_id.s) { + chopper_append_c(chop, "a=mid:"); + chopper_append_str(chop, &call_media->media_id); + chopper_append_c(chop, "\r\n"); + } + insert_codec_parameters(chop, call_media); ps_rtcp = NULL; diff --git a/include/call.h b/include/call.h index 5db4a16b4..17797b7d0 100644 --- a/include/call.h +++ b/include/call.h @@ -242,6 +242,7 @@ struct stream_params { str ice_ufrag; str ice_pwd; int ptime; + str media_id; }; struct endpoint_map { @@ -320,6 +321,7 @@ struct call_media { struct ice_agent *ice_agent; + str media_id; GQueue sdes_in, sdes_out; struct dtls_fingerprint fingerprint; /* as received */