2010-10-07 18:20:02 +00:00
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
|
|
|
|
#include "speakup.h"
|
|
|
|
#include "spk_priv.h"
|
|
|
|
|
2013-01-08 18:39:01 +00:00
|
|
|
#define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */
|
2010-10-07 18:20:02 +00:00
|
|
|
|
2017-03-04 14:01:55 +00:00
|
|
|
static u16 synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */
|
|
|
|
static u16 *buff_in = synth_buffer;
|
|
|
|
static u16 *buff_out = synth_buffer;
|
|
|
|
static u16 *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
|
2010-10-07 18:20:02 +00:00
|
|
|
|
|
|
|
/* These try to throttle applications by stopping the TTYs
|
|
|
|
* Note: we need to make sure that we will restart them eventually, which is
|
|
|
|
* usually not possible to do from the notifiers. TODO: it should be possible
|
|
|
|
* starting from linux 2.6.26.
|
|
|
|
*
|
|
|
|
* So we only stop when we know alive == 1 (else we discard the data anyway),
|
|
|
|
* and the alive synth will eventually call start_ttys from the thread context.
|
|
|
|
*/
|
|
|
|
void speakup_start_ttys(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_NR_CONSOLES; i++) {
|
|
|
|
if (speakup_console[i] && speakup_console[i]->tty_stopped)
|
|
|
|
continue;
|
2015-11-19 16:18:43 +00:00
|
|
|
if ((vc_cons[i].d) && (vc_cons[i].d->port.tty))
|
2010-10-08 02:30:49 +00:00
|
|
|
start_tty(vc_cons[i].d->port.tty);
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(speakup_start_ttys);
|
|
|
|
|
|
|
|
static void speakup_stop_ttys(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_NR_CONSOLES; i++)
|
2015-11-19 16:18:43 +00:00
|
|
|
if ((vc_cons[i].d && (vc_cons[i].d->port.tty)))
|
2010-10-08 02:30:49 +00:00
|
|
|
stop_tty(vc_cons[i].d->port.tty);
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int synth_buffer_free(void)
|
|
|
|
{
|
2017-03-04 14:01:55 +00:00
|
|
|
int chars_free;
|
2010-10-07 18:20:02 +00:00
|
|
|
|
|
|
|
if (buff_in >= buff_out)
|
2017-03-04 14:01:55 +00:00
|
|
|
chars_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
|
2010-10-07 18:20:02 +00:00
|
|
|
else
|
2017-03-04 14:01:55 +00:00
|
|
|
chars_free = buff_out - buff_in;
|
|
|
|
return chars_free;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int synth_buffer_empty(void)
|
|
|
|
{
|
|
|
|
return (buff_in == buff_out);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synth_buffer_empty);
|
|
|
|
|
2017-03-04 14:01:55 +00:00
|
|
|
void synth_buffer_add(u16 ch)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
if (!synth->alive) {
|
|
|
|
/* This makes sure that we won't stop TTYs if there is no synth
|
2015-08-14 19:34:37 +00:00
|
|
|
* to restart them
|
|
|
|
*/
|
2010-10-07 18:20:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (synth_buffer_free() <= 100) {
|
|
|
|
synth_start();
|
|
|
|
speakup_stop_ttys();
|
|
|
|
}
|
|
|
|
if (synth_buffer_free() <= 1)
|
|
|
|
return;
|
|
|
|
*buff_in++ = ch;
|
|
|
|
if (buff_in > buffer_end)
|
|
|
|
buff_in = synth_buffer;
|
|
|
|
}
|
|
|
|
|
2017-03-04 14:01:55 +00:00
|
|
|
u16 synth_buffer_getc(void)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
2017-03-04 14:01:55 +00:00
|
|
|
u16 ch;
|
2010-10-07 18:20:02 +00:00
|
|
|
|
|
|
|
if (buff_out == buff_in)
|
|
|
|
return 0;
|
|
|
|
ch = *buff_out++;
|
|
|
|
if (buff_out > buffer_end)
|
|
|
|
buff_out = synth_buffer;
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synth_buffer_getc);
|
|
|
|
|
2017-03-04 14:01:55 +00:00
|
|
|
u16 synth_buffer_peek(void)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
if (buff_out == buff_in)
|
|
|
|
return 0;
|
|
|
|
return *buff_out;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synth_buffer_peek);
|
|
|
|
|
2017-03-04 14:01:55 +00:00
|
|
|
void synth_buffer_skip_nonlatin1(void)
|
|
|
|
{
|
|
|
|
while (buff_out != buff_in) {
|
|
|
|
if (*buff_out < 0x100)
|
|
|
|
return;
|
|
|
|
buff_out++;
|
|
|
|
if (buff_out > buffer_end)
|
|
|
|
buff_out = synth_buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synth_buffer_skip_nonlatin1);
|
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
void synth_buffer_clear(void)
|
|
|
|
{
|
2015-10-23 19:12:14 +00:00
|
|
|
buff_in = synth_buffer;
|
|
|
|
buff_out = synth_buffer;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synth_buffer_clear);
|