mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-05-03 06:52:05 +00:00
add params to soundfiles and implement ;timeout=N to set a particular timeout in milliseconds especially usefule with streams that never end naturally like local_stream://
This commit is contained in:
parent
3fc0f2f28d
commit
d9c4b269b6
@ -351,6 +351,7 @@ struct switch_file_handle {
|
|||||||
char *file_path;
|
char *file_path;
|
||||||
char *spool_path;
|
char *spool_path;
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
int max_samples;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief Abstract interface to an asr module */
|
/*! \brief Abstract interface to an asr module */
|
||||||
|
@ -47,6 +47,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
|
|||||||
char *rhs = NULL;
|
char *rhs = NULL;
|
||||||
const char *spool_path = NULL;
|
const char *spool_path = NULL;
|
||||||
int is_stream = 0;
|
int is_stream = 0;
|
||||||
|
char *fp = NULL, *params = NULL;
|
||||||
|
int to = 0;
|
||||||
|
|
||||||
if (switch_test_flag(fh, SWITCH_FILE_OPEN)) {
|
if (switch_test_flag(fh, SWITCH_FILE_OPEN)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Handle already open\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Handle already open\n");
|
||||||
@ -76,6 +78,25 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
|
|||||||
switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
|
switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strchr(file_path, ';')) {
|
||||||
|
char *timeout;
|
||||||
|
|
||||||
|
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 ((to = atoi(timeout)) < 1) {
|
||||||
|
to = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (switch_directory_exists(file_path, fh->memory_pool) == SWITCH_STATUS_SUCCESS) {
|
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);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "File [%s] is a directory not a file.\n", file_path);
|
||||||
status = SWITCH_STATUS_GENERR;
|
status = SWITCH_STATUS_GENERR;
|
||||||
@ -175,6 +196,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
|
|||||||
switch_goto_status(status, fail);
|
switch_goto_status(status, fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (to) {
|
||||||
|
fh->max_samples = (fh->samplerate / 1000) * to;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((flags & SWITCH_FILE_FLAG_READ)) {
|
if ((flags & SWITCH_FILE_FLAG_READ)) {
|
||||||
fh->native_rate = fh->samplerate;
|
fh->native_rate = fh->samplerate;
|
||||||
} else {
|
} else {
|
||||||
@ -226,6 +252,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
|
|||||||
|
|
||||||
top:
|
top:
|
||||||
|
|
||||||
|
if (fh->max_samples > 0 && fh->samples_in >= fh->max_samples) {
|
||||||
|
*len = 0;
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (fh->buffer && switch_buffer_inuse(fh->buffer) >= *len * 2) {
|
if (fh->buffer && switch_buffer_inuse(fh->buffer) >= *len * 2) {
|
||||||
*len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
|
*len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user