Tone Indication Support. More...
#include "asterisk/astobj2.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... | |
Defines | |
| #define | ast_tone_zone_lock(tz) ao2_lock(tz) |
| Lock an ast_tone_zone. | |
| #define | ast_tone_zone_trylock(tz) ao2_trylock(tz) |
| Trylock an ast_tone_zone. | |
| #define | ast_tone_zone_unlock(tz) ao2_unlock(tz) |
| Unlock an ast_tone_zone. | |
Functions | |
| struct ast_tone_zone_sound * | ast_get_indication_tone (const struct ast_tone_zone *zone, const char *indication) |
| Locate a tone zone sound. | |
| struct ast_tone_zone * | ast_get_indication_zone (const char *country) |
| locate ast_tone_zone | |
| int | ast_playtones_start (struct ast_channel *chan, int vol, const char *tonelist, int interruptible) |
| Start playing a list of tones on a channel. | |
| void | ast_playtones_stop (struct ast_channel *chan) |
| Stop playing tones on a channel. | |
| int | ast_tone_zone_count (void) |
| Get the number of registered tone zones. | |
| struct ao2_iterator | ast_tone_zone_iterator_init (void) |
| Get an iterator for the available tone zones. | |
| int | ast_tone_zone_part_parse (const char *s, struct ast_tone_zone_part *tone_data) |
| Parse a tone part. | |
| static struct ast_tone_zone * | ast_tone_zone_ref (struct ast_tone_zone *tz) |
| Increase the reference count on an ast_tone_zone. | |
| 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. | |
| static struct ast_tone_zone_sound * | ast_tone_zone_sound_unref (struct ast_tone_zone_sound *ts) |
| Release a reference to an ast_tone_zone_sound. | |
| static struct ast_tone_zone * | ast_tone_zone_unref (struct ast_tone_zone *tz) |
| Release a reference to an ast_tone_zone. | |
Tone Indication Support.
Definition in file indications.h.
| #define ast_tone_zone_lock | ( | tz | ) | ao2_lock(tz) |
Lock an ast_tone_zone.
Definition at line 184 of file indications.h.
Referenced by ast_get_indication_tone(), ast_unregister_indication(), ast_var_indications_table(), complete_indications(), handle_cli_indication_add(), handle_cli_indication_show(), is_valid_tone_zone(), parse_tone_zone(), prune_tone_zone(), reset_tone_zone(), and tone_zone_mark().
| #define ast_tone_zone_trylock | ( | tz | ) | ao2_trylock(tz) |
Trylock an ast_tone_zone.
Definition at line 194 of file indications.h.
| #define ast_tone_zone_unlock | ( | tz | ) | ao2_unlock(tz) |
Unlock an ast_tone_zone.
Definition at line 189 of file indications.h.
Referenced by ast_get_indication_tone(), ast_unregister_indication(), ast_var_indications_table(), complete_indications(), handle_cli_indication_add(), handle_cli_indication_show(), is_valid_tone_zone(), parse_tone_zone(), prune_tone_zone(), reset_tone_zone(), and tone_zone_mark().
| struct ast_tone_zone_sound* ast_get_indication_tone | ( | const struct ast_tone_zone * | zone, | |
| const char * | indication | |||
| ) | [read] |
Locate a tone zone sound.
| zone | Zone to look in for a sound, if NULL, the default will be used | |
| indication | Sound to look for, such as "busy" |
Definition at line 452 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_sound::name, and ast_tone_zone::tones.
Referenced by ast_app_dtget(), ast_indicate_data(), dialtone_indicate(), handle_playtones(), in_band_indication(), pbx_builtin_waitexten(), play_dialtone(), read_exec(), readexten_exec(), and skinny_transfer().
00453 { 00454 struct ast_tone_zone_sound *ts = NULL; 00455 /* _zone is const to the users of the API */ 00456 struct ast_tone_zone *zone = (struct ast_tone_zone *) _zone; 00457 00458 /* If no zone is specified, use the default */ 00459 if (!zone) { 00460 ao2_lock(ast_tone_zones); 00461 if (default_tone_zone) { 00462 zone = ast_tone_zone_ref(default_tone_zone); 00463 } 00464 ao2_unlock(ast_tone_zones); 00465 00466 if (!zone) { 00467 return NULL; 00468 } 00469 } 00470 00471 ast_tone_zone_lock(zone); 00472 00473 /* Look through list of tones in the zone searching for the right one */ 00474 AST_LIST_TRAVERSE(&zone->tones, ts, entry) { 00475 if (!strcasecmp(ts->name, indication)) { 00476 /* Increase ref count for the reference we will return */ 00477 ts = ast_tone_zone_sound_ref(ts); 00478 break; 00479 } 00480 } 00481 00482 ast_tone_zone_unlock(zone); 00483 00484 return ts; 00485 }
| struct ast_tone_zone* ast_get_indication_zone | ( | const char * | country | ) | [read] |
locate ast_tone_zone
| country | country to find. If NULL is provided, get the default. |
Definition at line 430 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, and OBJ_POINTER.
Referenced by ast_set_indication_country(), ast_var_indications(), build_device(), func_channel_write(), handle_cli_indication_add(), and handle_cli_indication_remove().
00431 { 00432 struct ast_tone_zone *tz = NULL; 00433 struct ast_tone_zone zone_arg = { 00434 .nrringcadence = 0, 00435 }; 00436 00437 if (ast_strlen_zero(country)) { 00438 ao2_lock(ast_tone_zones); 00439 if (default_tone_zone) { 00440 tz = ast_tone_zone_ref(default_tone_zone); 00441 } 00442 ao2_unlock(ast_tone_zones); 00443 00444 return tz; 00445 } 00446 00447 ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country)); 00448 00449 return ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER); 00450 }
| int ast_playtones_start | ( | struct ast_channel * | chan, | |
| int | vol, | |||
| const char * | tonelist, | |||
| int | interruptible | |||
| ) |
Start playing a list of tones on a channel.
| chan | the channel to play tones on | |
| vol | volume | |
| tonelist | the list of tones to play, comma separated | |
| interruptible | whether or not this tone can be interrupted |
| 0 | success | |
| non-zero | failure |
Definition at line 301 of file indications.c.
References ast_activate_generator(), ast_free, ast_log(), ast_realloc, 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, ast_tone_zone_part::midinote, ast_tone_zone_part::modulate, playtones_item::modulate, playtones_def::nitems, playtones_def::reppos, s, ast_tone_zone_part::time, and playtones_def::vol.
00302 { 00303 char *s, *data = ast_strdupa(playlst); 00304 struct playtones_def d = { vol, -1, 0, 1, NULL }; 00305 char *stringp; 00306 char *separator; 00307 static const float sample_rate = 8000.0; 00308 static const float max_sample_val = 32768.0; 00309 00310 if (vol < 1) { 00311 d.vol = 7219; /* Default to -8db */ 00312 } 00313 00314 d.interruptible = interruptible; 00315 00316 stringp = data; 00317 00318 /* check if the data is separated with '|' or with ',' by default */ 00319 if (strchr(stringp,'|')) { 00320 separator = "|"; 00321 } else { 00322 separator = ","; 00323 } 00324 00325 while ((s = strsep(&stringp, separator)) && !ast_strlen_zero(s)) { 00326 struct ast_tone_zone_part tone_data = { 00327 .time = 0, 00328 }; 00329 00330 s = ast_strip(s); 00331 00332 if (s[0]=='!') { 00333 s++; 00334 } else if (d.reppos == -1) { 00335 d.reppos = d.nitems; 00336 } 00337 00338 if (ast_tone_zone_part_parse(s, &tone_data)) { 00339 ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s); 00340 continue; 00341 } 00342 00343 if (tone_data.midinote) { 00344 /* midi notes must be between 0 and 127 */ 00345 00346 if (tone_data.freq1 >= 0 && tone_data.freq1 <= 127) { 00347 tone_data.freq1 = midi_tohz[tone_data.freq1]; 00348 } else { 00349 tone_data.freq1 = 0; 00350 } 00351 00352 if (tone_data.freq2 >= 0 && tone_data.freq2 <= 127) { 00353 tone_data.freq2 = midi_tohz[tone_data.freq2]; 00354 } else { 00355 tone_data.freq2 = 0; 00356 } 00357 } 00358 00359 if (!(d.items = ast_realloc(d.items, (d.nitems + 1) * sizeof(*d.items)))) { 00360 return -1; 00361 } 00362 00363 d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (tone_data.freq1 / sample_rate)) * max_sample_val; 00364 d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol; 00365 d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol; 00366 00367 d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (tone_data.freq2 / sample_rate)) * max_sample_val; 00368 d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol; 00369 d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol; 00370 00371 d.items[d.nitems].duration = tone_data.time; 00372 d.items[d.nitems].modulate = tone_data.modulate; 00373 00374 d.nitems++; 00375 } 00376 00377 if (!d.nitems) { 00378 ast_log(LOG_ERROR, "No valid tone parts\n"); 00379 return -1; 00380 } 00381 00382 if (ast_activate_generator(chan, &playtones, &d)) { 00383 ast_free(d.items); 00384 return -1; 00385 } 00386 00387 return 0; 00388 }
| void ast_playtones_stop | ( | struct ast_channel * | chan | ) |
Stop playing tones on a channel.
| chan | the channel to stop tones on |
Stop the tones from playing
Definition at line 390 of file indications.c.
References ast_deactivate_generator().
00391 { 00392 ast_deactivate_generator(chan); 00393 }
| int ast_tone_zone_count | ( | void | ) |
Get the number of registered tone zones.
Definition at line 395 of file indications.c.
References ao2_container_count().
00396 { 00397 return ao2_container_count(ast_tone_zones); 00398 }
| struct ao2_iterator ast_tone_zone_iterator_init | ( | void | ) | [read] |
Get an iterator for the available tone zones.
Use ao2_iterator_next() to iterate the tone zones.
Definition at line 400 of file indications.c.
References ao2_iterator_init().
Referenced by ast_var_indications(), ast_var_indications_table(), and handle_cli_indication_show().
00401 { 00402 return ao2_iterator_init(ast_tone_zones, 0); 00403 }
| int ast_tone_zone_part_parse | ( | const char * | s, | |
| struct ast_tone_zone_part * | tone_data | |||
| ) |
Parse a tone part.
| s | The 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_data | An output parameter that contains the result of the parsing. |
| 0 | success | |
| -1 | failure, and the contents of tone_data are undefined |
Definition at line 244 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().
00245 { 00246 if (sscanf(s, "%30u+%30u/%30u", &tone_data->freq1, &tone_data->freq2, 00247 &tone_data->time) == 3) { 00248 /* f1+f2/time format */ 00249 } else if (sscanf(s, "%30u+%30u", &tone_data->freq1, &tone_data->freq2) == 2) { 00250 /* f1+f2 format */ 00251 tone_data->time = 0; 00252 } else if (sscanf(s, "%30u*%30u/%30u", &tone_data->freq1, &tone_data->freq2, 00253 &tone_data->time) == 3) { 00254 /* f1*f2/time format */ 00255 tone_data->modulate = 1; 00256 } else if (sscanf(s, "%30u*%30u", &tone_data->freq1, &tone_data->freq2) == 2) { 00257 /* f1*f2 format */ 00258 tone_data->time = 0; 00259 tone_data->modulate = 1; 00260 } else if (sscanf(s, "%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) { 00261 /* f1/time format */ 00262 tone_data->freq2 = 0; 00263 } else if (sscanf(s, "%30u", &tone_data->freq1) == 1) { 00264 /* f1 format */ 00265 tone_data->freq2 = 0; 00266 tone_data->time = 0; 00267 } else if (sscanf(s, "M%30u+M%30u/%30u", &tone_data->freq1, &tone_data->freq2, 00268 &tone_data->time) == 3) { 00269 /* Mf1+Mf2/time format */ 00270 tone_data->midinote = 1; 00271 } else if (sscanf(s, "M%30u+M%30u", &tone_data->freq1, &tone_data->freq2) == 2) { 00272 /* Mf1+Mf2 format */ 00273 tone_data->time = 0; 00274 tone_data->midinote = 1; 00275 } else if (sscanf(s, "M%30u*M%30u/%30u", &tone_data->freq1, &tone_data->freq2, 00276 &tone_data->time) == 3) { 00277 /* Mf1*Mf2/time format */ 00278 tone_data->modulate = 1; 00279 tone_data->midinote = 1; 00280 } else if (sscanf(s, "M%30u*M%30u", &tone_data->freq1, &tone_data->freq2) == 2) { 00281 /* Mf1*Mf2 format */ 00282 tone_data->time = 0; 00283 tone_data->modulate = 1; 00284 tone_data->midinote = 1; 00285 } else if (sscanf(s, "M%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) { 00286 /* Mf1/time format */ 00287 tone_data->freq2 = -1; 00288 tone_data->midinote = 1; 00289 } else if (sscanf(s, "M%30u", &tone_data->freq1) == 1) { 00290 /* Mf1 format */ 00291 tone_data->freq2 = -1; 00292 tone_data->time = 0; 00293 tone_data->midinote = 1; 00294 } else { 00295 return -1; 00296 } 00297 00298 return 0; 00299 }
| static struct ast_tone_zone* ast_tone_zone_ref | ( | struct ast_tone_zone * | tz | ) | [static, read] |
Increase the reference count on an ast_tone_zone.
Definition at line 212 of file indications.h.
References ao2_ref.
Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication_country(), ast_set_indication_country(), and func_channel_write().
00213 { 00214 ao2_ref(tz, +1); 00215 return tz; 00216 }
| static struct ast_tone_zone_sound* ast_tone_zone_sound_ref | ( | struct ast_tone_zone_sound * | ts | ) | [static, read] |
Increase the reference count on an ast_tone_zone_sound.
Definition at line 234 of file indications.h.
References ao2_ref.
Referenced by ast_get_indication_tone().
00235 { 00236 ao2_ref(ts, +1); 00237 return ts; 00238 }
| static struct ast_tone_zone_sound* ast_tone_zone_sound_unref | ( | struct ast_tone_zone_sound * | ts | ) | [static, read] |
Release a reference to an ast_tone_zone_sound.
Definition at line 223 of file indications.h.
References ao2_ref.
Referenced by ast_app_dtget(), ast_indicate_data(), ast_register_indication(), ast_tone_zone_destructor(), ast_unregister_indication(), handle_playtones(), in_band_indication(), pbx_builtin_waitexten(), play_dialtone(), prune_tone_zone(), read_exec(), readexten_exec(), skinny_transfer(), and stop_indicate().
00224 { 00225 ao2_ref(ts, -1); 00226 return NULL; 00227 }
| static struct ast_tone_zone* ast_tone_zone_unref | ( | struct ast_tone_zone * | tz | ) | [static, read] |
Release a reference to an ast_tone_zone.
Definition at line 201 of file indications.h.
References ao2_ref.
Referenced by ast_channel_free(), ast_set_indication_country(), ast_unregister_indication_country(), ast_var_indications(), ast_var_indications_table(), build_device(), complete_country(), complete_indications(), func_channel_write(), handle_cli_indication_add(), handle_cli_indication_remove(), handle_cli_indication_show(), parse_tone_zone(), and reload_config().
00202 { 00203 ao2_ref(tz, -1); 00204 return NULL; 00205 }
1.6.2