static int record_file(struct stasis_app_control *control, struct ast_channel *chan, void *data) { struct stasis_app_recording *recording = data; char *acceptdtmf; int res; ast_assert(recording != NULL); if (stasis_app_get_bridge(control)) { ast_log(LOG_ERROR, "Cannot record channel while in bridge\n"); recording_fail(control, recording, "Cannot record channel while in bridge"); return -1; } switch (recording->options->terminate_on) { case STASIS_APP_RECORDING_TERMINATE_NONE: case STASIS_APP_RECORDING_TERMINATE_INVALID: acceptdtmf = ""; break; case STASIS_APP_RECORDING_TERMINATE_ANY: acceptdtmf = "#*0123456789abcd"; break; default: acceptdtmf = ast_alloca(2); acceptdtmf[0] = recording->options->terminate_on; acceptdtmf[1] = '\0'; } res = ast_auto_answer(chan); if (res != 0) { ast_debug(3, "%s: Failed to answer\n", ast_channel_uniqueid(chan)); recording_fail(control, recording, "Failed to answer channel"); return -1; } recording_set_state( recording, STASIS_APP_RECORDING_STATE_RECORDING, NULL); ast_play_and_record_full(chan, NULL, /* playfile */ recording->absolute_name, recording->options->max_duration_seconds, recording->options->format, &recording->duration.total, recording->options->max_silence_seconds ? &recording->duration.energy_only : NULL, recording->options->beep, -1, /* silencethreshold */ recording->options->max_silence_seconds * 1000, NULL, /* path */ acceptdtmf, NULL, /* canceldtmf */ 1, /* skip_confirmation_sound */ recording->options->if_exists); ast_debug(3, "%s: Recording complete\n", ast_channel_uniqueid(chan)); recording_set_state( recording, STASIS_APP_RECORDING_STATE_COMPLETE, NULL); stasis_app_control_unregister_add_rule(control, &rule_recording); return 0; }
static void *record_file(struct stasis_app_control *control, struct ast_channel *chan, void *data) { RAII_VAR(struct stasis_app_recording *, recording, NULL, recording_cleanup); char *acceptdtmf; int res; int duration = 0; recording = data; ast_assert(recording != NULL); if (stasis_app_get_bridge(control)) { ast_log(LOG_ERROR, "Cannot record channel while in bridge\n"); recording_fail(recording); return NULL; } switch (recording->options->terminate_on) { case STASIS_APP_RECORDING_TERMINATE_NONE: case STASIS_APP_RECORDING_TERMINATE_INVALID: acceptdtmf = ""; break; case STASIS_APP_RECORDING_TERMINATE_ANY: acceptdtmf = "#*0123456789abcd"; break; default: acceptdtmf = ast_alloca(2); acceptdtmf[0] = recording->options->terminate_on; acceptdtmf[1] = '\0'; } res = ast_auto_answer(chan); if (res != 0) { ast_debug(3, "%s: Failed to answer\n", ast_channel_uniqueid(chan)); recording_fail(recording); return NULL; } ao2_lock(recording); recording->state = STASIS_APP_RECORDING_STATE_RECORDING; recording_publish(recording); ao2_unlock(recording); ast_play_and_record_full(chan, NULL, /* playfile */ recording->absolute_name, recording->options->max_duration_seconds, recording->options->format, &duration, NULL, /* sound_duration */ recording->options->beep, -1, /* silencethreshold */ recording->options->max_silence_seconds * 1000, NULL, /* path */ acceptdtmf, NULL, /* canceldtmf */ 1, /* skip_confirmation_sound */ recording->options->if_exists); ast_debug(3, "%s: Recording complete\n", ast_channel_uniqueid(chan)); ao2_lock(recording); recording->state = STASIS_APP_RECORDING_STATE_COMPLETE; recording_publish(recording); ao2_unlock(recording); return NULL; }