simplify file interface for stream file interfaces, cleanup.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7042 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
445da648f2
commit
0932532e6c
|
@ -85,7 +85,6 @@ static int do_rand(void)
|
|||
return index;
|
||||
}
|
||||
|
||||
|
||||
static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
|
||||
{
|
||||
local_stream_source_t *source = obj;
|
||||
|
@ -151,7 +150,6 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (skip > 0) {
|
||||
|
@ -180,7 +178,6 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Playing %s rate: %d\n", fname, source->rate);
|
||||
|
||||
while (RUNNING) {
|
||||
|
@ -217,7 +214,6 @@ 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) {
|
||||
|
@ -262,8 +258,6 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
|
|||
goto end;
|
||||
}
|
||||
|
||||
|
||||
|
||||
handle->samples = 0;
|
||||
handle->samplerate = source->rate;
|
||||
handle->channels = source->channels;
|
||||
|
@ -318,11 +312,6 @@ static switch_status_t local_stream_file_close(switch_file_handle_t *handle)
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t local_stream_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status_t local_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
|
||||
{
|
||||
local_stream_context_t *context = handle->private_info;
|
||||
|
@ -344,21 +333,6 @@ static switch_status_t local_stream_file_read(switch_file_handle_t *handle, void
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t local_stream_file_write(switch_file_handle_t *handle, void *data, size_t *len)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status_t local_stream_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status_t local_stream_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
/* Registration */
|
||||
|
||||
static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
|
||||
|
@ -372,7 +346,6 @@ static void launch_threads(void)
|
|||
switch_thread_t *thread;
|
||||
switch_threadattr_t *thd_attr = NULL;
|
||||
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
return;
|
||||
|
@ -442,14 +415,11 @@ static void launch_threads(void)
|
|||
switch_threadattr_detach_set(thd_attr, 1);
|
||||
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
||||
switch_thread_create(&thread, thd_attr, read_stream_thread, source, source->pool);
|
||||
|
||||
}
|
||||
|
||||
switch_xml_free(xml);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load)
|
||||
{
|
||||
switch_file_interface_t *file_interface;
|
||||
|
@ -462,10 +432,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load)
|
|||
file_interface->file_open = local_stream_file_open;
|
||||
file_interface->file_close = local_stream_file_close;
|
||||
file_interface->file_read = local_stream_file_read;
|
||||
file_interface->file_write = local_stream_file_write;
|
||||
file_interface->file_seek = local_stream_file_seek;
|
||||
file_interface->file_set_string = local_stream_file_set_string;
|
||||
file_interface->file_get_string = local_stream_file_get_string;
|
||||
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
|
|
|
@ -30,14 +30,11 @@
|
|||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
/* for apr_pstrcat */
|
||||
#define DEFAULT_PREBUFFER_SIZE 1024 * 16
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_tone_stream_load);
|
||||
SWITCH_MODULE_DEFINITION(mod_tone_stream, mod_tone_stream_load, NULL, NULL);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_tone_stream_shutdown);
|
||||
|
||||
|
||||
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
|
||||
{
|
||||
switch_buffer_t *audio_buffer = ts->user_data;
|
||||
|
@ -113,44 +110,21 @@ static switch_status_t tone_stream_file_close(switch_file_handle_t *handle)
|
|||
switch_buffer_t *audio_buffer = handle->private_info;
|
||||
|
||||
switch_buffer_destroy(&audio_buffer);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t tone_stream_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status_t tone_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
|
||||
{
|
||||
switch_buffer_t *audio_buffer = handle->private_info;
|
||||
switch_size_t bytes;
|
||||
|
||||
if ((bytes = (uint32_t) switch_buffer_read_loop(audio_buffer, data, *len * 2)) <= 0) {
|
||||
if ((bytes = switch_buffer_read_loop(audio_buffer, data, *len * 2)) <= 0) {
|
||||
*len = 0;
|
||||
return SWITCH_STATUS_FALSE;
|
||||
} else {
|
||||
*len = bytes / 2;
|
||||
}
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t tone_stream_file_write(switch_file_handle_t *handle, void *data, size_t *len)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status_t tone_stream_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status_t tone_stream_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
*len = bytes / 2;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* Registration */
|
||||
|
@ -169,10 +143,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_tone_stream_load)
|
|||
file_interface->file_open = tone_stream_file_open;
|
||||
file_interface->file_close = tone_stream_file_close;
|
||||
file_interface->file_read = tone_stream_file_read;
|
||||
file_interface->file_write = tone_stream_file_write;
|
||||
file_interface->file_seek = tone_stream_file_seek;
|
||||
file_interface->file_set_string = tone_stream_file_set_string;
|
||||
file_interface->file_get_string = tone_stream_file_get_string;
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
|
|
@ -178,6 +178,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||
|
||||
switch_assert(fh != NULL);
|
||||
switch_assert(fh->file_interface != NULL);
|
||||
|
||||
if (!fh->file_interface->file_write) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
|
||||
if (!fh->resampler) {
|
||||
|
@ -225,6 +229,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh,
|
|||
switch_assert(fh != NULL);
|
||||
switch_assert(fh->file_interface != NULL);
|
||||
|
||||
if (!fh->file_interface->file_seek) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
switch_set_flag(fh, SWITCH_FILE_SEEK);
|
||||
status = fh->file_interface->file_seek(fh, cur_pos, samples, whence);
|
||||
if (samples) {
|
||||
|
@ -238,6 +246,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(switch_file_handle_t
|
|||
switch_assert(fh != NULL);
|
||||
switch_assert(fh->file_interface != NULL);
|
||||
|
||||
if (!fh->file_interface->file_set_string) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
return fh->file_interface->file_set_string(fh, col, string);
|
||||
}
|
||||
|
||||
|
@ -246,6 +258,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(switch_file_handle_t
|
|||
switch_assert(fh != NULL);
|
||||
switch_assert(fh->file_interface != NULL);
|
||||
|
||||
if (!fh->file_interface->file_get_string) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
return fh->file_interface->file_get_string(fh, col, string);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue