Asterisk - The Open Source Telephony Project  GIT-master-1f78ee9
Data Structures | Macros | Functions
indications.h File Reference

Tone Indication Support. More...

#include "asterisk/astobj2.h"
#include "asterisk/utils.h"

Go to the source code of this file.

Data Structures

struct  ast_tone_zone
 A set of tones for a given locale. More...
 
struct  ast_tone_zone_part
 A description of a part of a tone. More...
 
struct  ast_tone_zone_sound
 Description of a tone. More...
 

Macros

#define ast_tone_zone_lock(tz)   ao2_lock(tz)
 Lock an ast_tone_zone. More...
 
#define ast_tone_zone_trylock(tz)   ao2_trylock(tz)
 Trylock an ast_tone_zone. More...
 
#define ast_tone_zone_unlock(tz)   ao2_unlock(tz)
 Unlock an ast_tone_zone. More...
 
#define MAX_TONEZONE_COUNTRY   16
 

Functions

struct ast_tone_zone_soundast_get_indication_tone (const struct ast_tone_zone *zone, const char *indication)
 Locate a tone zone sound. More...
 
struct ast_tone_zoneast_get_indication_zone (const char *country)
 locate ast_tone_zone More...
 
int ast_playtones_start (struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
 Start playing a list of tones on a channel. More...
 
void ast_playtones_stop (struct ast_channel *chan)
 Stop playing tones on a channel. More...
 
int ast_tone_zone_count (void)
 Get the number of registered tone zones. More...
 
struct ao2_iterator ast_tone_zone_iterator_init (void)
 Get an iterator for the available tone zones. More...
 
int ast_tone_zone_part_parse (const char *s, struct ast_tone_zone_part *tone_data)
 Parse a tone part. More...
 
static struct ast_tone_zoneast_tone_zone_ref (struct ast_tone_zone *tz)
 Increase the reference count on an ast_tone_zone. More...
 
static struct ast_tone_zone_soundast_tone_zone_sound_ref (struct ast_tone_zone_sound *ts)
 Increase the reference count on an ast_tone_zone_sound. More...
 
static struct ast_tone_zone_soundast_tone_zone_sound_unref (struct ast_tone_zone_sound *ts)
 Release a reference to an ast_tone_zone_sound. More...
 
static struct ast_tone_zoneast_tone_zone_unref (struct ast_tone_zone *tz)
 Release a reference to an ast_tone_zone. More...
 

Detailed Description

Tone Indication Support.

Author
Pauline Middelink midde.nosp@m.link.nosp@m.@poly.nosp@m.ware.nosp@m..nl
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file indications.h.

Macro Definition Documentation

◆ ast_tone_zone_lock

#define ast_tone_zone_lock (   tz)    ao2_lock(tz)

◆ ast_tone_zone_trylock

#define ast_tone_zone_trylock (   tz)    ao2_trylock(tz)

Trylock an ast_tone_zone.

Definition at line 198 of file indications.h.

◆ ast_tone_zone_unlock

#define ast_tone_zone_unlock (   tz)    ao2_unlock(tz)

◆ MAX_TONEZONE_COUNTRY

#define MAX_TONEZONE_COUNTRY   16

Definition at line 64 of file indications.h.

Function Documentation

◆ ast_get_indication_tone()

struct ast_tone_zone_sound* ast_get_indication_tone ( const struct ast_tone_zone zone,
const char *  indication 
)

Locate a tone zone sound.

Parameters
zoneZone to look in for a sound, if NULL, the default will be used
indicationSound to look for, such as "busy"
Returns
a reference to the specified sound if it exists, NULL if not
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 455 of file indications.c.

References ao2_lock, ao2_unlock, AST_LIST_TRAVERSE, ast_tone_zone_lock, ast_tone_zone_ref(), ast_tone_zone_sound_ref(), ast_tone_zone_unlock, ast_tone_zone_unref(), ast_tone_zone_sound::name, NULL, and ast_tone_zone::tones.

Referenced by ast_app_dtget(), ast_control_tone(), dial_handle_playtones(), dialtone_indicate(), handle_playtones(), in_band_indication(), indicate_data_internal(), pbx_builtin_waitexten(), play_dialtone(), read_exec(), readexten_exec(), and send_dial_tone().

456 {
457  struct ast_tone_zone_sound *ts = NULL;
458  /* _zone is const to the users of the API */
459  struct ast_tone_zone *zone = (struct ast_tone_zone *) _zone;
460 
461  /* If no zone is specified, use the default */
462  if (!zone) {
464  if (default_tone_zone) {
466  }
468 
469  if (!zone) {
470  return NULL;
471  }
472  }
473 
474  ast_tone_zone_lock(zone);
475 
476  /* Look through list of tones in the zone searching for the right one */
477  AST_LIST_TRAVERSE(&zone->tones, ts, entry) {
478  if (!strcasecmp(ts->name, indication)) {
479  /* Increase ref count for the reference we will return */
480  ts = ast_tone_zone_sound_ref(ts);
481  break;
482  }
483  }
484 
485  ast_tone_zone_unlock(zone);
486 
487  if (!_zone)
488  zone = ast_tone_zone_unref(zone);
489 
490  return ts;
491 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:205
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:73
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:193
static struct ao2_container * ast_tone_zones
Definition: indications.c:66
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
A set of tones for a given locale.
Definition: indications.h:74
#define ao2_lock(a)
Definition: astobj2.h:718
const char * name
Name of the tone. For example, "busy".
Definition: indications.h:37
static struct ast_tone_zone_sound * ast_tone_zone_sound_ref(struct ast_tone_zone_sound *ts)
Increase the reference count on an ast_tone_zone_sound.
Definition: indications.h:238
Description of a tone.
Definition: indications.h:35
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:216
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct ast_tone_zone::@263 tones
A list of tones for this locale.
Definition: search.h:40
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:188

◆ ast_get_indication_zone()

struct ast_tone_zone* ast_get_indication_zone ( const char *  country)

locate ast_tone_zone

Parameters
countrycountry to find. If NULL is provided, get the default.
Returns
a reference to the specified country if found or NULL if not found

locate ast_tone_zone

Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 433 of file indications.c.

References ao2_find, ao2_lock, ao2_unlock, ast_copy_string(), ast_strlen_zero, ast_tone_zone_ref(), ast_tone_zone::country, ast_tone_zone::nrringcadence, NULL, OBJ_POINTER, and tz.

Referenced by ast_control_tone(), ast_set_indication_country(), ast_var_indications(), build_device(), build_peer(), chan_pjsip_new(), func_channel_write_real(), handle_cli_indication_add(), handle_cli_indication_remove(), reload_config(), and sip_new().

434 {
435  struct ast_tone_zone *tz = NULL;
436  struct ast_tone_zone zone_arg = {
437  .nrringcadence = 0,
438  };
439 
440  if (ast_strlen_zero(country)) {
442  if (default_tone_zone) {
444  }
446 
447  return tz;
448  }
449 
450  ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
451 
452  return ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER);
453 }
char country[MAX_TONEZONE_COUNTRY]
Country code that this set of tones is for.
Definition: indications.h:76
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:73
#define OBJ_POINTER
Definition: astobj2.h:1154
static struct ao2_container * ast_tone_zones
Definition: indications.c:66
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
A set of tones for a given locale.
Definition: indications.h:74
#define ao2_lock(a)
Definition: astobj2.h:718
static char country[80]
Definition: pbx_dundi.c:205
static char * tz
Definition: cdr_pgsql.c:75
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:216
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:84

◆ ast_playtones_start()

int ast_playtones_start ( struct ast_channel chan,
int  vol,
const char *  tonelist,
int  interruptible 
)

Start playing a list of tones on a channel.

Parameters
chanthe channel to play tones on
volvolume
tonelistthe list of tones to play, comma separated
interruptiblewhether or not this tone can be interrupted
Return values
0success
non-zerofailure
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 302 of file indications.c.

References ast_activate_generator(), ast_free, ast_log, ast_realloc, ast_strdupa, ast_strip(), ast_strlen_zero, ast_tone_zone_part_parse(), cos, playtones_item::duration, playtones_item::fac1, playtones_item::fac2, ast_tone_zone_part::freq1, ast_tone_zone_part::freq2, playtones_item::init_v2_1, playtones_item::init_v2_2, playtones_item::init_v3_1, playtones_item::init_v3_2, playtones_def::interruptible, playtones_def::items, LOG_ERROR, M_PI, midi_tohz, ast_tone_zone_part::midinote, playtones_item::modulate, ast_tone_zone_part::modulate, playtones_def::nitems, NULL, playtones_def::reppos, strsep(), ast_tone_zone_part::time, and playtones_def::vol.

Referenced by ast_app_dtget(), ast_control_tone(), ast_senddigit_begin(), control_tone_frame_response(), dial_handle_playtones(), dialtone_indicate(), handle_playtones(), in_band_indication(), indicate_data_internal(), milliwatt_exec(), pbx_builtin_waitexten(), play_dialtone(), playtone(), read_exec(), readexten_exec(), receivefax_t38_init(), send_digit_to_chan(), send_tone_burst(), and sendfax_t38_init().

303 {
304  char *s, *data = ast_strdupa(playlst);
305  struct playtones_def d = { vol, -1, 0, 1, NULL };
306  char *stringp;
307  char *separator;
308  static const float sample_rate = 8000.0;
309  static const float max_sample_val = 32768.0;
310 
311  if (vol < 1) {
312  d.vol = 7219; /* Default to -8db */
313  }
314 
316 
317  stringp = data;
318 
319  /* check if the data is separated with '|' or with ',' by default */
320  if (strchr(stringp,'|')) {
321  separator = "|";
322  } else {
323  separator = ",";
324  }
325 
326  while ((s = strsep(&stringp, separator)) && !ast_strlen_zero(s)) {
327  struct playtones_item *new_items;
328  struct ast_tone_zone_part tone_data = {
329  .time = 0,
330  };
331 
332  s = ast_strip(s);
333  if (s[0]=='!') {
334  s++;
335  } else if (d.reppos == -1) {
336  d.reppos = d.nitems;
337  }
338 
339  if (ast_tone_zone_part_parse(s, &tone_data)) {
340  ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s);
341  continue;
342  }
343 
344  if (tone_data.midinote) {
345  /* midi notes must be between 0 and 127 */
346  if (tone_data.freq1 <= 127) {
347  tone_data.freq1 = midi_tohz[tone_data.freq1];
348  } else {
349  tone_data.freq1 = 0;
350  }
351 
352  if (tone_data.freq2 <= 127) {
353  tone_data.freq2 = midi_tohz[tone_data.freq2];
354  } else {
355  tone_data.freq2 = 0;
356  }
357  }
358 
359  new_items = ast_realloc(d.items, (d.nitems + 1) * sizeof(*d.items));
360  if (!new_items) {
361  ast_free(d.items);
362  return -1;
363  }
364  d.items = new_items;
365 
366  d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (tone_data.freq1 / sample_rate)) * max_sample_val;
367  d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
368  d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
369 
370  d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (tone_data.freq2 / sample_rate)) * max_sample_val;
371  d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
372  d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
373 
374  d.items[d.nitems].duration = tone_data.time;
375  d.items[d.nitems].modulate = tone_data.modulate;
376 
377  d.nitems++;
378  }
379 
380  if (!d.nitems) {
381  ast_log(LOG_ERROR, "No valid tone parts\n");
382  return -1;
383  }
384 
385  if (ast_activate_generator(chan, &playtones, &d)) {
386  ast_free(d.items);
387  return -1;
388  }
389 
390  return 0;
391 }
unsigned int cos
Definition: chan_iax2.c:353
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:228
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2926
static struct test_val d
A description of a part of a tone.
Definition: indications.h:109
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
Definition: indications.c:245
unsigned int midinote
Definition: indications.h:114
#define NULL
Definition: resample.c:96
static struct ast_generator playtones
Definition: indications.c:239
unsigned int freq1
Definition: indications.h:110
#define ast_log
Definition: astobj2.c:42
#define M_PI
Definition: resample.c:83
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define LOG_ERROR
Definition: logger.h:285
unsigned int time
Definition: indications.h:112
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_free(a)
Definition: astmm.h:182
struct playtones_item * items
Definition: indications.c:91
unsigned int modulate
Definition: indications.h:113
char * strsep(char **str, const char *delims)
unsigned int freq2
Definition: indications.h:111
static const int midi_tohz[128]
Definition: indications.c:50

◆ ast_playtones_stop()

void ast_playtones_stop ( struct ast_channel chan)

Stop playing tones on a channel.

Parameters
chanthe channel to stop tones on
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 393 of file indications.c.

References ast_deactivate_generator().

Referenced by ast_app_dtget(), ast_senddigit_end(), control_tone_frame_response(), disa_exec(), handle_stopplaytones(), indicate_data_internal(), pbx_builtin_waitexten(), playtone(), read_exec(), readexten_exec(), receivefax_t38_init(), send_tone_burst(), sendfax_t38_init(), stop_indicate(), and unistim_indicate().

394 {
396 }
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2868

◆ ast_tone_zone_count()

int ast_tone_zone_count ( void  )

Get the number of registered tone zones.

Returns
the total number of registered tone zones

Definition at line 398 of file indications.c.

References ao2_container_count().

399 {
401 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static struct ao2_container * ast_tone_zones
Definition: indications.c:66

◆ ast_tone_zone_iterator_init()

struct ao2_iterator ast_tone_zone_iterator_init ( void  )

Get an iterator for the available tone zones.

Note
Use ao2_iterator_next() to iterate the tone zones.
Use ao2_iterator_destroy() to clean up.
Returns
an initialized iterator

Definition at line 403 of file indications.c.

References ao2_iterator_init().

Referenced by ast_var_indications(), ast_var_indications_table(), and handle_cli_indication_show().

404 {
406 }
static struct ao2_container * ast_tone_zones
Definition: indications.c:66
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ ast_tone_zone_part_parse()

int ast_tone_zone_part_parse ( const char *  s,
struct ast_tone_zone_part tone_data 
)

Parse a tone part.

Parameters
sThe part of a tone to parse. This should be in the form described for the data part of ast_tone_zone_sound. '!' should be removed if present.
tone_dataAn output parameter that contains the result of the parsing.
Return values
0success
-1failure, and the contents of tone_data are undefined

Definition at line 245 of file indications.c.

References ast_tone_zone_part::freq1, ast_tone_zone_part::freq2, ast_tone_zone_part::midinote, ast_tone_zone_part::modulate, and ast_tone_zone_part::time.

Referenced by ast_playtones_start(), and send_dial_tone().

246 {
247  if (sscanf(s, "%30u+%30u/%30u", &tone_data->freq1, &tone_data->freq2,
248  &tone_data->time) == 3) {
249  /* f1+f2/time format */
250  } else if (sscanf(s, "%30u+%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
251  /* f1+f2 format */
252  tone_data->time = 0;
253  } else if (sscanf(s, "%30u*%30u/%30u", &tone_data->freq1, &tone_data->freq2,
254  &tone_data->time) == 3) {
255  /* f1*f2/time format */
256  tone_data->modulate = 1;
257  } else if (sscanf(s, "%30u*%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
258  /* f1*f2 format */
259  tone_data->time = 0;
260  tone_data->modulate = 1;
261  } else if (sscanf(s, "%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
262  /* f1/time format */
263  tone_data->freq2 = 0;
264  } else if (sscanf(s, "%30u", &tone_data->freq1) == 1) {
265  /* f1 format */
266  tone_data->freq2 = 0;
267  tone_data->time = 0;
268  } else if (sscanf(s, "M%30u+M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
269  &tone_data->time) == 3) {
270  /* Mf1+Mf2/time format */
271  tone_data->midinote = 1;
272  } else if (sscanf(s, "M%30u+M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
273  /* Mf1+Mf2 format */
274  tone_data->time = 0;
275  tone_data->midinote = 1;
276  } else if (sscanf(s, "M%30u*M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
277  &tone_data->time) == 3) {
278  /* Mf1*Mf2/time format */
279  tone_data->modulate = 1;
280  tone_data->midinote = 1;
281  } else if (sscanf(s, "M%30u*M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
282  /* Mf1*Mf2 format */
283  tone_data->time = 0;
284  tone_data->modulate = 1;
285  tone_data->midinote = 1;
286  } else if (sscanf(s, "M%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
287  /* Mf1/time format */
288  tone_data->freq2 = -1;
289  tone_data->midinote = 1;
290  } else if (sscanf(s, "M%30u", &tone_data->freq1) == 1) {
291  /* Mf1 format */
292  tone_data->freq2 = -1;
293  tone_data->time = 0;
294  tone_data->midinote = 1;
295  } else {
296  return -1;
297  }
298 
299  return 0;
300 }
unsigned int midinote
Definition: indications.h:114
unsigned int freq1
Definition: indications.h:110
unsigned int time
Definition: indications.h:112
unsigned int modulate
Definition: indications.h:113
unsigned int freq2
Definition: indications.h:111

◆ ast_tone_zone_ref()

static struct ast_tone_zone* ast_tone_zone_ref ( struct ast_tone_zone tz)
static

Increase the reference count on an ast_tone_zone.

Returns
The tone zone provided as an argument

Definition at line 216 of file indications.h.

References ao2_ref, and tz.

Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication_country(), ast_set_indication_country(), and func_channel_write_real().

217 {
218  ao2_ref(tz, +1);
219  return tz;
220 }
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static char * tz
Definition: cdr_pgsql.c:75

◆ ast_tone_zone_sound_ref()

static struct ast_tone_zone_sound* ast_tone_zone_sound_ref ( struct ast_tone_zone_sound ts)
static

Increase the reference count on an ast_tone_zone_sound.

Returns
The tone zone sound provided as an argument

Definition at line 238 of file indications.h.

References ao2_ref.

Referenced by ast_get_indication_tone().

239 {
240  ao2_ref(ts, +1);
241  return ts;
242 }
#define ao2_ref(o, delta)
Definition: astobj2.h:464

◆ ast_tone_zone_sound_unref()

static struct ast_tone_zone_sound* ast_tone_zone_sound_unref ( struct ast_tone_zone_sound ts)
static

◆ ast_tone_zone_unref()

static struct ast_tone_zone* ast_tone_zone_unref ( struct ast_tone_zone tz)
static