[packages] nzbget: fix compilation against OpenSSL v1.x (#8893)
[openwrt/svn-archive/archive.git] / net / asterisk-1.4.x / patches / 015-spandsp-app_fax.patch
1 --- /dev/null
2 +++ b/apps/app_rxfax.c
3 @@ -0,0 +1,376 @@
4 +/*
5 + * Asterisk -- A telephony toolkit for Linux.
6 + *
7 + * Trivial application to receive a TIFF FAX file
8 + *
9 + * Copyright (C) 2003, Steve Underwood
10 + *
11 + * Steve Underwood <steveu@coppice.org>
12 + *
13 + * This program is free software, distributed under the terms of
14 + * the GNU General Public License
15 + */
16 +
17 +/*** MODULEINFO
18 + <depend>spandsp</depend>
19 +***/
20 +
21 +#include "asterisk.h"
22 +
23 +ASTERISK_FILE_VERSION(__FILE__, "$Revision:$")
24 +
25 +#include <string.h>
26 +#include <stdlib.h>
27 +#include <stdio.h>
28 +#include <inttypes.h>
29 +#include <pthread.h>
30 +#include <errno.h>
31 +#include <tiffio.h>
32 +
33 +#include <spandsp.h>
34 +
35 +#include "asterisk/lock.h"
36 +#include "asterisk/file.h"
37 +#include "asterisk/logger.h"
38 +#include "asterisk/channel.h"
39 +#include "asterisk/pbx.h"
40 +#include "asterisk/module.h"
41 +#include "asterisk/translate.h"
42 +#include "asterisk/dsp.h"
43 +#include "asterisk/manager.h"
44 +
45 +static char *app = "RxFAX";
46 +
47 +static char *synopsis = "Receive a FAX to a file";
48 +
49 +static char *descrip =
50 +" RxFAX(filename[|caller][|debug]): Receives a FAX from the channel into the\n"
51 +"given filename. If the file exists it will be overwritten. The file\n"
52 +"should be in TIFF/F format.\n"
53 +"The \"caller\" option makes the application behave as a calling machine,\n"
54 +"rather than the answering machine. The default behaviour is to behave as\n"
55 +"an answering machine.\n"
56 +"Uses LOCALSTATIONID to identify itself to the remote end.\n"
57 +" LOCALHEADERINFO to generate a header line on each page.\n"
58 +"Sets REMOTESTATIONID to the sender CSID.\n"
59 +" FAXPAGES to the number of pages received.\n"
60 +" FAXBITRATE to the transmition rate.\n"
61 +" FAXRESOLUTION to the resolution.\n"
62 +"Returns -1 when the user hangs up.\n"
63 +"Returns 0 otherwise.\n";
64 +
65 +#define MAX_BLOCK_SIZE 240
66 +
67 +static void span_message(int level, const char *msg)
68 +{
69 + int ast_level;
70 +
71 + if (level == SPAN_LOG_WARNING)
72 + ast_level = __LOG_WARNING;
73 + else if (level == SPAN_LOG_WARNING)
74 + ast_level = __LOG_WARNING;
75 + else
76 + ast_level = __LOG_DEBUG;
77 + ast_log(ast_level, __FILE__, __LINE__, __PRETTY_FUNCTION__, msg);
78 +}
79 +/*- End of function --------------------------------------------------------*/
80 +
81 +static void t30_flush(t30_state_t *s, int which)
82 +{
83 + /* TODO: */
84 +}
85 +/*- End of function --------------------------------------------------------*/
86 +
87 +static void phase_e_handler(t30_state_t *s, void *user_data, int result)
88 +{
89 + struct ast_channel *chan;
90 + t30_stats_t t;
91 + char local_ident[21];
92 + char far_ident[21];
93 + char buf[11];
94 +
95 + chan = (struct ast_channel *) user_data;
96 + if (result == T30_ERR_OK)
97 + {
98 + t30_get_transfer_statistics(s, &t);
99 + t30_get_far_ident(s, far_ident);
100 + t30_get_local_ident(s, local_ident);
101 + ast_log(LOG_DEBUG, "==============================================================================\n");
102 + ast_log(LOG_DEBUG, "Fax successfully received.\n");
103 + ast_log(LOG_DEBUG, "Remote station id: %s\n", far_ident);
104 + ast_log(LOG_DEBUG, "Local station id: %s\n", local_ident);
105 + ast_log(LOG_DEBUG, "Pages transferred: %i\n", t.pages_transferred);
106 + ast_log(LOG_DEBUG, "Image resolution: %i x %i\n", t.x_resolution, t.y_resolution);
107 + ast_log(LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
108 + ast_log(LOG_DEBUG, "==============================================================================\n");
109 + manager_event(EVENT_FLAG_CALL,
110 + "FaxReceived", "Channel: %s\nExten: %s\nCallerID: %s\nRemoteStationID: %s\nLocalStationID: %s\nPagesTransferred: %i\nResolution: %i\nTransferRate: %i\nFileName: %s\n",
111 + chan->name,
112 + chan->exten,
113 + (chan->cid.cid_num) ? chan->cid.cid_num : "",
114 + far_ident,
115 + local_ident,
116 + t.pages_transferred,
117 + t.y_resolution,
118 + t.bit_rate,
119 + s->rx_file);
120 + pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident);
121 + snprintf(buf, sizeof(buf), "%i", t.pages_transferred);
122 + pbx_builtin_setvar_helper(chan, "FAXPAGES", buf);
123 + snprintf(buf, sizeof(buf), "%i", t.y_resolution);
124 + pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", buf);
125 + snprintf(buf, sizeof(buf), "%i", t.bit_rate);
126 + pbx_builtin_setvar_helper(chan, "FAXBITRATE", buf);
127 + }
128 + else
129 + {
130 + ast_log(LOG_DEBUG, "==============================================================================\n");
131 + ast_log(LOG_DEBUG, "Fax receive not successful - result (%d) %s.\n", result, t30_completion_code_to_str(result));
132 + ast_log(LOG_DEBUG, "==============================================================================\n");
133 + }
134 +}
135 +/*- End of function --------------------------------------------------------*/
136 +
137 +static void phase_d_handler(t30_state_t *s, void *user_data, int result)
138 +{
139 + struct ast_channel *chan;
140 + t30_stats_t t;
141 +
142 + chan = (struct ast_channel *) user_data;
143 + if (result)
144 + {
145 + t30_get_transfer_statistics(s, &t);
146 + ast_log(LOG_DEBUG, "==============================================================================\n");
147 + ast_log(LOG_DEBUG, "Pages transferred: %i\n", t.pages_transferred);
148 + ast_log(LOG_DEBUG, "Image size: %i x %i\n", t.width, t.length);
149 + ast_log(LOG_DEBUG, "Image resolution %i x %i\n", t.x_resolution, t.y_resolution);
150 + ast_log(LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
151 + ast_log(LOG_DEBUG, "Bad rows %i\n", t.bad_rows);
152 + ast_log(LOG_DEBUG, "Longest bad row run %i\n", t.longest_bad_row_run);
153 + ast_log(LOG_DEBUG, "Compression type %i\n", t.encoding);
154 + ast_log(LOG_DEBUG, "Image size (bytes) %i\n", t.image_size);
155 + ast_log(LOG_DEBUG, "==============================================================================\n");
156 + }
157 +}
158 +/*- End of function --------------------------------------------------------*/
159 +
160 +static int rxfax_exec(struct ast_channel *chan, void *data)
161 +{
162 + int res = 0;
163 + char template_file[256];
164 + char target_file[256];
165 + char *s;
166 + char *t;
167 + char *v;
168 + const char *x;
169 + int option;
170 + int len;
171 + int i;
172 + fax_state_t fax;
173 + int calling_party;
174 + int verbose;
175 + int samples;
176 +
177 + struct ast_module_user *u;
178 + struct ast_frame *inf = NULL;
179 + struct ast_frame outf;
180 +
181 + int original_read_fmt;
182 + int original_write_fmt;
183 +
184 + uint8_t __buf[sizeof(uint16_t)*MAX_BLOCK_SIZE + 2*AST_FRIENDLY_OFFSET];
185 + uint8_t *buf = __buf + AST_FRIENDLY_OFFSET;
186 +
187 + if (chan == NULL)
188 + {
189 + ast_log(LOG_WARNING, "Fax receive channel is NULL. Giving up.\n");
190 + return -1;
191 + }
192 +
193 + span_set_message_handler(span_message);
194 +
195 + /* The next few lines of code parse out the filename and header from the input string */
196 + if (data == NULL)
197 + {
198 + /* No data implies no filename or anything is present */
199 + ast_log(LOG_WARNING, "Rxfax requires an argument (filename)\n");
200 + return -1;
201 + }
202 +
203 + calling_party = FALSE;
204 + verbose = FALSE;
205 + target_file[0] = '\0';
206 +
207 + for (option = 0, v = s = data; v; option++, s++)
208 + {
209 + t = s;
210 + v = strchr(s, '|');
211 + s = (v) ? v : s + strlen(s);
212 + strncpy((char *) buf, t, s - t);
213 + buf[s - t] = '\0';
214 + if (option == 0)
215 + {
216 + /* The first option is always the file name */
217 + len = s - t;
218 + if (len > 255)
219 + len = 255;
220 + strncpy(target_file, t, len);
221 + target_file[len] = '\0';
222 + /* Allow the use of %d in the file name for a wild card of sorts, to
223 + create a new file with the specified name scheme */
224 + if ((x = strchr(target_file, '%')) && x[1] == 'd')
225 + {
226 + strcpy(template_file, target_file);
227 + i = 0;
228 + do
229 + {
230 + snprintf(target_file, 256, template_file, 1);
231 + i++;
232 + }
233 + while (ast_fileexists(target_file, "", chan->language) != -1);
234 + }
235 + }
236 + else if (strncmp("caller", t, s - t) == 0)
237 + {
238 + calling_party = TRUE;
239 + }
240 + else if (strncmp("debug", t, s - t) == 0)
241 + {
242 + verbose = TRUE;
243 + }
244 + }
245 +
246 + /* Done parsing */
247 +
248 + u = ast_module_user_add(chan);
249 +
250 + if (chan->_state != AST_STATE_UP)
251 + {
252 + /* Shouldn't need this, but checking to see if channel is already answered
253 + * Theoretically asterisk should already have answered before running the app */
254 + res = ast_answer(chan);
255 + }
256 +
257 + if (!res)
258 + {
259 + original_read_fmt = chan->readformat;
260 + if (original_read_fmt != AST_FORMAT_SLINEAR)
261 + {
262 + res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
263 + if (res < 0)
264 + {
265 + ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
266 + return -1;
267 + }
268 + }
269 + original_write_fmt = chan->writeformat;
270 + if (original_write_fmt != AST_FORMAT_SLINEAR)
271 + {
272 + res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
273 + if (res < 0)
274 + {
275 + ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
276 + res = ast_set_read_format(chan, original_read_fmt);
277 + if (res)
278 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
279 + return -1;
280 + }
281 + }
282 + fax_init(&fax, calling_party);
283 + if (verbose)
284 + fax.logging.level = SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW;
285 + x = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
286 + if (x && x[0])
287 + t30_set_local_ident(&fax.t30_state, x);
288 + x = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO");
289 + if (x && x[0])
290 + t30_set_header_info(&fax.t30_state, x);
291 + t30_set_rx_file(&fax.t30_state, target_file, -1);
292 + //t30_set_phase_b_handler(&fax.t30_state, phase_b_handler, chan);
293 + t30_set_phase_d_handler(&fax.t30_state, phase_d_handler, chan);
294 + t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, chan);
295 + t30_set_ecm_capability(&fax.t30_state, TRUE);
296 + t30_set_supported_compressions(&fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
297 + while (ast_waitfor(chan, -1) > -1)
298 + {
299 + inf = ast_read(chan);
300 + if (inf == NULL)
301 + {
302 + res = -1;
303 + break;
304 + }
305 + if (inf->frametype == AST_FRAME_VOICE)
306 + {
307 + if (fax_rx(&fax, inf->data, inf->samples))
308 + break;
309 + samples = (inf->samples <= MAX_BLOCK_SIZE) ? inf->samples : MAX_BLOCK_SIZE;
310 + len = fax_tx(&fax, (int16_t *) &buf[AST_FRIENDLY_OFFSET], samples);
311 + if (len)
312 + {
313 + memset(&outf, 0, sizeof(outf));
314 + outf.frametype = AST_FRAME_VOICE;
315 + outf.subclass = AST_FORMAT_SLINEAR;
316 + outf.datalen = len*sizeof(int16_t);
317 + outf.samples = len;
318 + outf.data = &buf[AST_FRIENDLY_OFFSET];
319 + outf.offset = AST_FRIENDLY_OFFSET;
320 + outf.src = "RxFAX";
321 + if (ast_write(chan, &outf) < 0)
322 + {
323 + ast_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
324 + break;
325 + }
326 + }
327 + }
328 + ast_frfree(inf);
329 + }
330 + if (inf == NULL)
331 + {
332 + ast_log(LOG_DEBUG, "Got hangup\n");
333 + res = -1;
334 + }
335 + if (original_read_fmt != AST_FORMAT_SLINEAR)
336 + {
337 + res = ast_set_read_format(chan, original_read_fmt);
338 + if (res)
339 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
340 + }
341 + if (original_write_fmt != AST_FORMAT_SLINEAR)
342 + {
343 + res = ast_set_write_format(chan, original_write_fmt);
344 + if (res)
345 + ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", chan->name);
346 + }
347 + t30_terminate(&fax.t30_state);
348 + }
349 + else
350 + {
351 + ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
352 + }
353 + ast_module_user_remove(u);
354 + return res;
355 +}
356 +/*- End of function --------------------------------------------------------*/
357 +
358 +static int unload_module(void)
359 +{
360 + int res;
361 +
362 + ast_module_user_hangup_all();
363 +
364 + res = ast_unregister_application(app);
365 +
366 +
367 + return res;
368 +}
369 +/*- End of function --------------------------------------------------------*/
370 +
371 +static int load_module(void)
372 +{
373 + return ast_register_application(app, rxfax_exec, synopsis, descrip);
374 +}
375 +/*- End of function --------------------------------------------------------*/
376 +
377 +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Trivial FAX Receive Application");
378 +
379 +/*- End of file ------------------------------------------------------------*/
380 --- /dev/null
381 +++ b/apps/app_txfax.c
382 @@ -0,0 +1,303 @@
383 +/*
384 + * Asterisk -- A telephony toolkit for Linux.
385 + *
386 + * Trivial application to send a TIFF file as a FAX
387 + *
388 + * Copyright (C) 2003, Steve Underwood
389 + *
390 + * Steve Underwood <steveu@coppice.org>
391 + *
392 + * This program is free software, distributed under the terms of
393 + * the GNU General Public License
394 + */
395 +
396 +/*** MODULEINFO
397 + <depend>spandsp</depend>
398 +***/
399 +
400 +#include "asterisk.h"
401 +
402 +ASTERISK_FILE_VERSION(__FILE__, "$Revision:$")
403 +
404 +#include <string.h>
405 +#include <stdlib.h>
406 +#include <stdio.h>
407 +#include <inttypes.h>
408 +#include <pthread.h>
409 +#include <errno.h>
410 +#include <tiffio.h>
411 +
412 +#include <spandsp.h>
413 +
414 +#include "asterisk/lock.h"
415 +#include "asterisk/file.h"
416 +#include "asterisk/logger.h"
417 +#include "asterisk/channel.h"
418 +#include "asterisk/pbx.h"
419 +#include "asterisk/module.h"
420 +#include "asterisk/translate.h"
421 +
422 +static char *app = "TxFAX";
423 +
424 +static char *synopsis = "Send a FAX file";
425 +
426 +static char *descrip =
427 +" TxFAX(filename[|caller][|debug]): Send a given TIFF file to the channel as a FAX.\n"
428 +"The \"caller\" option makes the application behave as a calling machine,\n"
429 +"rather than the answering machine. The default behaviour is to behave as\n"
430 +"an answering machine.\n"
431 +"Uses LOCALSTATIONID to identify itself to the remote end.\n"
432 +" LOCALHEADERINFO to generate a header line on each page.\n"
433 +"Sets REMOTESTATIONID to the receiver CSID.\n"
434 +"Returns -1 when the user hangs up, or if the file does not exist.\n"
435 +"Returns 0 otherwise.\n";
436 +
437 +#define MAX_BLOCK_SIZE 240
438 +
439 +static void span_message(int level, const char *msg)
440 +{
441 + int ast_level;
442 +
443 + if (level == SPAN_LOG_WARNING)
444 + ast_level = __LOG_WARNING;
445 + else if (level == SPAN_LOG_WARNING)
446 + ast_level = __LOG_WARNING;
447 + else
448 + ast_level = __LOG_DEBUG;
449 + ast_log(ast_level, __FILE__, __LINE__, __PRETTY_FUNCTION__, msg);
450 +}
451 +/*- End of function --------------------------------------------------------*/
452 +
453 +#if 0
454 +static void t30_flush(t30_state_t *s, int which)
455 +{
456 + /* TODO: */
457 +}
458 +/*- End of function --------------------------------------------------------*/
459 +#endif
460 +
461 +static void phase_e_handler(t30_state_t *s, void *user_data, int result)
462 +{
463 + struct ast_channel *chan;
464 + char far_ident[21];
465 +
466 + chan = (struct ast_channel *) user_data;
467 + if (result == T30_ERR_OK)
468 + {
469 + t30_get_far_ident(s, far_ident);
470 + pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident);
471 + }
472 + else
473 + {
474 + ast_log(LOG_DEBUG, "==============================================================================\n");
475 + ast_log(LOG_DEBUG, "Fax send not successful - result (%d) %s.\n", result, t30_completion_code_to_str(result));
476 + ast_log(LOG_DEBUG, "==============================================================================\n");
477 + }
478 +}
479 +/*- End of function --------------------------------------------------------*/
480 +
481 +static int txfax_exec(struct ast_channel *chan, void *data)
482 +{
483 + int res = 0;
484 + char source_file[256];
485 + char *s;
486 + char *t;
487 + char *v;
488 + const char *x;
489 + int option;
490 + int len;
491 + fax_state_t fax;
492 + int calling_party;
493 + int verbose;
494 + int samples;
495 +
496 + struct ast_module_user *u;
497 + struct ast_frame *inf = NULL;
498 + struct ast_frame outf;
499 +
500 + int original_read_fmt;
501 + int original_write_fmt;
502 +
503 + uint8_t __buf[sizeof(uint16_t)*MAX_BLOCK_SIZE + 2*AST_FRIENDLY_OFFSET];
504 + uint8_t *buf = __buf + AST_FRIENDLY_OFFSET;
505 +
506 + if (chan == NULL)
507 + {
508 + ast_log(LOG_WARNING, "Fax transmit channel is NULL. Giving up.\n");
509 + return -1;
510 + }
511 +
512 + span_set_message_handler(span_message);
513 +
514 + /* The next few lines of code parse out the filename and header from the input string */
515 + if (data == NULL)
516 + {
517 + /* No data implies no filename or anything is present */
518 + ast_log(LOG_WARNING, "Txfax requires an argument (filename)\n");
519 + return -1;
520 + }
521 +
522 + calling_party = FALSE;
523 + verbose = FALSE;
524 + source_file[0] = '\0';
525 +
526 + for (option = 0, v = s = data; v; option++, s++)
527 + {
528 + t = s;
529 + v = strchr(s, '|');
530 + s = (v) ? v : s + strlen(s);
531 + strncpy((char *) buf, t, s - t);
532 + buf[s - t] = '\0';
533 + if (option == 0)
534 + {
535 + /* The first option is always the file name */
536 + len = s - t;
537 + if (len > 255)
538 + len = 255;
539 + strncpy(source_file, t, len);
540 + source_file[len] = '\0';
541 + }
542 + else if (strncmp("caller", t, s - t) == 0)
543 + {
544 + calling_party = TRUE;
545 + }
546 + else if (strncmp("debug", t, s - t) == 0)
547 + {
548 + verbose = TRUE;
549 + }
550 + }
551 +
552 + /* Done parsing */
553 +
554 + u = ast_module_user_add(chan);
555 +
556 + if (chan->_state != AST_STATE_UP)
557 + {
558 + /* Shouldn't need this, but checking to see if channel is already answered
559 + * Theoretically asterisk should already have answered before running the app */
560 + res = ast_answer(chan);
561 + }
562 +
563 + if (!res)
564 + {
565 + original_read_fmt = chan->readformat;
566 + if (original_read_fmt != AST_FORMAT_SLINEAR)
567 + {
568 + res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
569 + if (res < 0)
570 + {
571 + ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
572 + return -1;
573 + }
574 + }
575 + original_write_fmt = chan->writeformat;
576 + if (original_write_fmt != AST_FORMAT_SLINEAR)
577 + {
578 + res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
579 + if (res < 0)
580 + {
581 + ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
582 + res = ast_set_read_format(chan, original_read_fmt);
583 + if (res)
584 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
585 + return -1;
586 + }
587 + }
588 + fax_init(&fax, calling_party);
589 + if (verbose)
590 + fax.logging.level = SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW;
591 +
592 + x = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
593 + if (x && x[0])
594 + t30_set_local_ident(&fax.t30_state, x);
595 + x = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO");
596 + if (x && x[0])
597 + t30_set_header_info(&fax.t30_state, x);
598 + t30_set_tx_file(&fax.t30_state, source_file, -1, -1);
599 + //t30_set_phase_b_handler(&fax.t30_state, phase_b_handler, chan);
600 + //t30_set_phase_d_handler(&fax.t30_state, phase_d_handler, chan);
601 + t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, chan);
602 + t30_set_ecm_capability(&fax.t30_state, TRUE);
603 + t30_set_supported_compressions(&fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
604 + while (ast_waitfor(chan, -1) > -1)
605 + {
606 + inf = ast_read(chan);
607 + if (inf == NULL)
608 + {
609 + res = -1;
610 + break;
611 + }
612 + if (inf->frametype == AST_FRAME_VOICE)
613 + {
614 + if (fax_rx(&fax, inf->data, inf->samples))
615 + break;
616 + samples = (inf->samples <= MAX_BLOCK_SIZE) ? inf->samples : MAX_BLOCK_SIZE;
617 + len = fax_tx(&fax, (int16_t *) &buf[AST_FRIENDLY_OFFSET], samples);
618 + if (len)
619 + {
620 + memset(&outf, 0, sizeof(outf));
621 + outf.frametype = AST_FRAME_VOICE;
622 + outf.subclass = AST_FORMAT_SLINEAR;
623 + outf.datalen = len*sizeof(int16_t);
624 + outf.samples = len;
625 + outf.data = &buf[AST_FRIENDLY_OFFSET];
626 + outf.offset = AST_FRIENDLY_OFFSET;
627 + if (ast_write(chan, &outf) < 0)
628 + {
629 + ast_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
630 + break;
631 + }
632 + }
633 + }
634 + ast_frfree(inf);
635 + }
636 + if (inf == NULL)
637 + {
638 + ast_log(LOG_DEBUG, "Got hangup\n");
639 + res = -1;
640 + }
641 + if (original_read_fmt != AST_FORMAT_SLINEAR)
642 + {
643 + res = ast_set_read_format(chan, original_read_fmt);
644 + if (res)
645 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
646 + }
647 + if (original_write_fmt != AST_FORMAT_SLINEAR)
648 + {
649 + res = ast_set_write_format(chan, original_write_fmt);
650 + if (res)
651 + ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", chan->name);
652 + }
653 + t30_terminate(&fax.t30_state);
654 + }
655 + else
656 + {
657 + ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
658 + }
659 + ast_module_user_remove(u);
660 + return res;
661 +}
662 +/*- End of function --------------------------------------------------------*/
663 +
664 +static int unload_module(void)
665 +{
666 + int res;
667 +
668 + ast_module_user_hangup_all();
669 +
670 + res = ast_unregister_application(app);
671 +
672 +
673 + return res;
674 +}
675 +/*- End of function --------------------------------------------------------*/
676 +
677 +static int load_module(void)
678 +{
679 + return ast_register_application(app, txfax_exec, synopsis, descrip);
680 +}
681 +/*- End of function --------------------------------------------------------*/
682 +
683 +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Trivial FAX Transmit Application");
684 +
685 +/*- End of file ------------------------------------------------------------*/
686 --- a/build_tools/menuselect-deps.in
687 +++ b/build_tools/menuselect-deps.in
688 @@ -23,6 +23,7 @@ PGSQL=@PBX_PGSQL@
689 POPT=@PBX_POPT@
690 PRI=@PBX_PRI@
691 RADIUS=@PBX_RADIUS@
692 +SPANDSP=@PBX_SPANDSP@
693 SPEEX=@PBX_SPEEX@
694 SPEEXDSP=@PBX_SPEEXDSP@
695 SPEEX_PREPROCESS=@PBX_SPEEX_PREPROCESS@
696 --- a/configure.ac
697 +++ b/configure.ac
698 @@ -205,6 +205,7 @@ AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pr
699 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
700 AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
701 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
702 +AST_EXT_LIB_SETUP([SPANDSP], [spandsp Library], [spandsp])
703 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
704 AST_EXT_LIB_SETUP([SPEEXDSP], [Speexdsp], [speexdsp])
705 AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
706 @@ -1359,6 +1360,8 @@ fi
707
708 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
709
710 +AST_EXT_LIB_CHECK([SPANDSP], [spandsp], [fax_init], [spandsp.h], [-ltiff -ljpeg -lz])
711 +
712 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
713
714 # See if the main speex library contains the preprocess functions
715 --- a/include/asterisk/plc.h
716 +++ b/include/asterisk/plc.h
717 @@ -1,18 +1,17 @@
718 -/*! \file
719 - * \brief SpanDSP - a series of DSP components for telephony
720 +/*
721 + * SpanDSP - a series of DSP components for telephony
722 *
723 * plc.h
724 *
725 - * \author Steve Underwood <steveu@coppice.org>
726 + * Written by Steve Underwood <steveu@coppice.org>
727 *
728 * Copyright (C) 2004 Steve Underwood
729 *
730 * All rights reserved.
731 *
732 * This program is free software; you can redistribute it and/or modify
733 - * it under the terms of the GNU General Public License as published by
734 - * the Free Software Foundation; either version 2 of the License, or
735 - * (at your option) any later version.
736 + * it under the terms of the GNU General Public License version 2, as
737 + * published by the Free Software Foundation.
738 *
739 * This program is distributed in the hope that it will be useful,
740 * but WITHOUT ANY WARRANTY; without even the implied warranty of
741 @@ -23,37 +22,36 @@
742 * along with this program; if not, write to the Free Software
743 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
744 *
745 - * This version may be optionally licenced under the GNU LGPL licence.
746 - *
747 - * A license has been granted to Digium (via disclaimer) for the use of
748 - * this code.
749 + * $Id: plc.h,v 1.15 2007/04/08 08:16:18 steveu Exp $
750 */
751
752 +/*! \file */
753
754 -#if !defined(_PLC_H_)
755 -#define _PLC_H_
756 -
757 -#ifdef SOLARIS
758 -#include <sys/int_types.h>
759 -#else
760 -#if defined(__OpenBSD__) || defined( __FreeBSD__)
761 -#include <inttypes.h>
762 -#else
763 -#include <stdint.h>
764 -#endif
765 -#endif
766 +#if !defined(_SPANDSP_PLC_H_)
767 +#define _SPANDSP_PLC_H_
768
769 /*! \page plc_page Packet loss concealment
770 \section plc_page_sec_1 What does it do?
771 -The packet loss concealment module provides a suitable synthetic fill-in signal,
772 -to minimise the audible effect of lost packets in VoIP applications. It is not
773 -tied to any particular codec, and could be used with almost any codec which does not
774 +The packet loss concealment module provides a synthetic fill-in signal, to minimise
775 +the audible effect of lost packets in VoIP applications. It is not tied to any
776 +particular codec, and could be used with almost any codec which does not
777 specify its own procedure for packet loss concealment.
778
779 -Where a codec specific concealment procedure exists, the algorithm is usually built
780 +Where a codec specific concealment procedure exists, that algorithm is usually built
781 around knowledge of the characteristics of the particular codec. It will, therefore,
782 generally give better results for that particular codec than this generic concealer will.
783
784 +The PLC code implements an algorithm similar to the one described in Appendix 1 of G.711.
785 +However, the G.711 algorithm is optimised for 10ms packets. Few people use such small
786 +packets. 20ms is a much more common value, and longer packets are also quite common. The
787 +algorithm has been adjusted with this in mind. Also, the G.711 approach causes an
788 +algorithmic delay, and requires significant buffer manipulation when there is no packet
789 +loss. The algorithm used here avoids this. It causes no delay, and achieves comparable
790 +quality with normal speech.
791 +
792 +Note that both this algorithm, and the one in G.711 are optimised for speech. For most kinds
793 +of music a much slower decay on bursts of lost packets give better results.
794 +
795 \section plc_page_sec_2 How does it work?
796 While good packets are being received, the plc_rx() routine keeps a record of the trailing
797 section of the known speech signal. If a packet is missed, plc_fillin() is called to produce
798 @@ -83,7 +81,7 @@ are needed to obtain smooth pleasant sou
799 correct steadily fall. Therefore, the volume of the synthesized signal is made to decay
800 linearly, such that after 50ms of missing audio it is reduced to silence.
801
802 -- When real speech resumes, an extra 1/4 pitch period of sythetic speech is blended with the
803 +- When real speech resumes, an extra 1/4 pitch period of synthetic speech is blended with the
804 start of the real speech. If the erasure is small, this smoothes the transition. If the erasure
805 is long, and the synthetic signal has faded to zero, the blending softens the start up of the
806 real signal, avoiding a kind of "click" or "pop" effect that might occur with a sudden onset.
807 @@ -110,6 +108,9 @@ That's it!
808 the pitch assessment. */
809 #define PLC_HISTORY_LEN (CORRELATION_SPAN + PLC_PITCH_MIN)
810
811 +/*!
812 + The generic packet loss concealer context.
813 +*/
814 typedef struct
815 {
816 /*! Consecutive erased samples */
817 @@ -127,12 +128,13 @@ typedef struct
818 } plc_state_t;
819
820
821 -#ifdef __cplusplus
822 -extern "C" {
823 +#if defined(__cplusplus)
824 +extern "C"
825 +{
826 #endif
827
828 -/*! Process a block of received audio samples.
829 - \brief Process a block of received audio samples.
830 +/*! Process a block of received audio samples for PLC.
831 + \brief Process a block of received audio samples for PLC.
832 \param s The packet loss concealer context.
833 \param amp The audio sample buffer.
834 \param len The number of samples in the buffer.
835 @@ -147,13 +149,18 @@ int plc_rx(plc_state_t *s, int16_t amp[]
836 \return The number of samples synthesized. */
837 int plc_fillin(plc_state_t *s, int16_t amp[], int len);
838
839 -/*! Process a block of received V.29 modem audio samples.
840 - \brief Process a block of received V.29 modem audio samples.
841 +/*! Initialise a packet loss concealer context.
842 + \brief Initialise a PLC context.
843 \param s The packet loss concealer context.
844 - \return A pointer to the he packet loss concealer context. */
845 + \return A pointer to the the packet loss concealer context. */
846 plc_state_t *plc_init(plc_state_t *s);
847
848 -#ifdef __cplusplus
849 +/*! Free a packet loss concealer context.
850 + \param s The packet loss concealer context.
851 + \return 0 for OK. */
852 +int plc_release(plc_state_t *s);
853 +
854 +#if defined(__cplusplus)
855 }
856 #endif
857
858 --- a/makeopts.in
859 +++ b/makeopts.in
860 @@ -141,6 +141,9 @@ PWLIB_LIB=@PWLIB_LIB@
861 RADIUS_INCLUDE=@RADIUS_INCLUDE@
862 RADIUS_LIB=@RADIUS_LIB@
863
864 +SPANDSP_INCLUDE=@SPANDSP_INCLUDE@
865 +SPANDSP_LIB=@SPANDSP_LIB@
866 +
867 SPEEX_INCLUDE=@SPEEX_INCLUDE@
868 SPEEX_LIB=@SPEEX_LIB@
869