<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/6574">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: Reduce (and improve) SDP renegotiation.<br><br>When pruning a request to change the topology of a channel be<br>more intelligent about the resulting topology that is actually<br>used for SDP renegotiation.<br><br>In a case where a stream has not already been negotiated we<br>don't need to renegotiate and offer a declined stream. This can<br>occur if something in Asterisk (such as ConfBridge) requests<br>to add video to a PJSIP channel that has no video codecs configured.<br>In this case since the stream did not already exist we can safely<br>remove the stream from the requested topology, resulting in no<br>renegotiation occurring.<br><br>In a case where a renegotiation is requested with a codec that is<br>not supported we can reuse the formats of the existing stream if<br>it exists to ensure that the stream continues to flow, instead of<br>removing it.<br><br>Change-Id: I636540798d55922377318fe619c510fb6ed125fb<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 29 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/6574/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c<br>index 2beb6dc..d61799b 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -1482,7 +1482,14 @@<br>                    * are configurable on the endpoint.<br>                   */<br>                   for (index = 0; index < ast_stream_topology_get_count(media_state->topology); ++index) {<br>+                               struct ast_stream *existing_stream = NULL;<br>+<br>                                 stream = ast_stream_topology_get_stream(media_state->topology, index);<br>+<br>+                         if (session->active_media_state->topology &&<br>+                                   index < ast_stream_topology_get_count(session->active_media_state->topology)) {<br>+                                     existing_stream = ast_stream_topology_get_stream(session->active_media_state->topology, index);<br>+                                }<br> <br>                          if (is_stream_limitation_reached(ast_stream_get_type(stream), session->endpoint, type_streams)) {<br>                                  if (index < AST_VECTOR_SIZE(&media_state->sessions)) {<br>@@ -1516,8 +1523,28 @@<br>                                      ast_format_cap_get_compatible(ast_stream_get_formats(stream), session->endpoint->media.codecs, joint_cap);<br>                                      if (!ast_format_cap_count(joint_cap)) {<br>                                               ao2_ref(joint_cap, -1);<br>-                                              ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);<br>-                                              continue;<br>+<br>+                                         if (!existing_stream) {<br>+                                                      /* If there is no existing stream we can just not have this stream in the topology<br>+                                                    * at all.<br>+                                                    */<br>+                                                  ast_stream_topology_del_stream(media_state->topology, index);<br>+                                                     index -= 1;<br>+                                                  continue;<br>+                                            } else if (ast_stream_get_state(stream) != ast_stream_get_state(existing_stream) ||<br>+                                                          strcmp(ast_stream_get_name(stream), ast_stream_get_name(existing_stream))) {<br>+                                                 /* If the underlying stream is a different type or different name then we have to<br>+                                                     * mark it as removed, as it is replacing an existing stream. We do this so order<br>+                                                     * is preserved.<br>+                                                      */<br>+                                                  ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);<br>+                                                      continue;<br>+                                            } else {<br>+                                                     /* However if the stream is otherwise remaining the same we can keep the formats<br>+                                                      * that exist on it already which allows media to continue to flow.<br>+                                                   */<br>+                                                  joint_cap = ao2_bump(ast_stream_get_formats(existing_stream));<br>+                                               }<br>                                     }<br>                                     ast_stream_set_formats(stream, joint_cap);<br>                            }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6574">change 6574</a>. To unsubscribe, 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/6574"/><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: I636540798d55922377318fe619c510fb6ed125fb </div>
<div style="display:none"> Gerrit-Change-Number: 6574 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>