Asterisk - The Open Source Telephony Project  18.5.0
app_tonedetect.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2021, Naveen Albert
5  *
6  * Naveen Albert <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Tone detection module
22  *
23  * \author Naveen Albert <[email protected]>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <support_level>extended</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 #include <math.h>
35 
36 #include "asterisk/module.h"
37 #include "asterisk/frame.h"
38 #include "asterisk/format_cache.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/dsp.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/audiohook.h"
43 #include "asterisk/app.h"
44 #include "asterisk/indications.h"
45 #include "asterisk/conversions.h"
46 
47 /*** DOCUMENTATION
48  <application name="WaitForTone" language="en_US">
49  <synopsis>
50  Wait for tone
51  </synopsis>
52  <syntax>
53  <parameter name="freq" required="true">
54  <para>Frequency of the tone to wait for. If the tone consists of
55  two frequencies, separate with the <literal>+</literal> symbol.
56  Detection may be less accurate for multiple frequencies.</para>
57  </parameter>
58  <parameter name="duration_ms" required="false">
59  <para>Minimum duration of tone, in ms. Default is 500ms.
60  Using a minimum duration under 50ms is unlikely to produce
61  accurate results.</para>
62  </parameter>
63  <parameter name="timeout" required="false">
64  <para>Maximum amount of time, in seconds, to wait for specified tone.
65  Default is forever.</para>
66  </parameter>
67  <parameter name="times" required="false">
68  <para>Number of times the tone should be detected (subject to the
69  provided timeout) before returning. Default is 1.</para>
70  </parameter>
71  <parameter name="options" required="false">
72  <optionlist>
73  <option name="d">
74  <para>Custom decibel threshold to use. Default is 16.</para>
75  </option>
76  <option name="s">
77  <para>Squelch tone.</para>
78  </option>
79  </optionlist>
80  </parameter>
81  </syntax>
82  <description>
83  <para>Waits for a tone to be detected before dialplan execution continues.</para>
84  <variablelist>
85  <variable name="WAITFORTONESTATUS">
86  <para>This indicates the result of the wait.</para>
87  <value name="SUCCESS"/>
88  <value name="ERROR"/>
89  <value name="TIMEOUT"/>
90  <value name="HANGUP"/>
91  </variable>
92  </variablelist>
93  </description>
94  <see-also>
95  <ref type="application">PlayTones</ref>
96  </see-also>
97  </application>
98  <function name="TONE_DETECT" language="en_US">
99  <synopsis>
100  Asynchronously detects a tone
101  </synopsis>
102  <syntax>
103  <parameter name="freq" required="true">
104  <para>Frequency of the tone to wait for. If the tone consists of
105  two frequencies, separate with the <literal>+</literal> symbol.
106  Detection may be less accurate for multiple frequencies.</para>
107  </parameter>
108  <parameter name="duration_ms" required="false">
109  <para>Minimum duration of tone, in ms. Default is 500ms.
110  Using a minimum duration under 50ms is unlikely to produce
111  accurate results.</para>
112  </parameter>
113  <parameter name="options">
114  <optionlist>
115  <option name="d">
116  <para>Custom decibel threshold to use. Default is 16.</para>
117  </option>
118  <option name="g">
119  <para>Go to the specified context,exten,priority if tone is received on this channel.
120  Detection will not end automatically.</para>
121  </option>
122  <option name="h">
123  <para>Go to the specified context,exten,priority if tone is transmitted on this channel.
124  Detection will not end automatically.</para>
125  </option>
126  <option name="r">
127  <para>Apply to received frames only. Default is both directions.</para>
128  </option>
129  <option name="s">
130  <para>Squelch tone.</para>
131  </option>
132  <option name="t">
133  <para>Apply to transmitted frames only. Default is both directions.</para>
134  </option>
135  <option name="x">
136  <para>Destroy the detector (stop detection).</para>
137  </option>
138  </optionlist>
139  </parameter>
140  </syntax>
141  <description>
142  <para>The TONE_DETECT function detects a tone of one or two frequencies and keeps
143  track of how many times the tone has been detected.</para>
144  <para>When reading this function (instead of writing), supply <literal>tx</literal>
145  to get the number of times a tone has been detected in the TX direction and
146  <literal>rx</literal> to get the number of times a tone has been detected in the
147  RX direction.</para>
148  <example title="intercept2600">
149  same => n,Set(TONE_DETECT(2600,1000,g(got-2600,s,1))=)
150  same => n,Wait(15)
151  same => n,NoOp(${TONE_DETECT(rx)})
152  </example>
153  </description>
154  </function>
155  ***/
156 
158  struct ast_dsp *dsp;
160  int freq1;
161  int freq2;
162  int duration;
163  int db;
164  char *gototx;
165  char *gotorx;
166  unsigned short int squelch;
167  unsigned short int tx;
168  unsigned short int rx;
169  int txcount;
170  int rxcount;
171 };
172 
173 enum td_opts {
174  OPT_TX = (1 << 1),
175  OPT_RX = (1 << 2),
176  OPT_END_FILTER = (1 << 3),
177  OPT_GOTO_RX = (1 << 4),
178  OPT_GOTO_TX = (1 << 5),
179  OPT_DECIBEL = (1 << 6),
180  OPT_SQUELCH = (1 << 7),
181 };
182 
183 enum {
187  /* note: this entry _MUST_ be the last one in the enum */
189 };
190 
196  AST_APP_OPTION('t', OPT_TX),
197  AST_APP_OPTION('r', OPT_RX),
199 });
200 
201 static void destroy_callback(void *data)
202 {
203  struct detect_information *di = data;
204  ast_dsp_free(di->dsp);
205  if (di->gotorx) {
206  ast_free(di->gotorx);
207  }
208  if (di->gototx) {
209  ast_free(di->gototx);
210  }
215  ast_free(di);
216  return;
217 }
218 
219 static const struct ast_datastore_info detect_datastore = {
220  .type = "detect",
221  .destroy = destroy_callback
222 };
223 
224 static int detect_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
225 {
226  struct ast_datastore *datastore = NULL;
227  struct detect_information *di = NULL;
228 
229  /* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
230  if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
231  return 0;
232 
233  /* Grab datastore which contains our gain information */
234  if (!(datastore = ast_channel_datastore_find(chan, &detect_datastore, NULL)))
235  return 0;
236 
237  di = datastore->data;
238 
239  if (!frame || frame->frametype != AST_FRAME_VOICE)
240  return 0;
241 
242  if (!(direction == AST_AUDIOHOOK_DIRECTION_READ ? &di->rx : &di->tx))
243  return 0;
244 
245  /* we don't want to modify the original frame */
246  if (!(frame = ast_frisolate(frame))) {
247  return 0;
248  }
249  frame = ast_dsp_process(chan, di->dsp, frame);
250  if (frame->frametype == AST_FRAME_DTMF) {
251  char result = frame->subclass.integer;
252  if (result == 'q') {
253  ast_debug(1, "TONE_DETECT just got a hit\n");
254  if (direction == AST_AUDIOHOOK_DIRECTION_READ)
255  di->rxcount = di->rxcount + 1;
256  else
257  di->txcount = di->txcount + 1;
258  if (direction == AST_AUDIOHOOK_DIRECTION_READ && di->gotorx) {
259  ast_async_parseable_goto(chan, di->gotorx);
260  } else if (di->gototx) {
261  ast_async_parseable_goto(chan, di->gototx);
262  }
263  }
264  }
265  ast_frfree(frame);
266 
267  return 0;
268 }
269 
270 static int remove_detect(struct ast_channel *chan)
271 {
272  struct ast_datastore *datastore = NULL;
273  struct detect_information *data;
274  SCOPED_CHANNELLOCK(chan_lock, chan);
275 
276  datastore = ast_channel_datastore_find(chan, &detect_datastore, NULL);
277  if (!datastore) {
278  ast_log(AST_LOG_WARNING, "Cannot remove TONE_DETECT from %s: TONE_DETECT not currently enabled\n",
279  ast_channel_name(chan));
280  return -1;
281  }
282  data = datastore->data;
283 
284  if (ast_audiohook_remove(chan, &data->audiohook)) {
285  ast_log(AST_LOG_WARNING, "Failed to remove TONE_DETECT audiohook from channel %s\n", ast_channel_name(chan));
286  return -1;
287  }
288 
289  if (ast_channel_datastore_remove(chan, datastore)) {
290  ast_log(AST_LOG_WARNING, "Failed to remove TONE_DETECT datastore from channel %s\n",
291  ast_channel_name(chan));
292  return -1;
293  }
294  ast_datastore_free(datastore);
295 
296  return 0;
297 }
298 
299 static int freq_parser(char *freqs, int *freq1, int *freq2) {
300  char *f1, *f2, *f3;
301  if (ast_strlen_zero(freqs)) {
302  ast_log(LOG_ERROR, "No frequency specified\n");
303  return -1;
304  }
305  f3 = ast_strdupa(freqs);
306  f1 = strsep(&f3, "+");
307  f2 = strsep(&f3, "+");
308  if (!ast_strlen_zero(f3)) {
309  ast_log(LOG_WARNING, "Only up to 2 frequencies may be specified: %s\n", freqs);
310  return -1;
311  }
312  if (ast_str_to_int(f1, freq1)) {
313  ast_log(LOG_WARNING, "Frequency must be an integer: %s\n", f1);
314  return -1;
315  }
316  if (*freq1 < 1) {
317  ast_log(LOG_WARNING, "Sorry, positive frequencies only: %d\n", *freq1);
318  return -1;
319  }
320  if (!ast_strlen_zero(f2)) {
321  ast_log(LOG_WARNING, "Sorry, currently only 1 frequency is supported\n");
322  return -1;
323  /* not supported just yet, but possibly will be in the future */
324  if (ast_str_to_int(f2, freq2)) {
325  ast_log(LOG_WARNING, "Frequency must be an integer: %s\n", f2);
326  return -1;
327  }
328  if (*freq2 < 1) {
329  ast_log(LOG_WARNING, "Sorry, positive frequencies only: %d\n", *freq2);
330  return -1;
331  }
332  }
333  return 0;
334 }
335 
336 static char* goto_parser(struct ast_channel *chan, char *loc) {
337  char *exten, *pri, *context, *parse;
338  char *dest;
339  int size;
340  parse = ast_strdupa(loc);
341  context = strsep(&parse, ",");
342  exten = strsep(&parse, ",");
343  pri = strsep(&parse, ",");
344  if (!exten) {
345  pri = context;
346  exten = NULL;
347  context = NULL;
348  } else if (!pri) {
349  pri = exten;
350  exten = context;
351  context = NULL;
352  }
353  ast_channel_lock(chan);
354  if (ast_strlen_zero(exten)) {
355  exten = ast_strdupa(ast_channel_exten(chan));
356  }
357  if (ast_strlen_zero(context)) {
358  context = ast_strdupa(ast_channel_context(chan));
359  }
360  ast_channel_unlock(chan);
361 
362  /* size + 1 for null terminator + 2 commas */
363  size = sizeof(context) + sizeof(exten) + sizeof(pri) + 2;
364  dest = ast_malloc(size + 1);
365  snprintf(dest, size, "%s,%s,%s", context, exten, pri);
366  return dest;
367 }
368 
369 static int detect_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
370 {
371  struct ast_datastore *datastore = NULL;
372  struct detect_information *di = NULL;
373 
374  if (!chan) {
375  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
376  return -1;
377  }
378 
379  ast_channel_lock(chan);
380  if (!(datastore = ast_channel_datastore_find(chan, &detect_datastore, NULL))) {
381  ast_channel_unlock(chan);
382  return -1; /* function not initiated yet, so nothing to read */
383  } else {
384  ast_channel_unlock(chan);
385  di = datastore->data;
386  }
387 
388  if (strchr(data, 't')) {
389  snprintf(buffer, buflen, "%d", di->txcount);
390  } else if (strchr(data, 'r')) {
391  snprintf(buffer, buflen, "%d", di->rxcount);
392  } else {
393  ast_log(LOG_WARNING, "Invalid direction: %s\n", data);
394  }
395 
396  return 0;
397 }
398 
399 static int detect_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
400 {
401  char *parse;
402  struct ast_datastore *datastore = NULL;
403  struct detect_information *di = NULL;
404  int is_new = 0;
405  struct ast_flags flags = { 0 };
406  char *opt_args[OPT_ARG_ARRAY_SIZE];
407  struct ast_dsp *dsp;
408  int freq1 = 0, freq2 = 0, duration = 500, db = 16, squelch = 0;
409 
414  );
415 
416  if (!chan) {
417  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
418  return -1;
419  }
420  parse = ast_strdupa(data);
421  AST_STANDARD_APP_ARGS(args, parse);
422 
423  ast_channel_lock(chan);
424  if (!(datastore = ast_channel_datastore_find(chan, &detect_datastore, NULL))) {
425  ast_channel_unlock(chan);
426  if (!(datastore = ast_datastore_alloc(&detect_datastore, NULL)))
427  return 0;
428  if (!(di = ast_calloc(1, sizeof(*di)))) {
429  ast_datastore_free(datastore);
430  return 0;
431  }
434  is_new = 1;
435  } else {
436  ast_channel_unlock(chan);
437  di = datastore->data;
438  }
439 
440  if (!ast_strlen_zero(args.options)) {
441  ast_app_parse_options(td_opts, &flags, opt_args, args.options);
442  }
443 
444  if (ast_test_flag(&flags, OPT_END_FILTER)) {
445  return remove_detect(chan);
446  }
447  if (freq_parser(args.freqs, &freq1, &freq2)) {
448  return -1;
449  }
450  if (!ast_strlen_zero(args.duration) && (ast_str_to_int(args.duration, &duration) || duration < 1)) {
451  ast_log(LOG_WARNING, "Invalid duration: %s\n", args.duration);
452  return -1;
453  }
454  di->duration = duration;
455  if (ast_test_flag(&flags, OPT_DECIBEL) && !ast_strlen_zero(opt_args[OPT_ARG_DECIBEL])) {
456  if ((ast_str_to_int(opt_args[OPT_ARG_DECIBEL], &db) || db < 1)) {
457  ast_log(LOG_WARNING, "Invalid decibel level: %s\n", opt_args[OPT_ARG_DECIBEL]);
458  return -1;
459  }
460  }
461  di->gotorx = NULL;
462  di->gototx = NULL;
463  /* resolve gotos now, in case a full context,exten,pri wasn't specified */
464  if (ast_test_flag(&flags, OPT_GOTO_RX) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO_RX])) {
465  di->gotorx = goto_parser(chan, opt_args[OPT_ARG_GOTO_RX]);
466  }
467  if (ast_test_flag(&flags, OPT_GOTO_TX) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO_TX])) {
468  di->gototx = goto_parser(chan, opt_args[OPT_ARG_GOTO_TX]);
469  }
470  di->db = db;
471  di->squelch = ast_test_flag(&flags, OPT_SQUELCH);
472 
473  di->tx = 1;
474  di->rx = 1;
475  if (ast_strlen_zero(args.options) || ast_test_flag(&flags, OPT_TX)) {
476  di->tx = 1;
477  di->rx = 0;
478  }
479  if (ast_strlen_zero(args.options) || ast_test_flag(&flags, OPT_RX)) {
480  di->rx = 1;
481  di->tx = 0;
482  }
483 
484  if (is_new) {
485  if (!(dsp = ast_dsp_new())) {
486  ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
487  return -1;
488  }
490  ast_dsp_set_freqmode(dsp, freq1, duration, db, squelch);
491  di->dsp = dsp;
492  di->txcount = 0;
493  di->rxcount = 0;
494  ast_debug(1, "Keeping our ears open for %s Hz, %d db\n", args.freqs, db);
495  datastore->data = di;
496  ast_channel_lock(chan);
497  ast_channel_datastore_add(chan, datastore);
498  ast_channel_unlock(chan);
499  ast_audiohook_attach(chan, &di->audiohook);
500  } else {
501  dsp = di->dsp;
502  ast_dsp_set_freqmode(dsp, freq1, duration, db, squelch);
503  }
504 
505  return 0;
506 }
507 
508 enum {
509  OPT_APP_DECIBEL = (1 << 0),
510  OPT_APP_SQUELCH = (1 << 1),
511 };
512 
513 enum {
515  /* note: this entry _MUST_ be the last one in the enum */
517 };
518 
523 
524 static int wait_exec(struct ast_channel *chan, const char *data)
525 {
526  char *appdata;
527  struct ast_flags flags = {0};
528  char *opt_args[OPT_APP_ARG_ARRAY_SIZE];
529  double timeoutf = 0;
530  int freq1 = 0, freq2 = 0, timeout = 0, duration = 500, times = 1, db = 16, squelch = 0;
531  struct ast_frame *frame = NULL;
532  struct ast_dsp *dsp;
533  struct timeval start;
534  int remaining_time = 0;
535  int hits = 0;
537  AST_APP_ARG(freqs);
540  AST_APP_ARG(times);
542  );
543 
544  appdata = ast_strdupa(data);
545  AST_STANDARD_APP_ARGS(args, appdata);
546 
547  if (!ast_strlen_zero(args.options)) {
548  ast_app_parse_options(wait_exec_options, &flags, opt_args, args.options);
549  }
550  if (freq_parser(args.freqs, &freq1, &freq2)) {
551  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "ERROR");
552  return -1;
553  }
554  if (!ast_strlen_zero(args.timeout) && (sscanf(args.timeout, "%30lf", &timeoutf) != 1 || timeout < 0)) {
555  ast_log(LOG_WARNING, "Invalid timeout: %s\n", args.timeout);
556  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "ERROR");
557  return -1;
558  }
559  timeout = 1000 * timeoutf;
560  if (!ast_strlen_zero(args.duration) && (ast_str_to_int(args.duration, &duration) || duration < 1)) {
561  ast_log(LOG_WARNING, "Invalid duration: %s\n", args.duration);
562  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "ERROR");
563  return -1;
564  }
565  if (!ast_strlen_zero(args.times) && (ast_str_to_int(args.times, &times) || times < 1)) {
566  ast_log(LOG_WARNING, "Invalid number of times: %s\n", args.times);
567  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "ERROR");
568  return -1;
569  }
571  if ((ast_str_to_int(opt_args[OPT_APP_ARG_DECIBEL], &db) || db < 1)) {
572  ast_log(LOG_WARNING, "Invalid decibel level: %s\n", opt_args[OPT_APP_ARG_DECIBEL]);
573  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "ERROR");
574  return -1;
575  }
576  }
578  if (!(dsp = ast_dsp_new())) {
579  ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
580  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "ERROR");
581  return -1;
582  }
584  ast_dsp_set_freqmode(dsp, freq1, duration, db, squelch);
585  ast_debug(1, "Waiting for %s Hz, %d time(s), timeout %d ms, %d db\n", args.freqs, times, timeout, db);
586  start = ast_tvnow();
587  while (timeout == 0 || remaining_time > 0) {
588  if (timeout > 0) {
589  remaining_time = ast_remaining_ms(start, timeout);
590  if (remaining_time <= 0) {
591  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "TIMEOUT");
592  break;
593  }
594  }
595  if (ast_waitfor(chan, 1000) > 0) {
596  if (!(frame = ast_read(chan))) {
597  ast_debug(1, "Channel '%s' did not return a frame; probably hung up.\n", ast_channel_name(chan));
598  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "HANGUP");
599  break;
600  } else if (frame->frametype == AST_FRAME_VOICE) {
601  frame = ast_dsp_process(chan, dsp, frame);
602  if (frame->frametype == AST_FRAME_DTMF) {
603  char result = frame->subclass.integer;
604  if (result == 'q') {
605  hits++;
606  ast_debug(1, "We just detected %s Hz (hit #%d)\n", args.freqs, hits);
607  if (hits >= times) {
608  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "SUCCESS");
609  break;
610  }
611  }
612  }
613  }
614  } else {
615  pbx_builtin_setvar_helper(chan, "WAITFORTONESTATUS", "HANGUP");
616  }
617  }
618  ast_dsp_free(dsp);
619 
620  return 0;
621 }
622 
623 static char *waitapp = "WaitForTone";
624 
626  .name = "TONE_DETECT",
627  .read = detect_read,
628  .write = detect_write,
629 };
630 
631 static int unload_module(void)
632 {
633  int res;
634 
635  res = ast_unregister_application(waitapp);
636  res |= ast_custom_function_unregister(&detect_function);
637 
638  return res;
639 }
640 
641 static int load_module(void)
642 {
643  int res;
644 
645  res = ast_register_application_xml(waitapp, wait_exec);
646  res |= ast_custom_function_register(&detect_function);
647 
648  return res;
649 }
650 
651 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Tone detection module");
unsigned short int rx
const char * name
Definition: pbx.h:119
const char * type
Definition: datastore.h:32
Tone Indication Support.
#define ast_channel_lock(chan)
Definition: channel.h:2945
struct ast_frame * ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf)
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress...
Definition: dsp.c:1494
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define BEGIN_OPTIONS
goertzel_state_t freqs[FREQ_ARRAY_SIZE]
Definition: dsp.c:419
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1770
static char * goto_parser(struct ast_channel *chan, char *loc)
Convenient Signal Processing routines.
static void destroy_callback(void *data)
#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
Audiohooks Architecture.
int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
Remove an audiohook from a specified channel.
Definition: audiohook.c:764
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition: dsp.c:1745
static int timeout
Definition: cdr_mysql.c:86
#define AST_LOG_WARNING
Definition: logger.h:279
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
struct ast_audiohook audiohook
Structure for a data store type.
Definition: datastore.h:31
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
Definition: audiohook.c:501
static const struct ast_app_option wait_exec_options[128]
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
static int detect_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
Structure for a data store object.
Definition: datastore.h:68
static const struct ast_datastore_info detect_datastore
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2404
const char * args
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define AST_FRAME_DTMF
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
Definition: audiohook.c:133
static int unload_module(void)
static char * waitapp
static int remove_detect(struct ast_channel *chan)
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
struct ast_frame_subclass subclass
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
struct ast_dsp * dsp
ast_audiohook_manipulate_callback manipulate_callback
Definition: audiohook.h:117
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
Initialize an audiohook structure.
Definition: audiohook.c:108
static int detect_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition: audiohook.h:300
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
static int detect_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
unsigned short int squelch
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Definition: lock.h:617
General Asterisk PBX channel definitions.
Definition: dsp.c:405
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
Asterisk internal frame definitions.
Conversion utility functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:2906
const char * ast_channel_exten(const struct ast_channel *chan)
Core PBX routines and definitions.
int ast_str_to_int(const char *str, int *res)
Convert the given string to a signed integer.
Definition: conversions.c:44
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Definition: audiohook.c:579
#define LOG_ERROR
Definition: logger.h:285
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:2033
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Tone detection module")
static float di[4]
Definition: tdd.c:58
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition: dsp.c:1755
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
Structure used to handle boolean flags.
Definition: utils.h:199
ast_audiohook_direction
Definition: audiohook.h:48
int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:8864
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
void * data
Definition: datastore.h:70
static int load_module(void)
char * strsep(char **str, const char *delims)
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3171
const char * ast_channel_name(const struct ast_channel *chan)
#define END_OPTIONS
#define ast_frfree(fr)
static PGresult * result
Definition: cel_pgsql.c:88
td_opts
Data structure associated with a single frame of data.
int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq1, int dur, int db, int squelch)
Set arbitrary frequency detection mode.
Definition: dsp.c:1859
const char * ast_channel_context(const struct ast_channel *chan)
enum ast_audiohook_status status
Definition: audiohook.h:107
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
enum ast_frame_type frametype
static struct test_options options
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
#define DSP_FEATURE_FREQ_DETECT
Definition: dsp.h:45
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
direction
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition: audiohook.h:295
Asterisk module definitions.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
static int freq_parser(char *freqs, int *freq1, int *freq2)
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2399
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508
unsigned short int tx
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
static int wait_exec(struct ast_channel *chan, const char *data)
static struct ast_custom_function detect_function
Media Format Cache API.
#define AST_APP_ARG(name)
Define an application argument.