Newer
Older
if (len > sizeof(ts->data) / 2 - 1) {
ast_log(LOG_WARNING, "Can't generate that much data!\n");
return -1;
}
memset(&ts->f, 0, sizeof(ts->f));
for (x=0;x<len/2;x++) {
ts->data[x] = ts->vol * (
sin((ts->freq1 * 2.0 * M_PI / 8000.0) * (ts->pos + x)) +
sin((ts->freq2 * 2.0 * M_PI / 8000.0) * (ts->pos + x))
);
}
ts->f.frametype = AST_FRAME_VOICE;
ts->f.subclass = AST_FORMAT_SLINEAR;
ts->f.datalen = len;
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
ts->f.offset = AST_FRIENDLY_OFFSET;
ts->f.data = ts->data;
ast_write(chan, &ts->f);
ts->pos += x;
if (ts->duration > 0) {
if (ts->pos >= ts->duration * 8)
return -1;
}
return 0;
}
static struct ast_generator tonepair = {
alloc: tonepair_alloc,
release: tonepair_release,
generate: tonepair_generator,
};
int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
{
struct tonepair_def d = { 0, };
d.freq1 = freq1;
d.freq2 = freq2;
d.duration = duration;
if (vol < 1)
d.vol = 8192;
else
d.vol = vol;
if (ast_activate_generator(chan, &tonepair, &d))
return -1;
return 0;
}
void ast_tonepair_stop(struct ast_channel *chan)
{
ast_deactivate_generator(chan);
}
int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
{
struct ast_frame *f;
int res;
if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
return res;
/* Give us some wiggle room */
while(chan->generatordata && (ast_waitfor(chan, 100) >= 0)) {
f = ast_read(chan);
if (f)
ast_frfree(f);
else
return -1;
}
return 0;
}
ast_group_t ast_get_group(char *s)
{
char *copy;
char *piece;
char *c=NULL;
int start=0, finish=0,x;
copy = ast_strdupa(s);
if (!copy) {
ast_log(LOG_ERROR, "Out of memory\n");
return 0;
}
c = copy;
while((piece = strsep(&c, ","))) {
if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
/* Range */
} else if (sscanf(piece, "%d", &start)) {
/* Just one */
finish = start;
} else {
ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'.\n", s, piece);
continue;
}
for (x=start;x<=finish;x++) {
if ((x > 63) || (x < 0)) {
ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
} else
group |= (1 << x);
}
}
return group;
}
static int (*ast_moh_start_ptr)(struct ast_channel *, char *) = NULL;
static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL;
Mark Spencer
committed
static void (*ast_moh_cleanup_ptr)(struct ast_channel *) = NULL;
void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, char *),
Mark Spencer
committed
void (*stop_ptr)(struct ast_channel *),
void (*cleanup_ptr)(struct ast_channel *)
)
{
ast_moh_start_ptr = start_ptr;
ast_moh_stop_ptr = stop_ptr;
Mark Spencer
committed
ast_moh_cleanup_ptr = cleanup_ptr;
}
void ast_uninstall_music_functions(void)
{
ast_moh_start_ptr = NULL;
ast_moh_stop_ptr = NULL;
Mark Spencer
committed
ast_moh_cleanup_ptr = NULL;
}
/*! Turn on/off music on hold on a given channel */
int ast_moh_start(struct ast_channel *chan, char *mclass)
{
if(ast_moh_start_ptr)
return ast_moh_start_ptr(chan, mclass);
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : "default");
return 0;
}
void ast_moh_stop(struct ast_channel *chan)
{
if(ast_moh_stop_ptr)
ast_moh_stop_ptr(chan);
}
Mark Spencer
committed
void ast_moh_cleanup(struct ast_channel *chan)
{
if(ast_moh_cleanup_ptr)
ast_moh_cleanup_ptr(chan);
}
void ast_channels_init(void)
{
ast_cli_register(&cli_show_channeltypes);
}
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
/*--- ast_print_group: Print call group and pickup group ---*/
char *ast_print_group(char *buf, int buflen, ast_group_t group)
{
unsigned int i;
int first=1;
char num[3];
buf[0] = '\0';
if (!group) /* Return empty string if no group */
return(buf);
for (i=0; i<=63; i++) { /* Max group is 63 */
if (group & (1 << i)) {
if (!first) {
strncat(buf, ", ", buflen);
} else {
first=0;
}
snprintf(num, sizeof(num), "%u", i);
strncat(buf, num, buflen);
}
}
return(buf);
}