let silence_stream://0 indicate perpetual silence

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9197 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-07-29 15:18:28 +00:00
parent 24cef98170
commit eec15605aa
1 changed files with 23 additions and 21 deletions

View File

@ -38,6 +38,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_tone_stream_shutdown);
struct silence_handle { struct silence_handle {
int32_t samples; int32_t samples;
int silence; int silence;
int forever;
}; };
static switch_status_t silence_stream_file_open(switch_file_handle_t *handle, const char *path) static switch_status_t silence_stream_file_open(switch_file_handle_t *handle, const char *path)
@ -45,31 +46,30 @@ static switch_status_t silence_stream_file_open(switch_file_handle_t *handle, co
struct silence_handle *sh; struct silence_handle *sh;
int ms; int ms;
char *p;
sh = switch_core_alloc(handle->memory_pool, sizeof(*sh)); sh = switch_core_alloc(handle->memory_pool, sizeof(*sh));
ms = atoi(path); ms = atoi(path);
if (ms > 0) { if (ms > 0) {
char *p;
sh->samples = (handle->samplerate / 1000) * ms; sh->samples = (handle->samplerate / 1000) * ms;
} else {
sh->samples = 0;
sh->forever = 1;
}
if ((p = strchr(path, ','))) { if ((p = strchr(path, ','))) {
p++; p++;
ms = atoi(p); ms = atoi(p);
if (ms > 0) { if (ms > 0) {
sh->silence = ms; sh->silence = ms;
}
} }
handle->private_info = sh;
return SWITCH_STATUS_SUCCESS;
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid format!\n"); handle->private_info = sh;
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t silence_stream_file_close(switch_file_handle_t *handle) static switch_status_t silence_stream_file_close(switch_file_handle_t *handle)
@ -81,15 +81,17 @@ static switch_status_t silence_stream_file_read(switch_file_handle_t *handle, vo
{ {
struct silence_handle *sh = handle->private_info; struct silence_handle *sh = handle->private_info;
if (sh->samples <= 0) { if (!sh->forever) {
return SWITCH_STATUS_FALSE; if (sh->samples <= 0) {
} return SWITCH_STATUS_FALSE;
}
if (*len > (size_t)sh->samples) { if (*len > (size_t)sh->samples) {
*len = sh->samples; *len = sh->samples;
} }
sh->samples -= *len; sh->samples -= *len;
}
if (sh->silence) { if (sh->silence) {
switch_generate_sln_silence((int16_t *) data, *len, sh->silence); switch_generate_sln_silence((int16_t *) data, *len, sh->silence);