<p>Tzafrir Cohen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7657">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_console: don't read and write at the same time<br><br>It seems that the ALSA backend of PortAudio doesn't know how to to both<br>read and write at the same time by adding a per-device mutex.<br><br>FIXME: currently only a draft version. Need to either auto-detect<br>we work with the ALSA backend or add an extra configuration option<br>to use this mutex.<br><br>ASTERISK-27426 #close<br><br>Change-Id: I635eacee45f5413faa18f5a3b606af03b926dacb<br>---<br>M channels/chan_console.c<br>1 file changed, 10 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/7657/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/channels/chan_console.c b/channels/chan_console.c<br>index a24a6c8..93da049 100644<br>--- a/channels/chan_console.c<br>+++ b/channels/chan_console.c<br>@@ -68,6 +68,7 @@<br> <br> #include "asterisk/module.h"<br> #include "asterisk/channel.h"<br>+#include "asterisk/lock.h"<br> #include "asterisk/pbx.h"<br> #include "asterisk/causes.h"<br> #include "asterisk/cli.h"<br>@@ -167,6 +168,8 @@<br> unsigned int destroy:1;<br> /*! ID for the stream monitor thread */<br> pthread_t thread;<br>+ /*! Mutex for read/write */<br>+ ast_mutex_t mutex;<br> } globals;<br> <br> AST_MUTEX_DEFINE_STATIC(globals_lock);<br>@@ -278,7 +281,9 @@<br> <br> for (;;) {<br> pthread_testcancel();<br>+ ast_mutex_lock(&pvt->mutex);<br> res = Pa_ReadStream(pvt->stream, buf, sizeof(buf) / sizeof(int16_t));<br>+ ast_mutex_unlock(&pvt->mutex);<br> pthread_testcancel();<br> <br> if (!pvt->owner) {<br>@@ -368,6 +373,7 @@<br> <br> pvt->streamstate = 1;<br> ast_debug(1, "Starting stream\n");<br>+ ast_mutex_init(&pvt->mutex);<br> <br> res = open_stream(pvt);<br> if (res != paNoError) {<br>@@ -391,6 +397,7 @@<br> }<br> <br> return_unlock:<br>+ ast_mutex_destroy(&pvt->mutex);<br> console_pvt_unlock(pvt);<br> <br> return ret_val;<br>@@ -403,6 +410,7 @@<br> <br> pthread_cancel(pvt->thread);<br> pthread_kill(pvt->thread, SIGURG);<br>+ ast_mutex_destroy(&pvt->mutex);<br> pthread_join(pvt->thread, NULL);<br> <br> console_pvt_lock(pvt);<br>@@ -611,7 +619,9 @@<br> {<br> struct console_pvt *pvt = ast_channel_tech_pvt(chan);<br> <br>+ ast_mutex_lock(&pvt->mutex);<br> Pa_WriteStream(pvt->stream, f->data.ptr, f->samples);<br>+ ast_mutex_unlock(&pvt->mutex);<br> <br> return 0;<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7657">change 7657</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/7657"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I635eacee45f5413faa18f5a3b606af03b926dacb </div>
<div style="display:none"> Gerrit-Change-Number: 7657 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen@xorcom.com> </div>