<p>Kevin Harwell <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15332">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, approved; Approved for Submit
ben kolodny: Looks good to me, but someone else must approve
George Joseph: Verified
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core_unreal: Fix T.38 faxing when using local channels.<br><br>After some changes to streams and topologies, receiving fax through<br>local channels stopped working. This change adds a stream topology with<br>a stream of type IMAGE to the local channel pair and allows fax to be<br>received.<br><br>ASTERISK-29035 #close<br><br>Change-Id: Id103cc5c9295295d8e68d5628e76220f8f17e9fb<br>---<br>M include/asterisk/core_unreal.h<br>M main/core_unreal.c<br>2 files changed, 90 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/core_unreal.h b/include/asterisk/core_unreal.h</span><br><span>index a28d39d..c6e770b 100644</span><br><span>--- a/include/asterisk/core_unreal.h</span><br><span>+++ b/include/asterisk/core_unreal.h</span><br><span>@@ -98,6 +98,8 @@</span><br><span> /*! Base name of the unreal channels. exten@context or other name. */</span><br><span> char name[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];</span><br><span> struct ast_stream_topology *reqtopology; /*!< Requested stream topology */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream_topology *owner_old_topology; /*!< Stored topology for owner side when we need to restore later (faxing) */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream_topology *chan_old_topology; /*!< Stored topology for chan side when we need to restore later (faxing) */</span><br><span> };</span><br><span> </span><br><span> #define AST_UNREAL_IS_OUTBOUND(a, b) ((a) == (b)->chan ? 1 : 0)</span><br><span>diff --git a/main/core_unreal.c b/main/core_unreal.c</span><br><span>index bff1c3e..653ef78 100644</span><br><span>--- a/main/core_unreal.c</span><br><span>+++ b/main/core_unreal.c</span><br><span>@@ -623,6 +623,9 @@</span><br><span> {</span><br><span> struct ast_unreal_pvt *p = ast_channel_tech_pvt(ast);</span><br><span> int res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *chan = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *owner = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_control_t38_parameters *parameters;</span><br><span> </span><br><span> if (!p) {</span><br><span> return -1;</span><br><span>@@ -677,6 +680,89 @@</span><br><span> res = unreal_colp_stream_topology_request_change(p, ast, data);</span><br><span> }</span><br><span> break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_CONTROL_T38_PARAMETERS:</span><br><span style="color: hsl(120, 100%, 40%);">+ parameters = data;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (parameters->request_response == AST_T38_NEGOTIATED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream *stream;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream_topology *new_topology;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stream = ast_stream_alloc("local_fax", AST_MEDIA_TYPE_IMAGE);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!stream) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to allocate memory for stream.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ new_topology = ast_stream_topology_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!new_topology) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to allocate memory for stream topology.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(stream);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stream_topology_append_stream(new_topology, stream);</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%);">+ * Lock both parts of the local channel so we can store their topologies and replace them with</span><br><span style="color: hsl(120, 100%, 40%);">+ * one that has a stream with type IMAGE. We can just hold the reference on the unreal_pvt</span><br><span style="color: hsl(120, 100%, 40%);">+ * structure and bump it, then steal the ref later when we are restoring the topology.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * We use ast_unreal_lock_all here because we don't know if the ;1 or ;2 side will get the</span><br><span style="color: hsl(120, 100%, 40%);">+ * signaling and we need to be sure that the locking order is the same to prevent possible</span><br><span style="color: hsl(120, 100%, 40%);">+ * deadlocks.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_unreal_lock_all(p, &chan, &owner);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (owner) {</span><br><span style="color: hsl(120, 100%, 40%);">+ p->owner_old_topology = ao2_bump(ast_channel_get_stream_topology(owner));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_set_stream_topology(owner, new_topology);</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%);">+ if (chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ p->chan_old_topology = ao2_bump(ast_channel_get_stream_topology(chan));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Bump the ref for new_topology, since it will be used by both sides of the local channel */</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(new_topology, +1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_set_stream_topology(chan, new_topology);</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%);">+ ao2_unlock(p);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (parameters->request_response == AST_T38_TERMINATED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Lock both parts of the local channel so we can restore their topologies to the original.</span><br><span style="color: hsl(120, 100%, 40%);">+ * The topology should be on the unreal_pvt structure, with a ref that we can steal. Same</span><br><span style="color: hsl(120, 100%, 40%);">+ * conditions as above.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_unreal_lock_all(p, &chan, &owner);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (owner) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_set_stream_topology(owner, p->owner_old_topology);</span><br><span style="color: hsl(120, 100%, 40%);">+ p->owner_old_topology = NULL;</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%);">+ if (chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_set_stream_topology(chan, p->chan_old_topology);</span><br><span style="color: hsl(120, 100%, 40%);">+ p->chan_old_topology = NULL;</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%);">+ ao2_unlock(p);</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 style="color: hsl(120, 100%, 40%);">+ * We unlock ast_unreal_pvt in the above conditionals since there's no way to</span><br><span style="color: hsl(120, 100%, 40%);">+ * tell if it's been unlocked already or not when we get to this point, but</span><br><span style="color: hsl(120, 100%, 40%);">+ * if either of these are not NULL, we know that they are locked and need to</span><br><span style="color: hsl(120, 100%, 40%);">+ * unlock them.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (owner) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(owner);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(owner);</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%);">+ if (chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Fall through for all T38 conditions */</span><br><span> default:</span><br><span> res = unreal_queue_indicate(p, ast, condition, data, datalen);</span><br><span> break;</span><br><span>@@ -1012,6 +1098,8 @@</span><br><span> doomed->reqcap = NULL;</span><br><span> ast_stream_topology_free(doomed->reqtopology);</span><br><span> doomed->reqtopology = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(doomed->owner_old_topology);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(doomed->chan_old_topology);</span><br><span> }</span><br><span> </span><br><span> struct ast_unreal_pvt *ast_unreal_alloc(size_t size, ao2_destructor_fn destructor, struct ast_format_cap *cap)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15332">change 15332</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/+/15332"/><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: Id103cc5c9295295d8e68d5628e76220f8f17e9fb </div>
<div style="display:none"> Gerrit-Change-Number: 15332 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.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-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: ben kolodny <3232963@gmail.com> </div>
<div style="display:none"> Gerrit-CC: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>