<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9377">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_confbridge: Use the SDP 'label' attribute to correlate users<br><br>Previously, the msid "label" attribute was used to correlate<br>participant info but because streams could be reused, the msid<br>wasn't being updated correctly when someone left the bridge and<br>another joined.<br><br>Now, instead of looking for the msid attribute on a channel's streams,<br>app_confbridge sets an "SDP:LABEL" attribute on the stream which<br>res_pjsip_sdp_rtp looks for. If it finds it, it adds a "label"<br>attribute to the current sdp.<br><br>Change-Id: I6cbaa87fb59a2e0688d956e72d2d09e4ac20d5a5<br>---<br>M apps/confbridge/confbridge_manager.c<br>M res/res_pjsip_sdp_rtp.c<br>2 files changed, 18 insertions(+), 43 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/77/9377/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/confbridge/confbridge_manager.c b/apps/confbridge/confbridge_manager.c</span><br><span>index a101530..51112ba 100644</span><br><span>--- a/apps/confbridge/confbridge_manager.c</span><br><span>+++ b/apps/confbridge/confbridge_manager.c</span><br><span>@@ -388,34 +388,18 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct ast_json *get_media_labels(struct confbridge_conference *conference,</span><br><span style="color: hsl(120, 100%, 40%);">+static void set_media_labels(struct confbridge_conference *conference,</span><br><span> struct ast_channel *src_chan, struct ast_channel *dest_chan, enum label_direction dir)</span><br><span> {</span><br><span> struct ast_stream_topology *topology;</span><br><span> struct ast_stream *stream;</span><br><span style="color: hsl(0, 100%, 40%);">- const char *curr_a_label;</span><br><span style="color: hsl(0, 100%, 40%);">- const char *a_label = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- const char *v_label = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_json *labels = ast_json_array_create();</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *chan = dir == LABEL_DIRECTION_SRC ? dest_chan : src_chan;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!labels) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- topology = ast_channel_get_stream_topology(dir == LABEL_DIRECTION_SRC ? src_chan : dest_chan);</span><br><span style="color: hsl(0, 100%, 40%);">- stream = get_stream(topology, AST_MEDIA_TYPE_AUDIO);</span><br><span style="color: hsl(0, 100%, 40%);">- curr_a_label = stream ? ast_stream_get_metadata(stream, "MSID:LABEL") : NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- a_label = curr_a_label ?: conference->bridge->uniqueid;</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_array_append(labels, ast_json_string_create(a_label));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- topology = ast_channel_get_stream_topology(dir == LABEL_DIRECTION_SRC ? dest_chan : src_chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ topology = ast_channel_get_stream_topology(chan);</span><br><span> stream = get_stream(topology, AST_MEDIA_TYPE_VIDEO);</span><br><span style="color: hsl(0, 100%, 40%);">- v_label = stream ? ast_stream_get_metadata(stream, "MSID:LABEL") : NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- if (v_label) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_array_append(labels, ast_json_string_create(v_label));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (stream) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stream_set_metadata(stream, "SDP:LABEL", ast_channel_uniqueid(chan));</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return ast_json_pack("{s: o }", "media_source_track_labels", labels);</span><br><span> }</span><br><span> </span><br><span> static void send_message(const char *msg_name, char *conf_name, struct ast_json *json_object,</span><br><span>@@ -505,7 +489,6 @@</span><br><span> ao2_lock(conference);</span><br><span> AST_LIST_TRAVERSE(&conference->active_list, user, list) {</span><br><span> struct ast_json *json_object;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_json* source_json_labels = NULL;</span><br><span> </span><br><span> /*</span><br><span> * If the msg type is join, we need to capture all targets channel info so we can</span><br><span>@@ -514,7 +497,6 @@</span><br><span> if (source_send_events && stasis_message_type(msg) == confbridge_join_type()) {</span><br><span> struct ast_channel_snapshot *target_snapshot;</span><br><span> struct ast_json *target_json_channel;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_json *target_json_labels;</span><br><span> </span><br><span> target_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(user->chan));</span><br><span> if (!target_snapshot) {</span><br><span>@@ -523,17 +505,15 @@</span><br><span> continue;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- target_json_labels = get_media_labels(conference, chan, user->chan, LABEL_DIRECTION_SRC);</span><br><span style="color: hsl(0, 100%, 40%);">- target_json_channel = channel_to_json(target_snapshot, extras, target_json_labels);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_media_labels(conference, chan, user->chan, LABEL_DIRECTION_SRC);</span><br><span style="color: hsl(120, 100%, 40%);">+ target_json_channel = channel_to_json(target_snapshot, extras, NULL);</span><br><span> ao2_ref(target_snapshot, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_unref(target_json_labels);</span><br><span> </span><br><span> if (!json_channels) {</span><br><span> json_channels = ast_json_array_create();</span><br><span> if (!json_channels) {</span><br><span> ast_log(LOG_ERROR, "Unable to allocate json array\n");</span><br><span> ast_json_unref(target_json_channel);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_unref(target_json_labels);</span><br><span> return;</span><br><span> }</span><br><span> }</span><br><span>@@ -555,11 +535,9 @@</span><br><span> continue;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- source_json_labels = get_media_labels(conference, chan, user->chan, LABEL_DIRECTION_DEST);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_object_update(extras, source_json_labels);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_media_labels(conference, chan, user->chan, LABEL_DIRECTION_DEST);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- json_object = pack_snapshots(obj->bridge, obj->channel, extras, source_json_labels, msg);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_unref(source_json_labels);</span><br><span style="color: hsl(120, 100%, 40%);">+ json_object = pack_snapshots(obj->bridge, obj->channel, extras, NULL, msg);</span><br><span> </span><br><span> if (!json_object) {</span><br><span> ast_log(LOG_ERROR, "Unable to convert %s message to json\n", msg_name);</span><br><span>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c</span><br><span>index c9c0f17..d435d8f 100644</span><br><span>--- a/res/res_pjsip_sdp_rtp.c</span><br><span>+++ b/res/res_pjsip_sdp_rtp.c</span><br><span>@@ -1100,6 +1100,7 @@</span><br><span> pj_str_t stmp;</span><br><span> pjmedia_sdp_attr *attr;</span><br><span> char msid[(AST_UUID_STR_LEN * 2) + 2];</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *stream_label = ast_stream_get_metadata(stream, "SDP:LABEL");</span><br><span> </span><br><span> if (!session->endpoint->media.webrtc) {</span><br><span> return;</span><br><span>@@ -1119,19 +1120,7 @@</span><br><span> }</span><br><span> </span><br><span> if (ast_strlen_zero(session_media->label)) {</span><br><span style="color: hsl(0, 100%, 40%);">- /*</span><br><span style="color: hsl(0, 100%, 40%);">- * If this stream has already been assigned a label, use it.</span><br><span style="color: hsl(0, 100%, 40%);">- * This will ensure that a confbridge participant is known by</span><br><span style="color: hsl(0, 100%, 40%);">- * the same label by all other participants.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">- const char *stream_label = ast_stream_get_metadata(stream, "MSID:LABEL");</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(stream_label)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_string(session_media->label, stream_label, sizeof(session_media->label));</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span> ast_uuid_generate_str(session_media->label, sizeof(session_media->label));</span><br><span style="color: hsl(0, 100%, 40%);">- ast_stream_set_metadata(stream, "MSID:LABEL", session_media->label);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span> }</span><br><span> </span><br><span> snprintf(msid, sizeof(msid), "%s %s", session_media->mslabel, session_media->label);</span><br><span>@@ -1139,6 +1128,14 @@</span><br><span> ast_codec_media_type2str(ast_stream_get_type(stream)), msid);</span><br><span> attr = pjmedia_sdp_attr_create(pool, "msid", pj_cstr(&stmp, msid));</span><br><span> pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* 'label' must come after 'msid' */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(stream_label)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Stream Label: %p %s %s\n", stream,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_codec_media_type2str(ast_stream_get_type(stream)), stream_label);</span><br><span style="color: hsl(120, 100%, 40%);">+ attr = pjmedia_sdp_attr_create(pool, "label", pj_cstr(&stmp, stream_label));</span><br><span style="color: hsl(120, 100%, 40%);">+ pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> static void add_rtcp_fb_to_stream(struct ast_sip_session *session,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9377">change 9377</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9377"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6cbaa87fb59a2e0688d956e72d2d09e4ac20d5a5 </div>
<div style="display:none"> Gerrit-Change-Number: 9377 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>