<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14069">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;">channel: write to a stream on multi-frame writes<br><br>If a frame handling routine returns a list of frames (vs. a single frame)<br>those frames are never passed to a tech's write_stream handler even if one is<br>available. For instance, if a codec translation occurred and that codec<br>returned multiple frames then those particular frames were always only sent<br>to the tech's "write" handler. If that tech (pjsip for example) was stream<br>capable then those frames were essentially ignored. Thus resulting in bad<br>audio.<br><br>This patch makes it so the "write_stream" handler is appropriately called<br>for all cases, and for all frames if available.<br><br>ASTERISK-28795 #close<br><br>Change-Id: I868faea0b73a07ed5a32c2b05bb9cf4b586f739d<br>---<br>M main/channel.c<br>1 file changed, 16 insertions(+), 23 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index cb413ff..7eb2546 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -5070,6 +5070,18 @@</span><br><span> adjust_frame_for_plc(chan, frame, datastore);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int tech_write(struct ast_channel *chan, struct ast_stream *stream,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream *default_stream, struct ast_frame *frame)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_channel_tech(chan)->write_stream) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return stream ? ast_channel_tech(chan)->write_stream(</span><br><span style="color: hsl(120, 100%, 40%);">+ chan, ast_stream_get_position(stream), frame) : 0;</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%);">+ return ((stream == default_stream) && ast_channel_tech(chan)->write) ?</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_tech(chan)->write(chan, frame) : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_write(struct ast_channel *chan, struct ast_frame *fr)</span><br><span> {</span><br><span> return ast_write_stream(chan, -1, fr);</span><br><span>@@ -5223,17 +5235,7 @@</span><br><span> break;</span><br><span> case AST_FRAME_MODEM:</span><br><span> CHECK_BLOCKING(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_channel_tech(chan)->write_stream) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (stream) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_channel_tech(chan)->write_stream(chan, ast_stream_get_position(stream), fr);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- res = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- } else if ((stream == default_stream) && ast_channel_tech(chan)->write) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_channel_tech(chan)->write(chan, fr);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- res = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ res = tech_write(chan, stream, default_stream, fr);</span><br><span> ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);</span><br><span> break;</span><br><span> case AST_FRAME_VOICE:</span><br><span>@@ -5400,7 +5402,8 @@</span><br><span> next = AST_LIST_NEXT(cur, frame_list);</span><br><span> AST_LIST_NEXT(cur, frame_list) = NULL;</span><br><span> if (!skip) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((res = ast_channel_tech(chan)->write(chan, cur)) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = tech_write(chan, stream, default_stream, cur);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res < 0) {</span><br><span> ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);</span><br><span> skip = 1;</span><br><span> } else if (next) {</span><br><span>@@ -5417,17 +5420,7 @@</span><br><span> /* reset f so the code below doesn't attempt to free it */</span><br><span> f = NULL;</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_channel_tech(chan)->write_stream) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (stream) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_channel_tech(chan)->write_stream(chan, ast_stream_get_position(stream), f);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- res = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- } else if ((stream == default_stream) && ast_channel_tech(chan)->write) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_channel_tech(chan)->write(chan, f);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- res = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ res = tech_write(chan, stream, default_stream, f);</span><br><span> }</span><br><span> ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);</span><br><span> break;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14069">change 14069</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/+/14069"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: certified/16.3 </div>
<div style="display:none"> Gerrit-Change-Id: I868faea0b73a07ed5a32c2b05bb9cf4b586f739d </div>
<div style="display:none"> Gerrit-Change-Number: 14069 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@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-MessageType: merged </div>