<!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"> <param name="channels" value="1"/>
</span><span class="cx"> <param name="interval" value="20"/>
</span><span class="cx"> <param name="timer-name" value="soft"/>
</span><ins>+ <!-- list of short files to break in with every so often -->
+ <!--<param name="chime-list" value="file1.wav,file2.wav"/>-->
+ <!-- frequency of break-in (seconds)-->
+ <!--<param name="chime-freq" value="30"/>-->
+ <!-- limit to how many seconds the file will play -->
+ <!--<param name="chime-max" value="500"/>-->
</ins><span class="cx"> </directory>
</span><span class="cx">
</span><span class="cx"> <directory name="moh/8000" path="$${base_dir}/sounds/music/8000">
</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 = &fh;
+
</ins><span class="cx">                                 switch_core_timer_next(&timer);
</span><span class="cx">                                 olen = source->samples;
</span><del>-                                is_open = switch_test_flag((&fh), SWITCH_FILE_OPEN);
</del><span class="cx">
</span><del>-                                if (is_open) {
-                                        if (switch_core_file_read(&fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
-                                                switch_core_file_close(&fh);
</del><ins>+                                if (source->chime_total) {
+
+                                        if (source->chime_counter > 0) {
+                                                source->chime_counter -= source->samples;
</ins><span class="cx">                                         }
</span><ins>+                                        
+                                        if (!switch_test_flag((&source->chime_fh), SWITCH_FILE_OPEN) && source->chime_counter <= 0) {
+                                                char *val;
+                                                
+                                                val = source->chime_list[source->chime_cur++];
</ins><span class="cx">
</span><del>-                                        switch_buffer_write(audio_buffer, abuf, olen * 2);
</del><ins>+                                                if (source->chime_cur >= source->chime_total) {
+                                                        source->chime_cur = 0;
+                                                }
+
+                                                if (switch_core_file_open(&source->chime_fh,
+                                                                                                 (char *) val,
+                                                                                                 source->channels,
+                                                                                                 source->rate,
+                                                                                                 SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", val);
+                                                }
+                                        }
+
+                                        if (switch_test_flag((&source->chime_fh), SWITCH_FILE_OPEN)) {
+                                                use_fh = &source->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, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
+                                                switch_core_file_close(use_fh);
+                                                if (use_fh == &source->chime_fh) {
+                                                        source->chime_counter = source->rate * source->chime_freq;
+                                                }
+                                                is_open = 0;
+                                        } else {
+                                                if (use_fh == &source->chime_fh && source->chime_max) {
+                                                        source->chime_max_counter += source->samples;
+                                                        if (source->chime_max_counter >= source->chime_max) {
+                                                                source->chime_max_counter = 0;
+                                                                switch_core_file_close(use_fh);
+                                                                source->chime_counter = source->rate * source->chime_freq;
+                                                                use_fh = &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 && !is_open) {
</span><span class="lines">@@ -260,6 +318,10 @@
</span><span class="cx">                 switch_core_file_close(&fh);
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        if (switch_test_flag((&source->chime_fh), SWITCH_FILE_OPEN)) {
+                switch_core_file_close(&source->chime_fh);
+        }
+
</ins><span class="cx">         source->ready = 0;
</span><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">         switch_core_hash_delete(globals.source_hash, source->name);
</span><span class="lines">@@ -462,6 +524,7 @@
</span><span class="cx">                 source->timer_name = "soft";
</span><span class="cx">                 source->prebuf = DEFAULT_PREBUFFER_SIZE;
</span><span class="cx">                 source->stopped = 0;
</span><ins>+                source->chime_freq = 30;
</ins><span class="cx">
</span><span class="cx">                 for (param = switch_xml_child(directory, "param"); param; param = param->next) {
</span><span class="cx">                         char *var = (char *) switch_xml_attr_soft(param, "name");
</span><span class="lines">@@ -484,6 +547,19 @@
</span><span class="cx">                                 if (tmp == 1 || tmp == 2) {
</span><span class="cx">                                         source->channels = (uint8_t) tmp;
</span><span class="cx">                                 }
</span><ins>+                        } else if (!strcasecmp(var, "chime-freq")) {
+                                int tmp = atoi(val);
+                                if (tmp > 1) {
+                                        source->chime_freq = tmp;
+                                }
+                        } else if (!strcasecmp(var, "chime-max")) {
+                                int tmp = atoi(val);
+                                if (tmp > 1) {
+                                        source->chime_max = tmp;
+                                }
+                        } else if (!strcasecmp(var, "chime-list")) {
+                                char *list_dup = switch_core_strdup(source->pool, val);
+                                source->chime_total = switch_separate_string(list_dup, ',', source->chime_list, (sizeof(source->chime_list) / sizeof(source->chime_list[0])));
</ins><span class="cx">                         } else if (!strcasecmp(var, "interval")) {
</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->chime_max) {
+                        source->chime_max *= source->rate;
+                }
+
+                if (source->chime_total) {
+                        source->chime_counter = source->rate * source->chime_freq;
+                }
+
</ins><span class="cx">                 source->samples = switch_samples_per_packet(source->rate, source->interval);
</span><span class="cx">
</span><span class="cx">                 switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>