From eec15605aac532c7d3a5e1a2bd53839c390d9ec7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 29 Jul 2008 15:18:28 +0000 Subject: [PATCH] let silence_stream://0 indicate perpetual silence git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9197 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../formats/mod_tone_stream/mod_tone_stream.c | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/mod/formats/mod_tone_stream/mod_tone_stream.c b/src/mod/formats/mod_tone_stream/mod_tone_stream.c index 1a8dcfd756..ddc62d88ab 100644 --- a/src/mod/formats/mod_tone_stream/mod_tone_stream.c +++ b/src/mod/formats/mod_tone_stream/mod_tone_stream.c @@ -38,6 +38,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_tone_stream_shutdown); struct silence_handle { int32_t samples; int silence; + int forever; }; 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; int ms; + char *p; sh = switch_core_alloc(handle->memory_pool, sizeof(*sh)); ms = atoi(path); if (ms > 0) { - char *p; - sh->samples = (handle->samplerate / 1000) * ms; + } else { + sh->samples = 0; + sh->forever = 1; + } - if ((p = strchr(path, ','))) { - p++; - ms = atoi(p); - if (ms > 0) { - sh->silence = ms; - } + if ((p = strchr(path, ','))) { + p++; + ms = atoi(p); + if (ms > 0) { + sh->silence = ms; } - - handle->private_info = sh; - return SWITCH_STATUS_SUCCESS; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid format!\n"); - - return SWITCH_STATUS_GENERR; + handle->private_info = sh; + + return SWITCH_STATUS_SUCCESS; } 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; - if (sh->samples <= 0) { - return SWITCH_STATUS_FALSE; - } + if (!sh->forever) { + if (sh->samples <= 0) { + return SWITCH_STATUS_FALSE; + } - if (*len > (size_t)sh->samples) { - *len = sh->samples; - } + if (*len > (size_t)sh->samples) { + *len = sh->samples; + } - sh->samples -= *len; + sh->samples -= *len; + } if (sh->silence) { switch_generate_sln_silence((int16_t *) data, *len, sh->silence);