Asterisk - The Open Source Telephony Project  18.5.0
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.

Referenced by festival_exec(), and load_module().

◆ MAXFESTLEN

#define MAXFESTLEN   2048

Definition at line 68 of file app_festival.c.

Referenced by festival_exec().

◆ 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"   
)

Referenced by load_module().

◆ festival_exec()

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

Definition at line 279 of file app_festival.c.

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_gethostbyname(), ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, ast_true(), ast_variable_retrieve(), CONFIG_STATUS_FILEINVALID, errno, FESTIVAL_CONFIG, host, LOG_ERROR, LOG_WARNING, MAXFESTLEN, MD5Final(), MD5Init(), MD5Update(), NULL, send_waveform_to_channel(), socket_receive_file_to_buff(), and text.

Referenced by load_module().

280 {
281  int usecache;
282  int res = 0;
283  struct sockaddr_in serv_addr;
284  struct hostent *serverhost;
285  struct ast_hostent ahp;
286  int fd;
287  FILE *fs;
288  const char *host;
289  const char *cachedir;
290  const char *temp;
291  const char *festivalcommand;
292  int port = 1314;
293  int n;
294  char ack[4];
295  char *waveform;
296  int filesize;
297  char bigstring[MAXFESTLEN];
298  int i;
299  struct MD5Context md5ctx;
300  unsigned char MD5Res[16];
301  char MD5Hex[33] = "";
302  char koko[4] = "";
303  char cachefile[MAXFESTLEN]="";
304  int readcache = 0;
305  int writecache = 0;
306  int strln;
307  int fdesc = -1;
308  char buffer[16384];
309  int seekpos = 0;
310  char *data;
311  struct ast_config *cfg;
312  char *newfestivalcommand;
313  struct ast_flags config_flags = { 0 };
315  AST_APP_ARG(text);
316  AST_APP_ARG(interrupt);
317  );
318 
319  if (ast_strlen_zero(vdata)) {
320  ast_log(LOG_WARNING, "festival requires an argument (text)\n");
321  return -1;
322  }
323 
324  cfg = ast_config_load(FESTIVAL_CONFIG, config_flags);
325  if (!cfg) {
326  ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
327  return -1;
328  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
329  ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format. Aborting.\n");
330  return -1;
331  }
332 
333  if (!(host = ast_variable_retrieve(cfg, "general", "host"))) {
334  host = "localhost";
335  }
336  if (!(temp = ast_variable_retrieve(cfg, "general", "port"))) {
337  port = 1314;
338  } else {
339  port = atoi(temp);
340  }
341  if (!(temp = ast_variable_retrieve(cfg, "general", "usecache"))) {
342  usecache = 0;
343  } else {
344  usecache = ast_true(temp);
345  }
346  if (!(cachedir = ast_variable_retrieve(cfg, "general", "cachedir"))) {
347  cachedir = "/tmp/";
348  }
349 
350  data = ast_strdupa(vdata);
352 
353  if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) {
354  const char *startcmd = "(tts_textasterisk \"";
355  const char *endcmd = "\" 'file)(quit)\n";
356 
357  strln = strlen(startcmd) + strlen(args.text) + strlen(endcmd) + 1;
358  newfestivalcommand = ast_alloca(strln);
359  snprintf(newfestivalcommand, strln, "%s%s%s", startcmd, args.text, endcmd);
360  festivalcommand = newfestivalcommand;
361  } else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */
362  int x, j;
363  newfestivalcommand = ast_alloca(strlen(festivalcommand) + strlen(args.text) + 1);
364 
365  for (x = 0, j = 0; x < strlen(festivalcommand); x++) {
366  if (festivalcommand[x] == '\\' && festivalcommand[x + 1] == 'n') {
367  newfestivalcommand[j++] = '\n';
368  x++;
369  } else if (festivalcommand[x] == '\\') {
370  newfestivalcommand[j++] = festivalcommand[x + 1];
371  x++;
372  } else if (festivalcommand[x] == '%' && festivalcommand[x + 1] == 's') {
373  sprintf(&newfestivalcommand[j], "%s", args.text); /* we know it is big enough */
374  j += strlen(args.text);
375  x++;
376  } else
377  newfestivalcommand[j++] = festivalcommand[x];
378  }
379  newfestivalcommand[j] = '\0';
380  festivalcommand = newfestivalcommand;
381  }
382 
383  if (args.interrupt && !strcasecmp(args.interrupt, "any"))
384  args.interrupt = AST_DIGIT_ANY;
385 
386  ast_debug(1, "Text passed to festival server : %s\n", args.text);
387  /* Connect to local festival server */
388 
389  fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
390 
391  if (fd < 0) {
392  ast_log(LOG_WARNING, "festival_client: can't get socket\n");
393  ast_config_destroy(cfg);
394  return -1;
395  }
396 
397  memset(&serv_addr, 0, sizeof(serv_addr));
398 
399  if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) {
400  /* its a name rather than an ipnum */
401  serverhost = ast_gethostbyname(host, &ahp);
402 
403  if (serverhost == NULL) {
404  ast_log(LOG_WARNING, "festival_client: gethostbyname failed\n");
405  ast_config_destroy(cfg);
406  close(fd);
407  return -1;
408  }
409  memmove(&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
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");
417  ast_config_destroy(cfg);
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) + strlen(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);
517  ast_config_destroy(cfg);
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);
544  ast_config_destroy(cfg);
545  return res;
546 }
#define AST_DIGIT_ANY
Definition: file.h:48
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
#define CONFIG_STATUS_FILEINVALID
void MD5Final(unsigned char digest[16], struct MD5Context *context)
Definition: md5.c:120
char * text
Definition: app_queue.c:1508
const char * args
#define NULL
Definition: resample.c:96
#define AST_FILE_MODE
Definition: asterisk.h:32
static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length, char *intkeys)
Definition: app_festival.c:174
void MD5Init(struct MD5Context *context)
Definition: md5.c:57
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
static char host[256]
Definition: muted.c:77
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define MAXFESTLEN
Definition: app_festival.c:68
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
static struct ast_hostent ahp
Definition: chan_skinny.c:1235
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
Definition: md5.c:72
#define LOG_ERROR
Definition: logger.h:285
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
int errno
#define ast_free(a)
Definition: astmm.h:182
#define FESTIVAL_CONFIG
Definition: app_festival.c:66
Structure used to handle boolean flags.
Definition: utils.h:199
Definition: md5.h:26
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Definition: main/utils.c:197
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
static char * socket_receive_file_to_buff(int fd, int *size)
Definition: app_festival.c:89
#define AST_APP_ARG(name)
Define an application argument.

◆ 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.

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

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  }
574  ast_config_destroy(cfg);
576 }
static int festival_exec(struct ast_channel *chan, const char *vdata)
Definition: app_festival.c:279
#define LOG_WARNING
Definition: logger.h:274
#define CONFIG_STATUS_FILEINVALID
#define ast_log
Definition: astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define LOG_ERROR
Definition: logger.h:285
#define FESTIVAL_CONFIG
Definition: app_festival.c:66
static char * app
Definition: app_festival.c:87
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Structure used to handle boolean flags.
Definition: utils.h:199
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ 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.

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().

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 }
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4322
#define LOG_WARNING
Definition: logger.h:274
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
ast_channel_state
ast_channel states
Definition: channelstate.h:35
Definition of a media format.
Definition: format.c:43
#define AST_FRAME_DTMF
struct ast_frame_subclass subclass
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5890
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:5189
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_frfree(fr)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2814
Data structure associated with a single frame of data.
enum ast_frame_type frametype
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:187
static int send_waveform_to_fd(char *waveform, int length, int fd)
Definition: app_festival.c:140

◆ 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.

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().

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);
157  ast_set_priority(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 }
#define LOG_WARNING
Definition: logger.h:274
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:3042
static struct test_val c
#define ast_log
Definition: astobj2.c:42
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:1799
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:3047
#define ast_opt_high_priority
Definition: options.h:110

◆ 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.

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

Referenced by festival_exec().

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:228
static int tmp()
Definition: bt_open.c:389
static struct test_val c
#define NULL
Definition: resample.c:96
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define ast_free(a)
Definition: astmm.h:182
static unsigned char * buff
Definition: chan_unistim.c:259

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 548 of file app_festival.c.

References app, and ast_unregister_application().

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

Variable Documentation

◆ app

char* app = "Festival"
static

Definition at line 87 of file app_festival.c.

Referenced by load_module(), and unload_module().