From 65631ed36b04566654410b7b22fc5cf8aa48a566 Mon Sep 17 00:00:00 2001 From: Brian West <brian@freeswitch.org> Date: Mon, 29 Dec 2014 10:02:31 -0600 Subject: [PATCH] Revert FS-7004 pending updated fixed for that issue from the original author. --- src/mod/formats/mod_sndfile/mod_sndfile.c | 25 +++-------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/mod/formats/mod_sndfile/mod_sndfile.c b/src/mod/formats/mod_sndfile/mod_sndfile.c index 4b6e9112a6..5d8d0865b5 100644 --- a/src/mod/formats/mod_sndfile/mod_sndfile.c +++ b/src/mod/formats/mod_sndfile/mod_sndfile.c @@ -54,13 +54,10 @@ struct sndfile_context { typedef struct sndfile_context sndfile_context; -static switch_status_t sndfile_perform_open(sndfile_context *context, const char *path, const char *mask, int mode); - static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const char *path) { sndfile_context *context; int mode = 0; - const char *mask = "rb"; char *ext; struct format_map *map = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; @@ -87,10 +84,8 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND) || switch_test_flag(handle, SWITCH_FILE_WRITE_OVER) || handle->offset_pos) { - mask = "ab+"; mode += SFM_RDWR; } else { - mask = "wb+"; mode += SFM_WRITE; } } @@ -186,7 +181,7 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha ldup = strdup(last); switch_assert(ldup); switch_snprintf(last, alt_len - (last - alt_path), "%d%s%s", handle->samplerate, SWITCH_PATH_SEPARATOR, ldup); - if (sndfile_perform_open(context, alt_path, mask, mode) == SWITCH_STATUS_SUCCESS) { + if ((context->handle = sf_open(alt_path, mode, &context->sfinfo))) { path = alt_path; } else { /* Try to find the file at the highest rate possible if we can't find one that matches the exact rate. @@ -194,7 +189,7 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha */ for (i = 3; i >= 0; i--) { switch_snprintf(last, alt_len - (last - alt_path), "%d%s%s", rates[i], SWITCH_PATH_SEPARATOR, ldup); - if (sndfile_perform_open(context, alt_path, mask, mode) == SWITCH_STATUS_SUCCESS) { + if ((context->handle = sf_open(alt_path, mode, &context->sfinfo))) { path = alt_path; break; } @@ -203,7 +198,7 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha } if (!context->handle) { - if (sndfile_perform_open(context, path, mask, mode) != SWITCH_STATUS_SUCCESS) { + if ((context->handle = sf_open(path, mode, &context->sfinfo)) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle)); status = SWITCH_STATUS_GENERR; goto end; @@ -241,20 +236,6 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha return status; } -static switch_status_t sndfile_perform_open(sndfile_context *context, const char *path, const char *mask, int mode) -{ - FILE *fd = NULL; - fd = fopen(path, mask); - if (!fd) { - return SWITCH_STATUS_FALSE; - } - if ((context->handle = sf_open_fd(fileno(fd), mode, &context->sfinfo, SWITCH_TRUE)) == 0) { - fclose(fd); - return SWITCH_STATUS_FALSE; - } - return SWITCH_STATUS_SUCCESS; -} - static switch_status_t sndfile_file_truncate(switch_file_handle_t *handle, int64_t offset) { sndfile_context *context = handle->private_info;