0001
0002 #include <linux/console.h>
0003 #include <linux/types.h>
0004 #include <linux/wait.h>
0005
0006 #include "speakup.h"
0007 #include "spk_priv.h"
0008
0009 #define SYNTH_BUF_SIZE 8192
0010
0011 static u16 synth_buffer[SYNTH_BUF_SIZE];
0012 static u16 *buff_in = synth_buffer;
0013 static u16 *buff_out = synth_buffer;
0014 static u16 *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 void speakup_start_ttys(void)
0025 {
0026 int i;
0027
0028 for (i = 0; i < MAX_NR_CONSOLES; i++) {
0029 if (speakup_console[i] && speakup_console[i]->tty_stopped)
0030 continue;
0031 if (vc_cons[i].d && vc_cons[i].d->port.tty)
0032 start_tty(vc_cons[i].d->port.tty);
0033 }
0034 }
0035 EXPORT_SYMBOL_GPL(speakup_start_ttys);
0036
0037 static void speakup_stop_ttys(void)
0038 {
0039 int i;
0040
0041 for (i = 0; i < MAX_NR_CONSOLES; i++)
0042 if (vc_cons[i].d && vc_cons[i].d->port.tty)
0043 stop_tty(vc_cons[i].d->port.tty);
0044 }
0045
0046 static int synth_buffer_free(void)
0047 {
0048 int chars_free;
0049
0050 if (buff_in >= buff_out)
0051 chars_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
0052 else
0053 chars_free = buff_out - buff_in;
0054 return chars_free;
0055 }
0056
0057 int synth_buffer_empty(void)
0058 {
0059 return (buff_in == buff_out);
0060 }
0061 EXPORT_SYMBOL_GPL(synth_buffer_empty);
0062
0063 void synth_buffer_add(u16 ch)
0064 {
0065 if (!synth->alive) {
0066
0067
0068
0069 return;
0070 }
0071 if (synth_buffer_free() <= 100) {
0072 synth_start();
0073 speakup_stop_ttys();
0074 }
0075 if (synth_buffer_free() <= 1)
0076 return;
0077 *buff_in++ = ch;
0078 if (buff_in > buffer_end)
0079 buff_in = synth_buffer;
0080
0081
0082
0083 spk_paused = false;
0084 }
0085
0086 u16 synth_buffer_getc(void)
0087 {
0088 u16 ch;
0089
0090 if (buff_out == buff_in)
0091 return 0;
0092 ch = *buff_out++;
0093 if (buff_out > buffer_end)
0094 buff_out = synth_buffer;
0095 return ch;
0096 }
0097 EXPORT_SYMBOL_GPL(synth_buffer_getc);
0098
0099 u16 synth_buffer_peek(void)
0100 {
0101 if (buff_out == buff_in)
0102 return 0;
0103 return *buff_out;
0104 }
0105 EXPORT_SYMBOL_GPL(synth_buffer_peek);
0106
0107 void synth_buffer_skip_nonlatin1(void)
0108 {
0109 while (buff_out != buff_in) {
0110 if (*buff_out < 0x100)
0111 return;
0112 buff_out++;
0113 if (buff_out > buffer_end)
0114 buff_out = synth_buffer;
0115 }
0116 }
0117 EXPORT_SYMBOL_GPL(synth_buffer_skip_nonlatin1);
0118
0119 void synth_buffer_clear(void)
0120 {
0121 buff_in = synth_buffer;
0122 buff_out = synth_buffer;
0123 }
0124 EXPORT_SYMBOL_GPL(synth_buffer_clear);