<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14966] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14966">14966</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-09-24 13:13:46 -0500 (Thu, 24 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>add chime-list to local_stream</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkconfautoload_configslocal_streamconfxml">freeswitch/trunk/conf/autoload_configs/local_stream.conf.xml</a></li>
<li><a href="#freeswitchtrunksrcmodformatsmod_local_streammod_local_streamc">freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkconfautoload_configslocal_streamconfxml"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/conf/autoload_configs/local_stream.conf.xml (14965 => 14966)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/conf/autoload_configs/local_stream.conf.xml        2009-09-24 16:43:57 UTC (rev 14965)
+++ freeswitch/trunk/conf/autoload_configs/local_stream.conf.xml        2009-09-24 18:13:46 UTC (rev 14966)
</span><span class="lines">@@ -6,6 +6,12 @@
</span><span class="cx">     &lt;param name=&quot;channels&quot; value=&quot;1&quot;/&gt;
</span><span class="cx">     &lt;param name=&quot;interval&quot; value=&quot;20&quot;/&gt;
</span><span class="cx">     &lt;param name=&quot;timer-name&quot; value=&quot;soft&quot;/&gt;
</span><ins>+    &lt;!-- list of short files to break in with every so often --&gt;
+    &lt;!--&lt;param name=&quot;chime-list&quot; value=&quot;file1.wav,file2.wav&quot;/&gt;--&gt;
+    &lt;!-- frequency of break-in (seconds)--&gt;
+    &lt;!--&lt;param name=&quot;chime-freq&quot; value=&quot;30&quot;/&gt;--&gt;
+    &lt;!-- limit to how many seconds the file will play --&gt;
+    &lt;!--&lt;param name=&quot;chime-max&quot; value=&quot;500&quot;/&gt;--&gt;
</ins><span class="cx">   &lt;/directory&gt;
</span><span class="cx"> 
</span><span class="cx">   &lt;directory name=&quot;moh/8000&quot; path=&quot;$${base_dir}/sounds/music/8000&quot;&gt;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodformatsmod_local_streammod_local_streamc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c (14965 => 14966)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c        2009-09-24 16:43:57 UTC (rev 14965)
+++ freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c        2009-09-24 18:13:46 UTC (rev 14966)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx"> 
</span><span class="cx"> typedef struct local_stream_context local_stream_context_t;
</span><span class="cx"> 
</span><ins>+#define MAX_CHIME 100
</ins><span class="cx"> struct local_stream_source {
</span><span class="cx">         char *name;
</span><span class="cx">         char *location;
</span><span class="lines">@@ -81,6 +82,14 @@
</span><span class="cx">         switch_thread_rwlock_t *rwlock;
</span><span class="cx">         int ready;
</span><span class="cx">         int stopped;
</span><ins>+        int chime_freq;
+        int chime_total;
+        int chime_max;
+        int chime_cur;
+        char *chime_list[MAX_CHIME];
+        int32_t chime_counter;
+        int32_t chime_max_counter;
+        switch_file_handle_t chime_fh;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> typedef struct local_stream_source local_stream_source_t;
</span><span class="lines">@@ -202,18 +211,67 @@
</span><span class="cx"> 
</span><span class="cx">                         while (RUNNING) {
</span><span class="cx">                                 int is_open;
</span><ins>+                                switch_file_handle_t *use_fh = &amp;fh;
+
</ins><span class="cx">                                 switch_core_timer_next(&amp;timer);
</span><span class="cx">                                 olen = source-&gt;samples;
</span><del>-                                is_open = switch_test_flag((&amp;fh), SWITCH_FILE_OPEN);
</del><span class="cx"> 
</span><del>-                                if (is_open) {
-                                        if (switch_core_file_read(&amp;fh, abuf, &amp;olen) != SWITCH_STATUS_SUCCESS || !olen) {
-                                                switch_core_file_close(&amp;fh);
</del><ins>+                                if (source-&gt;chime_total) {
+
+                                        if (source-&gt;chime_counter &gt; 0) {
+                                                source-&gt;chime_counter -= source-&gt;samples;
</ins><span class="cx">                                         }
</span><ins>+                                        
+                                        if (!switch_test_flag((&amp;source-&gt;chime_fh), SWITCH_FILE_OPEN) &amp;&amp; source-&gt;chime_counter &lt;= 0) {
+                                                char *val;
+                                                
+                                                val = source-&gt;chime_list[source-&gt;chime_cur++];
</ins><span class="cx"> 
</span><del>-                                        switch_buffer_write(audio_buffer, abuf, olen * 2);
</del><ins>+                                                if (source-&gt;chime_cur &gt;= source-&gt;chime_total) {
+                                                        source-&gt;chime_cur = 0;
+                                                }
+
+                                                if (switch_core_file_open(&amp;source-&gt;chime_fh,
+                                                                                                  (char *) val,
+                                                                                                  source-&gt;channels, 
+                                                                                                  source-&gt;rate, 
+                                                                                                  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Can't open %s\n&quot;, val);
+                                                }
+                                        }
+
+                                        if (switch_test_flag((&amp;source-&gt;chime_fh), SWITCH_FILE_OPEN)) {
+                                                use_fh = &amp;source-&gt;chime_fh;
+                                        }
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><ins>+                        retry:
+
+                                is_open = switch_test_flag(use_fh, SWITCH_FILE_OPEN);
+
+                                if (is_open) {
+                                        if (switch_core_file_read(use_fh, abuf, &amp;olen) != SWITCH_STATUS_SUCCESS || !olen) {
+                                                switch_core_file_close(use_fh);
+                                                if (use_fh == &amp;source-&gt;chime_fh) {
+                                                        source-&gt;chime_counter = source-&gt;rate * source-&gt;chime_freq;
+                                                }
+                                                is_open = 0;
+                                        } else {
+                                                if (use_fh == &amp;source-&gt;chime_fh &amp;&amp; source-&gt;chime_max) {
+                                                        source-&gt;chime_max_counter += source-&gt;samples;
+                                                        if (source-&gt;chime_max_counter &gt;= source-&gt;chime_max) {
+                                                                source-&gt;chime_max_counter = 0;
+                                                                switch_core_file_close(use_fh);
+                                                                source-&gt;chime_counter = source-&gt;rate * source-&gt;chime_freq;
+                                                                use_fh = &amp;fh;
+                                                                goto retry;
+                                                        }
+                                                }
+
+                                                switch_buffer_write(audio_buffer, abuf, olen * 2);
+                                        }
+                                }
+
</ins><span class="cx">                                 used = switch_buffer_inuse(audio_buffer);
</span><span class="cx"> 
</span><span class="cx">                                 if (!used &amp;&amp; !is_open) {
</span><span class="lines">@@ -260,6 +318,10 @@
</span><span class="cx">                 switch_core_file_close(&amp;fh);
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        if (switch_test_flag((&amp;source-&gt;chime_fh), SWITCH_FILE_OPEN)) {
+                switch_core_file_close(&amp;source-&gt;chime_fh);
+        }
+
</ins><span class="cx">         source-&gt;ready = 0;
</span><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">         switch_core_hash_delete(globals.source_hash, source-&gt;name);
</span><span class="lines">@@ -462,6 +524,7 @@
</span><span class="cx">                 source-&gt;timer_name = &quot;soft&quot;;
</span><span class="cx">                 source-&gt;prebuf = DEFAULT_PREBUFFER_SIZE;
</span><span class="cx">                 source-&gt;stopped = 0;
</span><ins>+                source-&gt;chime_freq = 30;
</ins><span class="cx"> 
</span><span class="cx">                 for (param = switch_xml_child(directory, &quot;param&quot;); param; param = param-&gt;next) {
</span><span class="cx">                         char *var = (char *) switch_xml_attr_soft(param, &quot;name&quot;);
</span><span class="lines">@@ -484,6 +547,19 @@
</span><span class="cx">                                 if (tmp == 1 || tmp == 2) {
</span><span class="cx">                                         source-&gt;channels = (uint8_t) tmp;
</span><span class="cx">                                 }
</span><ins>+                        } else if (!strcasecmp(var, &quot;chime-freq&quot;)) {
+                                int tmp = atoi(val);
+                                if (tmp &gt; 1) {
+                                        source-&gt;chime_freq = tmp;
+                                }
+                        } else if (!strcasecmp(var, &quot;chime-max&quot;)) {
+                                int tmp = atoi(val);
+                                if (tmp &gt; 1) {
+                                        source-&gt;chime_max = tmp;
+                                }
+                        } else if (!strcasecmp(var, &quot;chime-list&quot;)) {
+                                char *list_dup = switch_core_strdup(source-&gt;pool, val);
+                                source-&gt;chime_total = switch_separate_string(list_dup, ',', source-&gt;chime_list, (sizeof(source-&gt;chime_list) / sizeof(source-&gt;chime_list[0])));
</ins><span class="cx">                         } else if (!strcasecmp(var, &quot;interval&quot;)) {
</span><span class="cx">                                 int tmp = atoi(val);
</span><span class="cx">                                 if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) {
</span><span class="lines">@@ -497,6 +573,14 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+                if (source-&gt;chime_max) {
+                        source-&gt;chime_max *= source-&gt;rate;
+                }
+
+                if (source-&gt;chime_total) {
+                        source-&gt;chime_counter = source-&gt;rate * source-&gt;chime_freq;
+                }
+
</ins><span class="cx">                 source-&gt;samples = switch_samples_per_packet(source-&gt;rate, source-&gt;interval);
</span><span class="cx"> 
</span><span class="cx">                 switch_mutex_init(&amp;source-&gt;mutex, SWITCH_MUTEX_NESTED, source-&gt;pool);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>