Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Macros | Functions | Variables
app_festival.c File Reference

Connect to festival. More...

#include "asterisk.h"
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/md5.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/endian.h"
#include "asterisk/format_cache.h"
Include dependency graph for app_festival.c:

Go to the source code of this file.

Macros

#define FESTIVAL_CONFIG   "festival.conf"
 
#define MAXFESTLEN   2048
 
#define MAXLEN   180
 

Functions

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Simple Festival Interface")
 
static int festival_exec (struct ast_channel *chan, const char *vdata)
 
static int load_module (void)
 Load the module. More...
 
static int send_waveform_to_channel (struct ast_channel *chan, char *waveform, int length, char *intkeys)
 
static int send_waveform_to_fd (char *waveform, int length, int fd)
 
static char * socket_receive_file_to_buff (int fd, int *size)
 
static int unload_module (void)
 

Variables

static char * app = "Festival"
 

Detailed Description

Connect to festival.

Author
Christos Ricudis ricud.nosp@m.is@i.nosp@m.tc.au.nosp@m.th.g.nosp@m.r
ExtRef:
The Festival Speech Synthesis System - http://www.cstr.ed.ac.uk/projects/festival/

Definition in file app_festival.c.

Macro Definition Documentation

◆ FESTIVAL_CONFIG

#define FESTIVAL_CONFIG   "festival.conf"

Definition at line 66 of file app_festival.c.

◆ MAXFESTLEN

#define MAXFESTLEN   2048

Definition at line 68 of file app_festival.c.

◆ MAXLEN

#define MAXLEN   180

Definition at line 67 of file app_festival.c.

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Simple Festival Interface"   
)

◆ festival_exec()

static int festival_exec ( struct ast_channel chan,
const char *  vdata 
)
static

Definition at line 279 of file app_festival.c.

280{
281 int usecache;
282 int res = 0;
283 struct sockaddr_in serv_addr;
284 int fd;
285 FILE *fs;
286 const char *host;
287 const char *cachedir;
288 const char *temp;
289 const char *festivalcommand;
290 int port = 1314;
291 int n;
292 char ack[4];
293 char *waveform;
294 int filesize;
295 char bigstring[MAXFESTLEN];
296 int i;
297 struct MD5Context md5ctx;
298 unsigned char MD5Res[16];
299 char MD5Hex[33] = "";
300 char koko[4] = "";
301 char cachefile[MAXFESTLEN]="";
302 int readcache = 0;
303 int writecache = 0;
304 int strln;
305 int fdesc = -1;
306 char buffer[16384];
307 int seekpos = 0;
308 char *data;
309 struct ast_config *cfg;
310 char *newfestivalcommand;
311 struct ast_flags config_flags = { 0 };
314 AST_APP_ARG(interrupt);
315 );
316
317 if (ast_strlen_zero(vdata)) {
318 ast_log(LOG_WARNING, "festival requires an argument (text)\n");
319 return -1;
320 }
321
322 cfg = ast_config_load(FESTIVAL_CONFIG, config_flags);
323 if (!cfg) {
324 ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
325 return -1;
326 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
327 ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format. Aborting.\n");
328 return -1;
329 }
330
331 if (!(host = ast_variable_retrieve(cfg, "general", "host"))) {
332 host = "localhost";
333 }
334 if (!(temp = ast_variable_retrieve(cfg, "general", "port"))) {
335 port = 1314;
336 } else {
337 port = atoi(temp);
338 }
339 if (!(temp = ast_variable_retrieve(cfg, "general", "usecache"))) {
340 usecache = 0;
341 } else {
342 usecache = ast_true(temp);
343 }
344 if (!(cachedir = ast_variable_retrieve(cfg, "general", "cachedir"))) {
345 cachedir = "/tmp/";
346 }
347
348 data = ast_strdupa(vdata);
350
351 if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) {
352 const char *startcmd = "(tts_textasterisk \"";
353 const char *endcmd = "\" 'file)(quit)\n";
354
355 strln = strlen(startcmd) + strlen(args.text) + strlen(endcmd) + 1;
356 newfestivalcommand = ast_alloca(strln);
357 snprintf(newfestivalcommand, strln, "%s%s%s", startcmd, args.text, endcmd);
358 festivalcommand = newfestivalcommand;
359 } else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */
360 int x, j;
361 newfestivalcommand = ast_alloca(strlen(festivalcommand) + strlen(args.text) + 1);
362
363 for (x = 0, j = 0; x < strlen(festivalcommand); x++) {
364 if (festivalcommand[x] == '\\' && festivalcommand[x + 1] == 'n') {
365 newfestivalcommand[j++] = '\n';
366 x++;
367 } else if (festivalcommand[x] == '\\') {
368 newfestivalcommand[j++] = festivalcommand[x + 1];
369 x++;
370 } else if (festivalcommand[x] == '%' && festivalcommand[x + 1] == 's') {
371 sprintf(&newfestivalcommand[j], "%s", args.text); /* we know it is big enough */
372 j += strlen(args.text);
373 x++;
374 } else
375 newfestivalcommand[j++] = festivalcommand[x];
376 }
377 newfestivalcommand[j] = '\0';
378 festivalcommand = newfestivalcommand;
379 }
380
381 if (args.interrupt && !strcasecmp(args.interrupt, "any"))
382 args.interrupt = AST_DIGIT_ANY;
383
384 ast_debug(1, "Text passed to festival server : %s\n", args.text);
385 /* Connect to local festival server */
386
387 fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
388
389 if (fd < 0) {
390 ast_log(LOG_WARNING, "festival_client: can't get socket\n");
392 return -1;
393 }
394
395 memset(&serv_addr, 0, sizeof(serv_addr));
396
397 if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) {
398 /* its a name rather than an ipnum */
399 struct ast_sockaddr addr = { {0,} };
400
401 if (ast_sockaddr_resolve_first_af(&addr, host, PARSE_PORT_FORBID, AF_INET)) {
402 ast_log(LOG_WARNING, "festival_client: ast_sockaddr_resolve_first_af() failed\n");
404 close(fd);
405 return -1;
406 }
407
408 /* We'll overwrite port and family in a sec */
409 ast_sockaddr_to_sin(&addr, &serv_addr);
410 }
411
412 serv_addr.sin_family = AF_INET;
413 serv_addr.sin_port = htons(port);
414
415 if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) {
416 ast_log(LOG_WARNING, "festival_client: connect to server failed\n");
418 close(fd);
419 return -1;
420 }
421
422 /* Compute MD5 sum of string */
423 MD5Init(&md5ctx);
424 MD5Update(&md5ctx, (unsigned char *)args.text, strlen(args.text));
425 MD5Final(MD5Res, &md5ctx);
426 MD5Hex[0] = '\0';
427
428 /* Convert to HEX and look if there is any matching file in the cache
429 directory */
430 for (i = 0; i < 16; i++) {
431 snprintf(koko, sizeof(koko), "%X", (unsigned)MD5Res[i]);
432 strncat(MD5Hex, koko, sizeof(MD5Hex) - strlen(MD5Hex) - 1);
433 }
434 readcache = 0;
435 writecache = 0;
436 if (strlen(cachedir) + sizeof(MD5Hex) + 1 <= MAXFESTLEN && (usecache == -1)) {
437 snprintf(cachefile, sizeof(cachefile), "%s/%s", cachedir, MD5Hex);
438 fdesc = open(cachefile, O_RDWR);
439 if (fdesc == -1) {
440 fdesc = open(cachefile, O_CREAT | O_RDWR, AST_FILE_MODE);
441 if (fdesc != -1) {
442 writecache = 1;
443 strln = strlen(args.text);
444 ast_debug(1, "line length : %d\n", strln);
445 if (write(fdesc,&strln,sizeof(int)) < 0) {
446 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
447 }
448 if (write(fdesc,data,strln) < 0) {
449 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
450 }
451 seekpos = lseek(fdesc, 0, SEEK_CUR);
452 ast_debug(1, "Seek position : %d\n", seekpos);
453 }
454 } else {
455 if (read(fdesc,&strln,sizeof(int)) != sizeof(int)) {
456 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
457 }
458 ast_debug(1, "Cache file exists, strln=%d, strlen=%d\n", strln, (int)strlen(args.text));
459 if (strlen(args.text) == strln) {
460 ast_debug(1, "Size OK\n");
461 if (read(fdesc,&bigstring,strln) != strln) {
462 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
463 }
464 bigstring[strln] = 0;
465 if (strcmp(bigstring, args.text) == 0) {
466 readcache = 1;
467 } else {
468 ast_log(LOG_WARNING, "Strings do not match\n");
469 }
470 } else {
471 ast_log(LOG_WARNING, "Size mismatch\n");
472 }
473 }
474 }
475
476 if (readcache == 1) {
477 close(fd);
478 fd = fdesc;
479 ast_debug(1, "Reading from cache...\n");
480 } else {
481 ast_debug(1, "Passing text to festival...\n");
482 fs = fdopen(dup(fd), "wb");
483
484 fprintf(fs, "%s", festivalcommand);
485 fflush(fs);
486 fclose(fs);
487 }
488
489 /* Write to cache and then pass it down */
490 if (writecache == 1) {
491 ast_debug(1, "Writing result to cache...\n");
492 while ((strln = read(fd, buffer, 16384)) != 0) {
493 if (write(fdesc,buffer,strln) < 0) {
494 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
495 }
496 }
497 close(fd);
498 close(fdesc);
499 fd = open(cachefile, O_RDWR);
500 lseek(fd, seekpos, SEEK_SET);
501 }
502
503 ast_debug(1, "Passing data to channel...\n");
504
505 /* Read back info from server */
506 /* This assumes only one waveform will come back, also LP is unlikely */
507 do {
508 int read_data;
509 for (n = 0; n < 3; ) {
510 read_data = read(fd, ack + n, 3 - n);
511 /* this avoids falling in infinite loop
512 * in case that festival server goes down
513 */
514 if (read_data == -1) {
515 ast_log(LOG_WARNING, "Unable to read from cache/festival fd\n");
516 close(fd);
518 return -1;
519 }
520 n += read_data;
521 }
522 ack[3] = '\0';
523 if (strcmp(ack, "WV\n") == 0) { /* receive a waveform */
524 ast_debug(1, "Festival WV command\n");
525 if ((waveform = socket_receive_file_to_buff(fd, &filesize))) {
526 res = send_waveform_to_channel(chan, waveform, filesize, args.interrupt);
527 ast_free(waveform);
528 }
529 break;
530 } else if (strcmp(ack, "LP\n") == 0) { /* receive an s-expr */
531 ast_debug(1, "Festival LP command\n");
532 if ((waveform = socket_receive_file_to_buff(fd, &filesize))) {
533 waveform[filesize] = '\0';
534 ast_log(LOG_WARNING, "Festival returned LP : %s\n", waveform);
535 ast_free(waveform);
536 }
537 } else if (strcmp(ack, "ER\n") == 0) { /* server got an error */
538 ast_log(LOG_WARNING, "Festival returned ER\n");
539 res = -1;
540 break;
541 }
542 } while (strcmp(ack, "OK\n") != 0);
543 close(fd);
545 return res;
546}
#define MAXFESTLEN
Definition: app_festival.c:68
#define FESTIVAL_CONFIG
Definition: app_festival.c:66
static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length, char *intkeys)
Definition: app_festival.c:174
static char * socket_receive_file_to_buff(int fd, int *size)
Definition: app_festival.c:89
char * text
Definition: app_queue.c:1639
#define AST_FILE_MODE
Definition: asterisk.h:32
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
#define AST_DIGIT_ANY
Definition: file.h:48
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_config_load(filename, flags)
Load a config file.
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:783
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_WARNING
int errno
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
Definition: md5.c:72
void MD5Init(struct MD5Context *context)
Definition: md5.c:57
void MD5Final(unsigned char digest[16], struct MD5Context *context)
Definition: md5.c:120
int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr, const char *name, int flag, int family)
Return the first entry from ast_sockaddr_resolve filtered by address family.
Definition: netsock2.c:337
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition: netsock2.h:765
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Definition: md5.h:26
Structure used to handle boolean flags.
Definition: utils.h:199
Socket address structure.
Definition: netsock2.h:97
const char * args

References args, ast_alloca, AST_APP_ARG, ast_config_destroy(), ast_config_load, ast_debug, AST_DECLARE_APP_ARGS, AST_DIGIT_ANY, AST_FILE_MODE, ast_free, ast_log, ast_sockaddr_resolve_first_af(), ast_sockaddr_to_sin, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_true(), ast_variable_retrieve(), CONFIG_STATUS_FILEINVALID, errno, FESTIVAL_CONFIG, LOG_ERROR, LOG_WARNING, MAXFESTLEN, MD5Final(), MD5Init(), MD5Update(), PARSE_PORT_FORBID, send_waveform_to_channel(), socket_receive_file_to_buff(), and text.

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Load the module.

Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.

Definition at line 563 of file app_festival.c.

564{
565 struct ast_flags config_flags = { 0 };
566 struct ast_config *cfg = ast_config_load(FESTIVAL_CONFIG, config_flags);
567 if (!cfg) {
568 ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
570 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
571 ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format. Aborting.\n");
573 }
576}
static char * app
Definition: app_festival.c:87
static int festival_exec(struct ast_channel *chan, const char *vdata)
Definition: app_festival.c:279
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

References app, ast_config_destroy(), ast_config_load, ast_log, AST_MODULE_LOAD_DECLINE, ast_register_application_xml, CONFIG_STATUS_FILEINVALID, FESTIVAL_CONFIG, festival_exec(), LOG_ERROR, and LOG_WARNING.

◆ send_waveform_to_channel()

static int send_waveform_to_channel ( struct ast_channel chan,
char *  waveform,
int  length,
char *  intkeys 
)
static

Definition at line 174 of file app_festival.c.

175{
176 int res = 0;
177 int fds[2];
178 int needed = 0;
179 struct ast_format *owriteformat;
180 struct ast_frame *f;
181 struct myframe {
182 struct ast_frame f;
184 char frdata[2048];
185 } myf = {
186 .f = { 0, },
187 };
188
189 if (pipe(fds)) {
190 ast_log(LOG_WARNING, "Unable to create pipe\n");
191 return -1;
192 }
193
194 /* Answer if it's not already going */
195 if (ast_channel_state(chan) != AST_STATE_UP)
196 ast_answer(chan);
197 ast_stopstream(chan);
198 ast_indicate(chan, -1);
199
200 owriteformat = ao2_bump(ast_channel_writeformat(chan));
202 if (res < 0) {
203 ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
204 ao2_cleanup(owriteformat);
205 return -1;
206 }
207
208 myf.f.frametype = AST_FRAME_VOICE;
209 myf.f.subclass.format = ast_format_slin;
210 myf.f.offset = AST_FRIENDLY_OFFSET;
211 myf.f.src = __PRETTY_FUNCTION__;
212 myf.f.data.ptr = myf.frdata;
213
214 res = send_waveform_to_fd(waveform, length, fds[1]);
215 if (res >= 0) {
216 /* Order is important -- there's almost always going to be mp3... we want to prioritize the
217 user */
218 for (;;) {
219 res = ast_waitfor(chan, 1000);
220 if (res < 1) {
221 res = -1;
222 break;
223 }
224 f = ast_read(chan);
225 if (!f) {
226 ast_log(LOG_WARNING, "Null frame == hangup() detected\n");
227 res = -1;
228 break;
229 }
230 if (f->frametype == AST_FRAME_DTMF) {
231 ast_debug(1, "User pressed a key\n");
232 if (intkeys && strchr(intkeys, f->subclass.integer)) {
233 res = f->subclass.integer;
234 ast_frfree(f);
235 break;
236 }
237 }
238 if (f->frametype == AST_FRAME_VOICE) {
239 /* Treat as a generator */
240 needed = f->samples * 2;
241 if (needed > sizeof(myf.frdata)) {
242 ast_log(LOG_WARNING, "Only able to deliver %d of %d requested samples\n",
243 (int)sizeof(myf.frdata) / 2, needed/2);
244 needed = sizeof(myf.frdata);
245 }
246 res = read(fds[0], myf.frdata, needed);
247 if (res > 0) {
248 myf.f.datalen = res;
249 myf.f.samples = res / 2;
250 if (ast_write(chan, &myf.f) < 0) {
251 res = -1;
252 ast_frfree(f);
253 break;
254 }
255 if (res < needed) { /* last frame */
256 ast_debug(1, "Last frame\n");
257 res = 0;
258 ast_frfree(f);
259 break;
260 }
261 } else {
262 ast_debug(1, "No more waveform\n");
263 res = 0;
264 }
265 }
266 ast_frfree(f);
267 }
268 }
269 close(fds[0]);
270 close(fds[1]);
271
272 if (!res && owriteformat)
273 ast_set_write_format(chan, owriteformat);
274 ao2_cleanup(owriteformat);
275
276 return res;
277}
static int send_waveform_to_fd(char *waveform, int length, int fd)
Definition: app_festival.c:140
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3162
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5144
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4257
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5803
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2805
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4277
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
#define AST_FRAME_DTMF
#define ast_frfree(fr)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
@ AST_FRAME_VOICE
Definition of a media format.
Definition: format.c:43
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype

References ao2_bump, ao2_cleanup, ast_answer(), ast_channel_writeformat(), ast_debug, ast_format_slin, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frfree, AST_FRIENDLY_OFFSET, ast_indicate(), ast_log, ast_read(), ast_set_write_format(), AST_STATE_UP, ast_stopstream(), ast_waitfor(), ast_write(), ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, ast_frame::offset, ast_frame::samples, send_waveform_to_fd(), and ast_frame::subclass.

Referenced by festival_exec().

◆ send_waveform_to_fd()

static int send_waveform_to_fd ( char *  waveform,
int  length,
int  fd 
)
static

Definition at line 140 of file app_festival.c.

141{
142 int res;
143#if __BYTE_ORDER == __BIG_ENDIAN
144 int x;
145 char c;
146#endif
147
148 res = ast_safe_fork(0);
149 if (res < 0)
150 ast_log(LOG_WARNING, "Fork failed\n");
151 if (res) {
152 return res;
153 }
154 dup2(fd, 0);
158#if __BYTE_ORDER == __BIG_ENDIAN
159 for (x = 0; x < length; x += 2) {
160 c = *(waveform + x + 1);
161 *(waveform + x + 1) = *(waveform + x);
162 *(waveform + x) = c;
163 }
164#endif
165
166 if (write(0, waveform, length) < 0) {
167 /* Cannot log -- all FDs are already closed */
168 }
169
170 close(fd);
171 _exit(0);
172}
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
Definition: asterisk.c:1837
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child.
Definition: main/app.c:3197
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
Definition: main/app.c:3192
#define ast_opt_high_priority
Definition: options.h:112
static struct test_val c

References ast_close_fds_above_n(), ast_log, ast_opt_high_priority, ast_safe_fork(), ast_set_priority(), c, and LOG_WARNING.

Referenced by send_waveform_to_channel().

◆ socket_receive_file_to_buff()

static char * socket_receive_file_to_buff ( int  fd,
int *  size 
)
static

Definition at line 89 of file app_festival.c.

90{
91 /* Receive file (probably a waveform file) from socket using
92 * Festival key stuff technique, but long winded I know, sorry
93 * but will receive any file without closing the stream or
94 * using OOB data
95 */
96 static char *file_stuff_key = "ft_StUfF_key"; /* must == Festival's key */
97 char *buff, *tmp;
98 int bufflen;
99 int n,k,i;
100 char c;
101
102 bufflen = 1024;
103 if (!(buff = ast_malloc(bufflen)))
104 return NULL;
105 *size = 0;
106
107 for (k = 0; file_stuff_key[k] != '\0';) {
108 n = read(fd, &c, 1);
109 if (n == 0)
110 break; /* hit stream eof before end of file */
111 if ((*size) + k + 1 >= bufflen) {
112 /* +1 so you can add a terminating NULL if you want */
113 bufflen += bufflen / 4;
114 if (!(tmp = ast_realloc(buff, bufflen))) {
115 ast_free(buff);
116 return NULL;
117 }
118 buff = tmp;
119 }
120 if (file_stuff_key[k] == c)
121 k++;
122 else if ((c == 'X') && (file_stuff_key[k+1] == '\0')) {
123 /* It looked like the key but wasn't */
124 for (i = 0; i < k; i++, (*size)++)
125 buff[*size] = file_stuff_key[i];
126 k = 0;
127 /* omit the stuffed 'X' */
128 } else {
129 for (i = 0; i < k; i++, (*size)++)
130 buff[*size] = file_stuff_key[i];
131 k = 0;
132 buff[*size] = c;
133 (*size)++;
134 }
135 }
136
137 return buff;
138}
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:226
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
static int tmp()
Definition: bt_open.c:389
static unsigned char * buff
Definition: chan_unistim.c:259
#define NULL
Definition: resample.c:96

References ast_free, ast_malloc, ast_realloc, buff, c, NULL, and tmp().

Referenced by festival_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 548 of file app_festival.c.

549{
551}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, and ast_unregister_application().

Variable Documentation

◆ app

char* app = "Festival"
static

Definition at line 87 of file app_festival.c.

Referenced by load_module(), and unload_module().