file_string write failover FS-4930
This commit is contained in:
parent
9486a645f8
commit
83acda0413
|
@ -4483,24 +4483,32 @@ SWITCH_STANDARD_APP(limit_hash_execute_function)
|
||||||
/* for apr_pstrcat */
|
/* for apr_pstrcat */
|
||||||
#define DEFAULT_PREBUFFER_SIZE 1024 * 64
|
#define DEFAULT_PREBUFFER_SIZE 1024 * 64
|
||||||
|
|
||||||
struct file_string_source;
|
struct file_string_audio_col {
|
||||||
|
switch_audio_col_t col;
|
||||||
|
char *value;
|
||||||
|
struct file_string_audio_col *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct file_string_audio_col file_string_audio_col_t;
|
||||||
|
|
||||||
struct file_string_context {
|
struct file_string_context {
|
||||||
|
char *file;
|
||||||
char *argv[128];
|
char *argv[128];
|
||||||
int argc;
|
int argc;
|
||||||
int index;
|
int index;
|
||||||
int samples;
|
int samples;
|
||||||
switch_file_handle_t fh;
|
switch_file_handle_t fh;
|
||||||
|
file_string_audio_col_t *audio_cols;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct file_string_context file_string_context_t;
|
typedef struct file_string_context file_string_context_t;
|
||||||
|
|
||||||
|
|
||||||
static switch_status_t next_file(switch_file_handle_t *handle)
|
static switch_status_t next_file(switch_file_handle_t *handle)
|
||||||
{
|
{
|
||||||
file_string_context_t *context = handle->private_info;
|
file_string_context_t *context = handle->private_info;
|
||||||
char *file;
|
char *file;
|
||||||
const char *prefix = handle->prefix;
|
const char *prefix = handle->prefix;
|
||||||
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
top:
|
top:
|
||||||
|
|
||||||
|
@ -4544,6 +4552,11 @@ static switch_status_t next_file(switch_file_handle_t *handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_core_file_open(&context->fh, file, handle->channels, handle->samplerate, handle->flags, NULL) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_file_open(&context->fh, file, handle->channels, handle->samplerate, handle->flags, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open file %s\n", file);
|
||||||
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
|
switch_file_remove(file, handle->memory_pool);
|
||||||
|
}
|
||||||
goto top;
|
goto top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4553,6 +4566,39 @@ static switch_status_t next_file(switch_file_handle_t *handle)
|
||||||
handle->dbuf = NULL;
|
handle->dbuf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
|
file_string_audio_col_t *col_ptr = context->audio_cols;
|
||||||
|
|
||||||
|
while (col_ptr) {
|
||||||
|
switch_core_file_set_string(&context->fh, col_ptr->col, col_ptr->value);
|
||||||
|
col_ptr = col_ptr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->file && switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) { /* TODO handle other data type flags */
|
||||||
|
switch_size_t len;
|
||||||
|
uint16_t buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
|
||||||
|
switch_status_t status;
|
||||||
|
switch_file_handle_t fh = { 0 };
|
||||||
|
|
||||||
|
if ((status = switch_core_file_open(&fh, context->file, handle->channels, handle->samplerate,
|
||||||
|
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
do {
|
||||||
|
len = SWITCH_RECOMMENDED_BUFFER_SIZE / handle->channels;
|
||||||
|
if ((status = switch_core_file_read(&fh, buf, &len)) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
status = switch_core_file_write(&context->fh, buf, &len);
|
||||||
|
}
|
||||||
|
} while (status == SWITCH_STATUS_SUCCESS);
|
||||||
|
|
||||||
|
switch_core_file_close(&fh);
|
||||||
|
switch_file_remove(context->file, handle->memory_pool);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", context->file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context->file = file;
|
||||||
|
|
||||||
handle->samples = context->fh.samples;
|
handle->samples = context->fh.samples;
|
||||||
handle->cur_samplerate = context->fh.samplerate;
|
handle->cur_samplerate = context->fh.samplerate;
|
||||||
handle->cur_channels = context->fh.real_channels;
|
handle->cur_channels = context->fh.real_channels;
|
||||||
|
@ -4577,7 +4623,7 @@ static switch_status_t next_file(switch_file_handle_t *handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4626,6 +4672,36 @@ static switch_status_t file_string_file_close(switch_file_handle_t *handle)
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static switch_status_t file_string_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
|
||||||
|
{
|
||||||
|
file_string_context_t *context = handle->private_info;
|
||||||
|
file_string_audio_col_t *col_ptr = context->audio_cols;
|
||||||
|
|
||||||
|
while (col_ptr && col != col_ptr->col) {
|
||||||
|
col_ptr = col_ptr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (col_ptr) {
|
||||||
|
col_ptr->value = switch_core_strdup(handle->memory_pool, string);
|
||||||
|
} else {
|
||||||
|
col_ptr = switch_core_alloc(handle->memory_pool, sizeof(*col_ptr));
|
||||||
|
col_ptr->value = switch_core_strdup(handle->memory_pool, string);
|
||||||
|
col_ptr->col = col;
|
||||||
|
col_ptr->next = context->audio_cols;
|
||||||
|
context->audio_cols = col_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch_core_file_set_string(&context->fh, col, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
static switch_status_t file_string_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
|
||||||
|
{
|
||||||
|
file_string_context_t *context = handle->private_info;
|
||||||
|
|
||||||
|
return switch_core_file_get_string(&context->fh, col, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static switch_status_t file_string_file_read(switch_file_handle_t *handle, void *data, size_t *len)
|
static switch_status_t file_string_file_read(switch_file_handle_t *handle, void *data, size_t *len)
|
||||||
{
|
{
|
||||||
file_string_context_t *context = handle->private_info;
|
file_string_context_t *context = handle->private_info;
|
||||||
|
@ -5644,6 +5720,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
|
||||||
file_interface->file_read = file_string_file_read;
|
file_interface->file_read = file_string_file_read;
|
||||||
file_interface->file_write = file_string_file_write;
|
file_interface->file_write = file_string_file_write;
|
||||||
file_interface->file_seek = file_string_file_seek;
|
file_interface->file_seek = file_string_file_seek;
|
||||||
|
file_interface->file_set_string = file_string_file_set_string;
|
||||||
|
file_interface->file_get_string = file_string_file_get_string;
|
||||||
|
|
||||||
file_url_supported_formats[0] = "file";
|
file_url_supported_formats[0] = "file";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue