<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18496">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: Flip stream direction of second channel.<br><br>When a new unreal (local) channel is created, a second (;2) channel is<br>created as a counterpart which clones the topology of the first<br>channel. This creates issues when an outgoing stream is sendonly or<br>recvonly as the stream state of the inbound channel will be the same<br>as the stream state of the outbound channel.<br><br>Now the stream state is flipped for the streams of the 2nd channel in<br>ast_unreal_new_channels if the outgoing stream topology is recvonly or<br>sendonly.<br><br>ASTERISK-29655<br>Reported by: Michael Auracher<br><br>ASTERISK-29638<br>Reported by: Michael Auracher<br><br>Change-Id: I0cea29635bb20b7bf7fd0fb95498cd44dab98fbf<br>---<br>M main/core_unreal.c<br>1 file changed, 23 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/core_unreal.c b/main/core_unreal.c</span><br><span>index a79fca4..d43272c 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/+/18496">change 18496</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/+/18496"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 19 </div>
<div style="display:none"> Gerrit-Change-Id: I0cea29635bb20b7bf7fd0fb95498cd44dab98fbf </div>
<div style="display:none"> Gerrit-Change-Number: 18496 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Maximilian Fridrich <m.fridrich@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>