[Asterisk-code-review] chan console: don't read and write at the same time (asterisk[master])
Tzafrir Cohen
asteriskteam at digium.com
Tue Dec 19 06:31:17 CST 2017
Tzafrir Cohen has uploaded this change for review. ( https://gerrit.asterisk.org/7657
Change subject: chan_console: don't read and write at the same time
......................................................................
chan_console: don't read and write at the same time
It seems that the ALSA backend of PortAudio doesn't know how to to both
read and write at the same time by adding a per-device mutex.
FIXME: currently only a draft version. Need to either auto-detect
we work with the ALSA backend or add an extra configuration option
to use this mutex.
ASTERISK-27426 #close
Change-Id: I635eacee45f5413faa18f5a3b606af03b926dacb
---
M channels/chan_console.c
1 file changed, 10 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/7657/1
diff --git a/channels/chan_console.c b/channels/chan_console.c
index a24a6c8..93da049 100644
--- a/channels/chan_console.c
+++ b/channels/chan_console.c
@@ -68,6 +68,7 @@
#include "asterisk/module.h"
#include "asterisk/channel.h"
+#include "asterisk/lock.h"
#include "asterisk/pbx.h"
#include "asterisk/causes.h"
#include "asterisk/cli.h"
@@ -167,6 +168,8 @@
unsigned int destroy:1;
/*! ID for the stream monitor thread */
pthread_t thread;
+ /*! Mutex for read/write */
+ ast_mutex_t mutex;
} globals;
AST_MUTEX_DEFINE_STATIC(globals_lock);
@@ -278,7 +281,9 @@
for (;;) {
pthread_testcancel();
+ ast_mutex_lock(&pvt->mutex);
res = Pa_ReadStream(pvt->stream, buf, sizeof(buf) / sizeof(int16_t));
+ ast_mutex_unlock(&pvt->mutex);
pthread_testcancel();
if (!pvt->owner) {
@@ -368,6 +373,7 @@
pvt->streamstate = 1;
ast_debug(1, "Starting stream\n");
+ ast_mutex_init(&pvt->mutex);
res = open_stream(pvt);
if (res != paNoError) {
@@ -391,6 +397,7 @@
}
return_unlock:
+ ast_mutex_destroy(&pvt->mutex);
console_pvt_unlock(pvt);
return ret_val;
@@ -403,6 +410,7 @@
pthread_cancel(pvt->thread);
pthread_kill(pvt->thread, SIGURG);
+ ast_mutex_destroy(&pvt->mutex);
pthread_join(pvt->thread, NULL);
console_pvt_lock(pvt);
@@ -611,7 +619,9 @@
{
struct console_pvt *pvt = ast_channel_tech_pvt(chan);
+ ast_mutex_lock(&pvt->mutex);
Pa_WriteStream(pvt->stream, f->data.ptr, f->samples);
+ ast_mutex_unlock(&pvt->mutex);
return 0;
}
--
To view, visit https://gerrit.asterisk.org/7657
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I635eacee45f5413faa18f5a3b606af03b926dacb
Gerrit-Change-Number: 7657
Gerrit-PatchSet: 1
Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171219/9de055b1/attachment-0001.html>
More information about the asterisk-code-review
mailing list