char *spool_path;
const char *prefix;
int max_samples;
+ switch_event_t *params;
};
/*! \brief Abstract interface to an asr module */
handle->seekable = context->fh.seekable;
handle->speed = context->fh.speed;
handle->interval = context->fh.interval;
+ handle->max_samples = 0;
if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) {
switch_set_flag(handle, SWITCH_FILE_NATIVE);
switch_buffer_create_dynamic(&audio_buffer, 1024, 1024, 0);
switch_assert(audio_buffer);
- if ((tmp = strstr(tonespec, ";loops="))) {
- *tmp = '\0';
- loops = atoi(tmp + 7);
- switch_buffer_set_loops(audio_buffer, loops);
+ if (handle->params) {
+ if ((tmp = switch_event_get_header(handle->params, "loops"))) {
+ loops = atoi(tmp);
+ switch_buffer_set_loops(audio_buffer, loops);
+ }
}
if (!handle->samplerate) {
char *rhs = NULL;
const char *spool_path = NULL;
int is_stream = 0;
- char *fp = NULL, *params = NULL;
+ char *fp = NULL;
+ switch_event_t *params = NULL;
int to = 0;
if (switch_test_flag(fh, SWITCH_FILE_OPEN)) {
return SWITCH_STATUS_FALSE;
}
+ fh->samples_in = 0;
+
if (!fh->samplerate) {
if (!(fh->samplerate = rate)) {
fh->samplerate = 8000;
switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
}
- if (strchr(file_path, ';')) {
+ if (*file_path == '{') {
char *timeout;
-
+ char *new_fp;
fp = switch_core_strdup(fh->memory_pool, file_path);
- file_path = fp;
- if ((params = strchr(fp, ';'))) {
- *params++ = '\0';
-
- if ((timeout = switch_find_parameter(params, "timeout", fh->memory_pool))) {
+ if (switch_event_create_brackets(fp, '{', '}', ',', &fh->params, &new_fp, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
+ if ((timeout = switch_event_get_header(fh->params, "timeout"))) {
if ((to = atoi(timeout)) < 1) {
to = 0;
}
}
-
+ } else {
+ new_fp = fp;
}
+
+ file_path = new_fp;
}
-
if (switch_directory_exists(file_path, fh->memory_pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "File [%s] is a directory not a file.\n", file_path);
status = SWITCH_STATUS_GENERR;
file_path = fh->spool_path ? fh->spool_path : fh->file_path;
+ if (params) {
+ fh->params = params;
+ }
if ((status = fh->file_interface->file_open(fh, file_path)) != SWITCH_STATUS_SUCCESS) {
if (fh->spool_path) {
switch_clear_flag(fh, SWITCH_FILE_OPEN);
+ if (fh->params) {
+ switch_event_destroy(&fh->params);
+ }
+
+ fh->samples_in = 0;
+ fh->max_samples = 0;
+
if (switch_test_flag(fh, SWITCH_FILE_FLAG_FREE_POOL)) {
switch_core_destroy_memory_pool(&fh->memory_pool);
}
return SWITCH_STATUS_FALSE;
}
+ if (fh->params) {
+ switch_event_destroy(&fh->params);
+ }
+
+ fh->samples_in = 0;
+ fh->max_samples = 0;
+
if (fh->buffer) {
switch_buffer_destroy(&fh->buffer);
}
#define FILE_BLOCKSIZE 1024 * 8
#define FILE_BUFSIZE 1024 * 64
-static void add_playback_vars_to_event(switch_core_session_t *session, switch_event_t *event, char *vars)
-{
- char *tmp;
-
- if (!session || !event || !vars)
- return;
-
- if ((tmp = switch_core_session_strdup(session, vars))) {
- char *argv[128] = { 0 };
- int argc, i;
-
- if (!(argc = switch_separate_string(tmp, ',', argv, (sizeof(argv) / sizeof(argv[0])))))
- return;
-
- for (i = 0; i < argc; i++) {
- char *var, *val;
-
- if ((var = strchr(argv[i], '='))) {
- *var = '\0';
- val = var+1;
- var = argv[i];
-
- if (var && *var && val && *val) {
- if ((var = switch_core_session_sprintf(session, "playback_variable_%s", var))) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, var, val);
- }
- }
- }
- }
- }
-}
-
SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, const char *file, switch_input_args_t *args)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_bool_t timeout_as_success = SWITCH_FALSE;
const char *var;
int more_data = 0;
- char *playback_vars, *tmp;
switch_event_t *event;
uint32_t test_native = 0, last_native = 0;
}
}
- /* Try to parse extra parameters for this playback (parameters within {} at the end of the filename */
- playback_vars = NULL;
- if ((tmp = strchr(file, '{'))) {
- char *tfile, *e;
-
- if ((tfile = switch_core_session_strdup(session, tmp))) {
- if ((e = switch_find_end_paren(tfile, '{', '}')) && *(e + 1) == '\0') {
- *tmp = '\0';
- *e = '\0';
- playback_vars = tfile+1;
- }
- }
- }
-
if ((prebuf = switch_channel_get_variable(channel, "stream_prebuffer"))) {
int maybe = atoi(prebuf);
if (maybe > 0) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Type", "tone_stream");
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Path", file);
- add_playback_vars_to_event(session, event, playback_vars);
+ if (fh->params) {
+ switch_event_merge(event, fh->params);
+ }
switch_event_fire(&event);
}
} else {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-Status", "done");
}
- add_playback_vars_to_event(session, event, playback_vars);
+ if (fh->params) {
+ switch_event_merge(event, fh->params);
+ }
switch_event_fire(&event);
}