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

Tone Indication Support. More...

#include "asterisk/astobj2.h"
#include "asterisk/utils.h"
Include dependency graph for indications.h:
This graph shows which files directly or indirectly include this file:

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)

Lock an ast_tone_zone.

Definition at line 188 of file indications.h.

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

Unlock an ast_tone_zone.

Definition at line 193 of file indications.h.

◆ 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

Definition at line 461 of file indications.c.

462{
463 struct ast_tone_zone_sound *ts = NULL;
464 /* _zone is const to the users of the API */
465 struct ast_tone_zone *zone = (struct ast_tone_zone *) _zone;
466
467 /* If no zone is specified, use the default */
468 if (!zone) {
470 if (default_tone_zone) {
472 }
474
475 if (!zone) {
476 return NULL;
477 }
478 }
479
480 ast_tone_zone_lock(zone);
481
482 /* Look through list of tones in the zone searching for the right one */
483 AST_LIST_TRAVERSE(&zone->tones, ts, entry) {
484 if (!strcasecmp(ts->name, indication)) {
485 /* Increase ref count for the reference we will return */
487 break;
488 }
489 }
490
492
493 if (!_zone)
494 zone = ast_tone_zone_unref(zone);
495
496 return ts;
497}
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
static struct ao2_container * ast_tone_zones
Definition: indications.c:66
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 ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:205
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:188
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
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:491
#define NULL
Definition: resample.c:96
Description of a tone.
Definition: indications.h:35
const char * name
Name of the tone. For example, "busy".
Definition: indications.h:37
A set of tones for a given locale.
Definition: indications.h:74
struct ast_tone_zone::@234 tones
A list of tones for this locale.
Definition: search.h:40

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_zones, default_tone_zone, ast_tone_zone_sound::name, NULL, and ast_tone_zone::tones.

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

◆ 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

Definition at line 439 of file indications.c.

440{
441 struct ast_tone_zone *tz = NULL;
442 struct ast_tone_zone zone_arg = {
443 .nrringcadence = 0,
444 };
445
448 if (default_tone_zone) {
450 }
452
453 return tz;
454 }
455
456 ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
457
458 return ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER);
459}
#define OBJ_POINTER
Definition: astobj2.h:1150
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
static char * tz
Definition: cdr_pgsql.c:71
static char country[80]
Definition: pbx_dundi.c:205
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:84
char country[MAX_TONEZONE_COUNTRY]
Country code that this set of tones is for.
Definition: indications.h:76

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

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

◆ 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

Definition at line 302 of file indications.c.

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
315 d.interruptible = interruptible;
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}
#define ast_free(a)
Definition: astmm.h:180
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:226
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
unsigned int cos
Definition: chan_iax2.c:356
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2970
char * strsep(char **str, const char *delims)
#define LOG_ERROR
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
Definition: indications.c:245
static const int midi_tohz[128]
Definition: indications.c:50
static struct ast_generator playtones
Definition: indications.c:239
#define M_PI
Definition: resample.c:83
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
A description of a part of a tone.
Definition: indications.h:109
unsigned int modulate
Definition: indications.h:113
unsigned int freq2
Definition: indications.h:111
unsigned int time
Definition: indications.h:112
unsigned int midinote
Definition: indications.h:114
unsigned int freq1
Definition: indications.h:110
static struct test_val d

References ast_activate_generator(), ast_free, ast_log, ast_realloc, ast_strdupa, ast_strip(), ast_strlen_zero(), ast_tone_zone_part_parse(), cos, d, ast_tone_zone_part::freq1, ast_tone_zone_part::freq2, playtones_def::interruptible, LOG_ERROR, M_PI, midi_tohz, ast_tone_zone_part::midinote, ast_tone_zone_part::modulate, NULL, playtones, strsep(), ast_tone_zone_part::time, and playtones_def::vol.

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

◆ ast_playtones_stop()

void ast_playtones_stop ( struct ast_channel chan)

Stop playing tones on a channel.

Parameters
chanthe channel to stop tones on

Definition at line 393 of file indications.c.

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

References ast_deactivate_generator().

Referenced by ast_app_dtget(), ast_senddigit_end(), ast_senddigit_mf_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(), and unistim_indicate().

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

399{
401}
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.

References ao2_container_count(), and ast_tone_zones.

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

404{
406}
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

References ao2_iterator_init(), and ast_tone_zones.

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

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

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}

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

◆ ast_tone_zone_ref()

static struct ast_tone_zone * ast_tone_zone_ref ( struct ast_tone_zone tz)
inlinestatic

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.

217{
218 ao2_ref(tz, +1);
219 return tz;
220}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459

References ao2_ref, and tz.

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

◆ ast_tone_zone_sound_ref()

static struct ast_tone_zone_sound * ast_tone_zone_sound_ref ( struct ast_tone_zone_sound ts)
inlinestatic

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.

239{
240 ao2_ref(ts, +1);
241 return ts;
242}

References ao2_ref.

Referenced by ast_get_indication_tone().

◆ ast_tone_zone_sound_unref()

static struct ast_tone_zone_sound * ast_tone_zone_sound_unref ( struct ast_tone_zone_sound ts)
inlinestatic

◆ ast_tone_zone_unref()

static struct ast_tone_zone * ast_tone_zone_unref ( struct ast_tone_zone tz)
inlinestatic