static void *playtones_alloc(struct ast_channel *chan, void *params) { struct playtones_def *pd = params; struct playtones_state *ps = NULL; if (!(ps = ast_calloc(1, sizeof(*ps)))) { return NULL; } ast_format_copy(&ps->origwfmt, ast_channel_writeformat(chan)); if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) { ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan)); playtones_release(NULL, ps); ps = NULL; } else { ps->vol = pd->vol; ps->reppos = pd->reppos; ps->nitems = pd->nitems; ps->items = pd->items; ps->oldnpos = -1; } /* Let interrupts interrupt :) */ if (pd->interruptible) { ast_set_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT); } else { ast_clear_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT); } return ps; }
static void *playtones_alloc(struct cw_channel *chan, void *params) { struct playtones_def *pd = params; struct playtones_state *ps; if ((ps = malloc(sizeof(*ps))) == NULL) return NULL; memset(ps, 0, sizeof(*ps)); ps->origwfmt = chan->writeformat; if (cw_set_write_format(chan, CW_FORMAT_SLINEAR)) { cw_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name); playtones_release(NULL, ps); ps = NULL; } else { struct playtones_item *pi; ps->vol = pd->vol; ps->reppos = pd->reppos; ps->nitems = pd->nitems; ps->items = pd->items; /* Initialize the tone generator */ pi = &pd->items[0]; tone_setup(ps, pi); } /* Let interrupts interrupt :) */ if (pd->interruptible) cw_set_flag(chan, CW_FLAG_WRITE_INT); else cw_clear_flag(chan, CW_FLAG_WRITE_INT); return ps; }