sample platter

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6706 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-12-12 21:30:55 +00:00
1 parent 2ff5e3ec40
commit 44636d333f
11 files changed
+239 -70

No files matched your search

@@ -1465,6 +1465,9 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread,
}
}
switch_resample_destroy(&member->read_resampler);
switch_resample_destroy(&member->mux_resampler);
switch_clear_flag_locked(member, MFLAG_ITHREAD);
return NULL;
+10 -1
View File
@@ -1239,7 +1239,9 @@ SWITCH_STANDARD_APP(record_function)
int argc;
char *mydata, *argv[4] = { 0 };
char *l = NULL;
const char *tmp;
int rate;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -1280,6 +1282,13 @@ SWITCH_STANDARD_APP(record_function)
}
}
if ((tmp = switch_channel_get_variable(channel, "record_rate"))) {
rate = atoi(tmp);
if (rate > 0) {
fh.samplerate = rate;
}
}
args.input_callback = on_dtmf;
status = switch_ivr_record_file(session, &fh, path, &args, limit);
@@ -79,7 +79,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
local_stream_context_t *cp;
char file_buf[128] = "", path_buf[512] = "";
switch_timer_t timer = {0};
int fd = -1;
if (switch_core_timer_init(&timer, source->timer_name, source->interval, source->samples, source->pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't start timer.\n");
@@ -89,7 +89,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
while(RUNNING) {
const char *fname;
if (switch_dir_open(&source->dir_handle, source->location, source->pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't open directory: %s\n", source->location);
return NULL;
@@ -98,27 +98,37 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "open directory: %s\n", source->location);
switch_yield(1000000);
while(RUNNING && (fname = switch_dir_next_file(source->dir_handle, file_buf, sizeof(file_buf)))) {
while(RUNNING) {
switch_size_t olen;
uint8_t abuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0};
snprintf(path_buf, sizeof(path_buf), "%s%s%s", source->location, SWITCH_PATH_SEPARATOR, fname);
if (switch_stristr(".loc", path_buf)) {
int fd, bytes;
if (fd > -1) {
char *p;
if (switch_fd_read_line(fd, path_buf, sizeof(path_buf))) {
if ((p = strchr(path_buf, '\r')) ||
(p = strchr(path_buf, '\n'))) {
*p = '\0';
}
} else {
close(fd);
fd = -1;
continue;
}
} else {
if (!(fname = switch_dir_next_file(source->dir_handle, file_buf, sizeof(file_buf)))) {
break;
}
if ((fd = open(path_buf, O_RDONLY)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", fname);
switch_yield(1000000);
snprintf(path_buf, sizeof(path_buf), "%s%s%s", source->location, SWITCH_PATH_SEPARATOR, fname);
if (switch_stristr(".loc", path_buf)) {
if ((fd = open(path_buf, O_RDONLY)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", fname);
switch_yield(1000000);
}
continue;
}
bytes = read(fd, path_buf, sizeof(path_buf));
if ((p = strchr(path_buf, '\r')) ||
(p = strchr(path_buf, '\n'))) {
*p = '\0';
}
close(fd);
}
fname = path_buf;
@@ -139,6 +149,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
while (RUNNING) {
switch_core_timer_next(&timer);
olen = source->samples;
if (switch_core_file_read(&fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
switch_core_file_close(&fh);
break;
@@ -156,8 +167,13 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
}
switch_dir_close(source->dir_handle);
source->dir_handle = NULL;
}
if (fd > -1) {
close(fd);
}
switch_core_destroy_memory_pool(&source->pool);
@@ -168,25 +184,37 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
{
local_stream_context_t *context;
local_stream_source_t *source;
char *alt_path = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n");
return SWITCH_STATUS_FALSE;
}
alt_path = switch_mprintf("%s/%d", path, handle->samplerate);
switch_mutex_lock(globals.mutex);
source = switch_core_hash_find(globals.source_hash, path);
if ((source = switch_core_hash_find(globals.source_hash, alt_path))) {
path = alt_path;
} else {
source = switch_core_hash_find(globals.source_hash, path);
}
switch_mutex_unlock(globals.mutex);
if (!source) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unknown source %s\n", path);
return SWITCH_STATUS_FALSE;
status = SWITCH_STATUS_FALSE;
goto end;
}
if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
return SWITCH_STATUS_MEMERR;
status = SWITCH_STATUS_MEMERR;
goto end;
}
handle->samples = 0;
handle->samplerate = source->rate;
handle->channels = source->channels;
@@ -201,7 +229,8 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
if (switch_buffer_create_dynamic(&context->audio_buffer, 512, 1024, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
return SWITCH_STATUS_MEMERR;
status = SWITCH_STATUS_MEMERR;
goto end;
}
context->source = source;
@@ -211,8 +240,9 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
source->context_list = context;
switch_mutex_unlock(source->mutex);
return SWITCH_STATUS_SUCCESS;
end:
switch_safe_free(alt_path);
return status;
}
static switch_status_t local_stream_file_close(switch_file_handle_t *handle)
@@ -350,6 +380,7 @@ static void launch_threads(void)
}
source->samples = switch_bytes_per_frame(source->rate, source->interval);
switch_core_hash_insert(globals.source_hash, source->name, source);
switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool);
@@ -26,7 +26,7 @@
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* mod_native_file.c -- Framework Demo Module
* mod_native_file.c -- Native Files
*
*/
#include <switch.h>
+32 -5
View File
@@ -61,6 +61,9 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
int mode = 0;
char *ext;
struct format_map *map = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *alt_path = NULL, *next, *last, *ldup = NULL;
size_t alt_len = 0;
if ((ext = strrchr(path, '.')) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format\n");
@@ -141,11 +144,28 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
if ((mode & SFM_WRITE) && sf_format_check(&context->sfinfo) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error : file format is invalid (0x%08X).\n", context->sfinfo.format);
return SWITCH_STATUS_GENERR;
};
}
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));
return SWITCH_STATUS_GENERR;
alt_len = strlen(path) + 10;
switch_zmalloc(alt_path, alt_len);
switch_copy_string(alt_path, path, alt_len);
if ((last = strrchr(alt_path, *SWITCH_PATH_SEPARATOR))) {
next = ++last;
ldup = strdup(last);
switch_assert(ldup);
switch_snprintf(next, alt_len - (last - alt_path), "%d%s%s", handle->samplerate, SWITCH_PATH_SEPARATOR, ldup);
if ((context->handle = sf_open(alt_path, mode, &context->sfinfo))) {
path = alt_path;
}
}
if (!context->handle) {
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;
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
@@ -157,8 +177,15 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
handle->seekable = context->sfinfo.seekable;
handle->speed = 0;
handle->private_info = context;
return SWITCH_STATUS_SUCCESS;
end:
switch_safe_free(alt_path);
switch_safe_free(ldup);
return status;
}
static switch_status_t sndfile_file_close(switch_file_handle_t *handle)