]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
let silence_stream://0 indicate perpetual silence
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 29 Jul 2008 15:18:28 +0000 (15:18 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 29 Jul 2008 15:18:28 +0000 (15:18 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9197 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/formats/mod_tone_stream/mod_tone_stream.c

index 1a8dcfd756959ac69c9d44c49417583c92242d80..ddc62d88abe433aa73433a1114fc5da6d4bedf37 100644 (file)
@@ -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);