chan_console: don't read and write at the same time
authorOron Peled <oron.peled@xorcom.com>
Tue, 19 Dec 2017 08:52:54 +0000 (10:52 +0200)
committerSean Bright <sean.bright@gmail.com>
Sat, 3 Feb 2018 14:41:07 +0000 (09:41 -0500)
It seems that the ALSA backend of PortAudio doesn't know how 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

channels/chan_console.c

index 7c57ec4..7692b26 100644 (file)
@@ -278,7 +278,9 @@ static void *stream_monitor(void *data)
 
        for (;;) {
                pthread_testcancel();
+               console_pvt_lock(pvt);
                res = Pa_ReadStream(pvt->stream, buf, sizeof(buf) / sizeof(int16_t));
+               console_pvt_unlock(pvt);
                pthread_testcancel();
 
                if (!pvt->owner) {
@@ -611,7 +613,9 @@ static int console_write(struct ast_channel *chan, struct ast_frame *f)
 {
        struct console_pvt *pvt = ast_channel_tech_pvt(chan);
 
+       console_pvt_lock(pvt);
        Pa_WriteStream(pvt->stream, f->data.ptr, f->samples);
+       console_pvt_unlock(pvt);
 
        return 0;
 }