<!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][15989] </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=15989">15989</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-12-17 14:46:49 -0600 (Thu, 17 Dec 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>add uuid_audio cli cmd</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_coreh">freeswitch/trunk/src/include/switch_core.h</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_ivrh">freeswitch/trunk/src/include/switch_ivr.h</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_commandsmod_commandsc">freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_core_media_bugc">freeswitch/trunk/src/switch_core_media_bug.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_ivr_asyncc">freeswitch/trunk/src/switch_ivr_async.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeswitch_coreh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_core.h (15988 => 15989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_core.h        2009-12-17 19:14:47 UTC (rev 15988)
+++ freeswitch/trunk/src/include/switch_core.h        2009-12-17 20:46:49 UTC (rev 15989)
</span><span class="lines">@@ -202,6 +202,8 @@
</span><span class="cx"> \return true value if the object has the flags defined
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(uint32_t) switch_core_media_bug_test_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag);
</span><ins>+SWITCH_DECLARE(uint32_t) switch_core_media_bug_set_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag);
+SWITCH_DECLARE(uint32_t) switch_core_media_bug_clear_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag);
</ins><span class="cx">
</span><span class="cx"> /*!
</span><span class="cx"> \brief Set a return replace frame
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_ivrh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_ivr.h (15988 => 15989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_ivr.h        2009-12-17 19:14:47 UTC (rev 15988)
+++ freeswitch/trunk/src/include/switch_ivr.h        2009-12-17 20:46:49 UTC (rev 15989)
</span><span class="lines">@@ -244,6 +244,10 @@
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_ivr_stop_record_session(switch_core_session_t *session, const char *file);
</span><span class="cx">
</span><ins>+
+SWITCH_DECLARE(switch_status_t) switch_ivr_session_audio(switch_core_session_t *session, const char *cmd, const char *direction, int level);
+SWITCH_DECLARE(switch_status_t) switch_ivr_stop_session_audio(switch_core_session_t *session);
+
</ins><span class="cx"> /*!
</span><span class="cx"> \brief Start looking for DTMF inband
</span><span class="cx"> \param session the session to start looking
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_commandsmod_commandsc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (15988 => 15989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c        2009-12-17 19:14:47 UTC (rev 15988)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c        2009-12-17 20:46:49 UTC (rev 15989)
</span><span class="lines">@@ -2405,6 +2405,69 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
+#define AUDIO_SYNTAX "<uuid> [start [read|write] [mute|level <level>]|stop]"
+SWITCH_STANDARD_API(session_audio_function)
+{
+        switch_core_session_t *u_session = NULL;
+        char *mycmd = NULL;
+        int fail = 0;
+        int argc = 0;
+        char *argv[5] = { 0 };
+        int level;
+
+        if (zstr(cmd)) {
+                fail++; goto done;
+        }
+
+        mycmd = strdup(cmd);
+        argc = switch_split(mycmd, ' ', argv);
+        
+        if (argc < 2) {
+                fail++; goto done;
+        }
+        
+        if (!(u_session = switch_core_session_locate(argv[0]))) {
+                stream->write_function(stream, "-ERR No Such Channel!\n");
+                goto done;
+        }
+        
+        if (!strcasecmp(argv[1], "stop")) {
+                switch_ivr_stop_session_audio(u_session);
+                goto done;
+        }
+
+        if (strcasecmp(argv[1], "start") || argc < 5 || (strcasecmp(argv[2], "read") && strcasecmp(argv[2], "write"))) {
+                fail++; goto done;
+        }
+
+        level = atoi(argv[4]);
+        
+        if (!strcasecmp(argv[3], "mute")) {
+                switch_ivr_session_audio(u_session, "mute", argv[2], level);
+        } else if (!strcasecmp(argv[3], "level")) {
+                switch_ivr_session_audio(u_session, "level", argv[2], level);
+        } else {
+                fail++;
+        }
+
+ done:
+
+        if (u_session) {
+                switch_core_session_rwunlock(u_session);
+        }
+
+        switch_safe_free(mycmd);
+
+        if (fail) {
+                stream->write_function(stream, "-USAGE: %s\n", AUDIO_SYNTAX);
+        } else {
+                stream->write_function(stream, "+OK\n");
+        }
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
</ins><span class="cx"> #define BREAK_SYNTAX "<uuid> [all]"
</span><span class="cx"> SWITCH_STANDARD_API(break_function)
</span><span class="cx"> {
</span><span class="lines">@@ -3895,6 +3958,7 @@
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, "url_encode", "url encode a string", url_encode_function, "<string>");
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "<user>@<domain> [var|param|attr] <name>");
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, "user_exists", "find a user", user_exists_function, "<key> <user> <domain>");
</span><ins>+        SWITCH_ADD_API(commands_api_interface, "uuid_audio", "uuid_audio", session_audio_function, AUDIO_SYNTAX);
</ins><span class="cx">         SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, "");
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, "uuid_broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX);
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX);
</span><span class="lines">@@ -3973,6 +4037,11 @@
</span><span class="cx">         switch_console_set_complete("add show nat_map");
</span><span class="cx">         switch_console_set_complete("add show say");
</span><span class="cx">         switch_console_set_complete("add show timer");
</span><ins>+        switch_console_set_complete("add uuid_audio ::console::list_uuid start read mute");
+        switch_console_set_complete("add uuid_audio ::console::list_uuid start read level");
+        switch_console_set_complete("add uuid_audio ::console::list_uuid start write mute");
+        switch_console_set_complete("add uuid_audio ::console::list_uuid start write level");
+        switch_console_set_complete("add uuid_audio ::console::list_uuid stop");
</ins><span class="cx">         switch_console_set_complete("add uuid_bridge ::console::list_uuid ::console::list_uuid");
</span><span class="cx">         switch_console_set_complete("add uuid_broadcast ::console::list_uuid");
</span><span class="cx">         switch_console_set_complete("add uuid_chat ::console::list_uuid");
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_media_bugc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_media_bug.c (15988 => 15989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_media_bug.c        2009-12-17 19:14:47 UTC (rev 15988)
+++ freeswitch/trunk/src/switch_core_media_bug.c        2009-12-17 20:46:49 UTC (rev 15989)
</span><span class="lines">@@ -61,6 +61,16 @@
</span><span class="cx">         return switch_test_flag(bug, flag);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+SWITCH_DECLARE(uint32_t) switch_core_media_bug_set_flag(switch_media_bug_t *bug, uint32_t flag)
+{
+        return switch_set_flag(bug, flag);
+}
+
+SWITCH_DECLARE(uint32_t) switch_core_media_bug_clear_flag(switch_media_bug_t *bug, uint32_t flag)
+{
+        return switch_clear_flag(bug, flag);
+}
+
</ins><span class="cx"> SWITCH_DECLARE(switch_core_session_t *) switch_core_media_bug_get_session(switch_media_bug_t *bug)
</span><span class="cx"> {
</span><span class="cx">         return bug->session;
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_ivr_asyncc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_ivr_async.c (15988 => 15989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_ivr_async.c        2009-12-17 19:14:47 UTC (rev 15988)
+++ freeswitch/trunk/src/switch_ivr_async.c        2009-12-17 20:46:49 UTC (rev 15989)
</span><span class="lines">@@ -1355,8 +1355,148 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> typedef struct {
</span><span class="cx">         switch_core_session_t *session;
</span><ins>+        int mute;
+        int read_level;
+        int write_level;
+        int read_mute;
+        int write_mute;
+} switch_session_audio_t;
+
+static switch_bool_t session_audio_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+{
+        switch_session_audio_t *pvt = (switch_session_audio_t *) user_data;
+        switch_frame_t *frame = NULL;
+        int level = 0, mute = 0;
+
+        
+        if (type == SWITCH_ABC_TYPE_READ_REPLACE || type == SWITCH_ABC_TYPE_WRITE_REPLACE) {
+                if (!(pvt->read_level || pvt->write_level || pvt->read_mute || pvt->write_mute)) {
+                        switch_channel_set_private(switch_core_session_get_channel(pvt->session), "__audio", NULL);
+                        return SWITCH_FALSE;
+                }
+        }
+
+        if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
+                level = pvt->read_level;
+                mute = pvt->read_mute;
+                frame = switch_core_media_bug_get_read_replace_frame(bug);
+        } else if (type == SWITCH_ABC_TYPE_WRITE_REPLACE) {
+                level = pvt->write_level;
+                mute = pvt->write_mute;
+                frame = switch_core_media_bug_get_write_replace_frame(bug);
+        }
+
+        if (frame) {
+                if (mute) {
+                        switch_generate_sln_silence(frame->data, frame->datalen / 2, 400);
+                } else if (level) {
+                        switch_change_sln_volume(frame->data, frame->datalen / 2, level);
+                }
+                
+                if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
+                        switch_core_media_bug_set_read_replace_frame(bug, frame);
+                } else if (type == SWITCH_ABC_TYPE_WRITE_REPLACE) {
+                        switch_core_media_bug_set_write_replace_frame(bug, frame);
+                }
+        }
+
+        return SWITCH_TRUE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_stop_session_audio(switch_core_session_t *session)
+{
+        switch_media_bug_t *bug;
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+
+        if ((bug = switch_channel_get_private(channel, "__audio"))) {
+                switch_channel_set_private(channel, "__audio", NULL);
+                switch_core_media_bug_remove(session, &bug);
+                return SWITCH_STATUS_SUCCESS;
+        }
+        return SWITCH_STATUS_FALSE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_session_audio(switch_core_session_t *session, const char *cmd, const char *direction, int level)
+{
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        switch_media_bug_t *bug;
+        switch_status_t status;
+        switch_session_audio_t *pvt;
+        switch_codec_implementation_t read_impl = {0};
+        int existing = 0, c_read = 0, c_write = 0, flags = 0;
+        
+        if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+                return SWITCH_STATUS_FALSE;
+        }
+
+ switch_core_session_get_read_impl(session, &read_impl);
+
+
+        if ((bug = switch_channel_get_private(channel, "__audio"))) {
+                pvt = switch_core_media_bug_get_user_data(bug);
+                existing = 1;
+        } else {
+                if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
+                        return SWITCH_STATUS_MEMERR;
+                }
+
+                pvt->session = session;
+        }
+        
+
+        if (!strcasecmp(direction, "write")) {
+                flags = SMBF_WRITE_REPLACE;
+                c_write = 1;
+        } else if (!strcasecmp(direction, "read")){
+                flags = SMBF_READ_REPLACE;
+                c_read = 1;
+        } else if (!strcasecmp(direction, "both")){
+                flags = SMBF_READ_REPLACE | SMBF_WRITE_REPLACE;
+                c_read = c_write = 1;
+        }
+
+
+        if (!strcasecmp(cmd, "mute")) {
+                if (c_read) {
+                        pvt->read_mute = level;
+                }
+                if (c_write) {
+                        pvt->write_mute = level;
+                }
+        } else if (!strcasecmp(cmd, "level")) {
+                if (level < 5 && level > -5) {
+                        if (c_read) {
+                                pvt->read_level = level;
+                        }
+                        if (c_write) {
+                                pvt->write_level = level;
+                        }
+                }
+        }
+        
+        if (existing) {
+                switch_core_media_bug_clear_flag(bug, SMBF_READ_REPLACE);
+                switch_core_media_bug_clear_flag(bug, SMBF_WRITE_REPLACE);
+                switch_core_media_bug_set_flag(bug, flags);
+                
+        } else {
+                if ((status = switch_core_media_bug_add(session, session_audio_callback, pvt, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
+                        return status;
+                }
+
+                switch_channel_set_private(channel, "__audio", bug);
+        }
+
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+
+typedef struct {
+        switch_core_session_t *session;
</ins><span class="cx">         teletone_dtmf_detect_state_t dtmf_detect;
</span><span class="cx"> } switch_inband_dtmf_t;
</span><span class="cx">
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>