<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18371">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core_unreal & app_dial: Flip stream direction of second channel.<br><br>When executing dial, the topology of the inbound channel is cloned and<br>used for the outbound channel. This creates issues when an incoming<br>stream is sendonly or recvonly as the stream state of the outbound<br>channel will be the same as the stream state of the inbound channel.<br><br>Now the stream state is flipped for the outgoing stream in<br>dial_exec_full if the incoming stream topology is recvonly or sendonly.<br><br>The same is the case for unreal (local) channels which create a second<br>(;2) channel as a counterpart which clones the topology of the<br>first channel. Now the stream state is flipped for the streams of<br>the 2nd channel in ast_unreal_new_channels if the incoming stream<br>topology is recvonly or sendonly.<br><br>ASTERISK-29655<br>Reported by: Michael Auracher<br><br>ASTERISK-29638<br>Reported by: Michael Auracher<br><br>Change-Id: I294dc834ac9a5f048b101b691669959e9df630e1<br>---<br>M apps/app_dial.c<br>M main/core_unreal.c<br>2 files changed, 40 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_dial.c b/apps/app_dial.c</span><br><span>index ee77551..fdcf66b 100644</span><br><span>--- a/apps/app_dial.c</span><br><span>+++ b/apps/app_dial.c</span><br><span>@@ -2587,9 +2587,11 @@</span><br><span>                struct ast_channel *tc; /* channel for this destination */</span><br><span>           char *number;</span><br><span>                char *tech;</span><br><span style="color: hsl(120, 100%, 40%);">+           int i;</span><br><span>               size_t tech_len;</span><br><span>             size_t number_len;</span><br><span>           struct ast_stream_topology *topology;</span><br><span style="color: hsl(120, 100%, 40%);">+         struct ast_stream *stream;</span><br><span> </span><br><span>               cur = ast_strip(cur);</span><br><span>                if (ast_strlen_zero(cur)) {</span><br><span>@@ -2655,6 +2657,21 @@</span><br><span> </span><br><span>             ast_channel_unlock(chan);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+         for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    stream = ast_stream_topology_get_stream(topology, i);</span><br><span style="color: hsl(120, 100%, 40%);">+                 /* For both recvonly and sendonly the stream state reflects our state, that is we</span><br><span style="color: hsl(120, 100%, 40%);">+                      * are receiving only and we are sending only. Since we are requesting a</span><br><span style="color: hsl(120, 100%, 40%);">+                       * channel for the peer, we need to swap this to reflect what we will be doing.</span><br><span style="color: hsl(120, 100%, 40%);">+                        * That is, if we are receiving from Alice then we want to be sending to Bob,</span><br><span style="color: hsl(120, 100%, 40%);">+                  * so swap recvonly to sendonly and vice versa.</span><br><span style="color: hsl(120, 100%, 40%);">+                        */</span><br><span style="color: hsl(120, 100%, 40%);">+                   if (ast_stream_get_state(stream) == AST_STREAM_STATE_RECVONLY) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              ast_stream_set_state(stream, AST_STREAM_STATE_SENDONLY);</span><br><span style="color: hsl(120, 100%, 40%);">+                      } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {</span><br><span style="color: hsl(120, 100%, 40%);">+                               ast_stream_set_state(stream, AST_STREAM_STATE_RECVONLY);</span><br><span style="color: hsl(120, 100%, 40%);">+                      }</span><br><span style="color: hsl(120, 100%, 40%);">+             }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>          tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);</span><br><span> </span><br><span>           ast_stream_topology_free(topology);</span><br><span>diff --git a/main/core_unreal.c b/main/core_unreal.c</span><br><span>index dec992d..861e188 100644</span><br><span>--- a/main/core_unreal.c</span><br><span>+++ b/main/core_unreal.c</span><br><span>@@ -1168,7 +1168,9 @@</span><br><span>     struct ast_assigned_ids id1 = {NULL, NULL};</span><br><span>  struct ast_assigned_ids id2 = {NULL, NULL};</span><br><span>  int generated_seqno = ast_atomic_fetchadd_int((int *) &name_sequence, +1);</span><br><span style="color: hsl(0, 100%, 40%);">-  struct ast_stream_topology *topology;</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct ast_stream_topology *chan_topology;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct ast_stream *stream;</span><br><span> </span><br><span>       /* set unique ids for the two channels */</span><br><span>    if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {</span><br><span>@@ -1186,14 +1188,27 @@</span><br><span>           id2.uniqueid = uniqueid2;</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* We need to create a topology to place on the first channel, as we can't</span><br><span style="color: hsl(120, 100%, 40%);">+        /* We need to create a topology to place on the second channel, as we can't</span><br><span>       * share a single one between both.</span><br><span>   */</span><br><span style="color: hsl(0, 100%, 40%);">-     topology = ast_stream_topology_clone(p->reqtopology);</span><br><span style="color: hsl(0, 100%, 40%);">-        if (!topology) {</span><br><span style="color: hsl(120, 100%, 40%);">+      chan_topology = ast_stream_topology_clone(p->reqtopology);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!chan_topology) {</span><br><span>                return NULL;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ast_stream_topology_get_count(chan_topology); ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+               stream = ast_stream_topology_get_stream(chan_topology, i);</span><br><span style="color: hsl(120, 100%, 40%);">+            /* We need to make sure that the ;2 channel has the opposite stream topology</span><br><span style="color: hsl(120, 100%, 40%);">+           * of the first channel if the stream is one-way. I.e. if the first channel</span><br><span style="color: hsl(120, 100%, 40%);">+            * is recvonly, the second channel has to be sendonly and vice versa.</span><br><span style="color: hsl(120, 100%, 40%);">+          */</span><br><span style="color: hsl(120, 100%, 40%);">+           if (ast_stream_get_state(stream) == AST_STREAM_STATE_RECVONLY) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      ast_stream_set_state(stream, AST_STREAM_STATE_SENDONLY);</span><br><span style="color: hsl(120, 100%, 40%);">+              } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       ast_stream_set_state(stream, AST_STREAM_STATE_RECVONLY);</span><br><span style="color: hsl(120, 100%, 40%);">+              }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  /*</span><br><span>    * Allocate two new Asterisk channels</span><br><span>         *</span><br><span>@@ -1206,7 +1221,7 @@</span><br><span>           "%s/%s-%08x;1", tech->type, p->name, (unsigned)generated_seqno);</span><br><span>     if (!owner) {</span><br><span>                ast_log(LOG_WARNING, "Unable to allocate owner channel structure\n");</span><br><span style="color: hsl(0, 100%, 40%);">-         ast_stream_topology_free(topology);</span><br><span style="color: hsl(120, 100%, 40%);">+           ast_stream_topology_free(chan_topology);</span><br><span>             return NULL;</span><br><span>         }</span><br><span> </span><br><span>@@ -1221,7 +1236,8 @@</span><br><span>        ast_channel_nativeformats_set(owner, p->reqcap);</span><br><span> </span><br><span>      if (ast_channel_is_multistream(owner)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                ast_channel_set_stream_topology(owner, topology);</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_channel_set_stream_topology(owner, p->reqtopology);</span><br><span style="color: hsl(120, 100%, 40%);">+            p->reqtopology = NULL;</span><br><span>    }</span><br><span> </span><br><span>        /* Determine our read/write format and set it on each channel */</span><br><span>@@ -1279,8 +1295,7 @@</span><br><span>     ast_channel_nativeformats_set(chan, p->reqcap);</span><br><span> </span><br><span>       if (ast_channel_is_multistream(chan)) {</span><br><span style="color: hsl(0, 100%, 40%);">-         ast_channel_set_stream_topology(chan, p->reqtopology);</span><br><span style="color: hsl(0, 100%, 40%);">-               p->reqtopology = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_channel_set_stream_topology(chan, chan_topology);</span><br><span>        }</span><br><span> </span><br><span>        /* Format was already determined when setting up owner */</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18371">change 18371</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/c/asterisk/+/18371"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I294dc834ac9a5f048b101b691669959e9df630e1 </div>
<div style="display:none"> Gerrit-Change-Number: 18371 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Maximilian Fridrich <m.fridrich@commend.com> </div>
<div style="display:none"> Gerrit-Reviewer: Florian Floimair <f.floimair@commend.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>