<!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][15298] </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=15298">15298</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-10-30 17:56:08 -0500 (Fri, 30 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>snapshot</pre>

<h3>Added Paths</h3>
<ul>
<li>freeswitch/trunk/src/mod/applications/mod_snapshot/</li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_snapshotmod_snapshot2008vcproj">freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.2008.vcproj</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_snapshotmod_snapshotc">freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodapplicationsmod_snapshotmod_snapshot2008vcproj"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.2008.vcproj (0 => 15298)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.2008.vcproj                                (rev 0)
+++ freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.2008.vcproj        2009-10-30 22:56:08 UTC (rev 15298)
</span><span class="lines">@@ -0,0 +1,287 @@
</span><ins>+&lt;?xml version=&quot;1.0&quot; encoding=&quot;Windows-1252&quot;?&gt;
+&lt;VisualStudioProject
+        ProjectType=&quot;Visual C++&quot;
+        Version=&quot;9.00&quot;
+        Name=&quot;mod_snapshot&quot;
+        ProjectGUID=&quot;{11C9BC3D-45E9-46E3-BE84-B8CEE4685E39}&quot;
+        RootNamespace=&quot;mod_snapshot&quot;
+        Keyword=&quot;Win32Proj&quot;
+        TargetFrameworkVersion=&quot;131072&quot;
+        &gt;
+        &lt;Platforms&gt;
+                &lt;Platform
+                        Name=&quot;Win32&quot;
+                /&gt;
+                &lt;Platform
+                        Name=&quot;x64&quot;
+                /&gt;
+        &lt;/Platforms&gt;
+        &lt;ToolFiles&gt;
+        &lt;/ToolFiles&gt;
+        &lt;Configurations&gt;
+                &lt;Configuration
+                        Name=&quot;Debug|Win32&quot;
+                        ConfigurationType=&quot;2&quot;
+                        InheritedPropertySheets=&quot;..\..\..\..\w32\module_debug.vsprops&quot;
+                        CharacterSet=&quot;2&quot;
+                        &gt;
+                        &lt;Tool
+                                Name=&quot;VCPreBuildEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCustomBuildTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXMLDataGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCWebServiceProxyGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCMIDLTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCLCompilerTool&quot;
+                                UsePrecompiledHeader=&quot;0&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManagedResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPreLinkEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCLinkerTool&quot;
+                                RandomizedBaseAddress=&quot;1&quot;
+                                DataExecutionPrevention=&quot;0&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCALinkTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManifestTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXDCMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCBscMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCFxCopTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCAppVerifierTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPostBuildEventTool&quot;
+                        /&gt;
+                &lt;/Configuration&gt;
+                &lt;Configuration
+                        Name=&quot;Debug|x64&quot;
+                        OutputDirectory=&quot;$(PlatformName)\$(ConfigurationName)&quot;
+                        IntermediateDirectory=&quot;$(PlatformName)\$(ConfigurationName)&quot;
+                        ConfigurationType=&quot;2&quot;
+                        InheritedPropertySheets=&quot;..\..\..\..\w32\module_debug.vsprops&quot;
+                        CharacterSet=&quot;2&quot;
+                        &gt;
+                        &lt;Tool
+                                Name=&quot;VCPreBuildEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCustomBuildTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXMLDataGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCWebServiceProxyGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCMIDLTool&quot;
+                                TargetEnvironment=&quot;3&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCLCompilerTool&quot;
+                                UsePrecompiledHeader=&quot;0&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManagedResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPreLinkEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCLinkerTool&quot;
+                                OutputFile=&quot;$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll&quot;
+                                RandomizedBaseAddress=&quot;1&quot;
+                                DataExecutionPrevention=&quot;0&quot;
+                                TargetMachine=&quot;17&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCALinkTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManifestTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXDCMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCBscMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCFxCopTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCAppVerifierTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPostBuildEventTool&quot;
+                        /&gt;
+                &lt;/Configuration&gt;
+                &lt;Configuration
+                        Name=&quot;Release|Win32&quot;
+                        ConfigurationType=&quot;2&quot;
+                        InheritedPropertySheets=&quot;..\..\..\..\w32\module_release.vsprops&quot;
+                        CharacterSet=&quot;2&quot;
+                        &gt;
+                        &lt;Tool
+                                Name=&quot;VCPreBuildEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCustomBuildTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXMLDataGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCWebServiceProxyGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCMIDLTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCLCompilerTool&quot;
+                                UsePrecompiledHeader=&quot;0&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManagedResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPreLinkEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCLinkerTool&quot;
+                                RandomizedBaseAddress=&quot;1&quot;
+                                DataExecutionPrevention=&quot;0&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCALinkTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManifestTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXDCMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCBscMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCFxCopTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCAppVerifierTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPostBuildEventTool&quot;
+                        /&gt;
+                &lt;/Configuration&gt;
+                &lt;Configuration
+                        Name=&quot;Release|x64&quot;
+                        OutputDirectory=&quot;$(PlatformName)\$(ConfigurationName)&quot;
+                        IntermediateDirectory=&quot;$(PlatformName)\$(ConfigurationName)&quot;
+                        ConfigurationType=&quot;2&quot;
+                        InheritedPropertySheets=&quot;..\..\..\..\w32\module_release.vsprops&quot;
+                        CharacterSet=&quot;2&quot;
+                        &gt;
+                        &lt;Tool
+                                Name=&quot;VCPreBuildEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCustomBuildTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXMLDataGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCWebServiceProxyGeneratorTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCMIDLTool&quot;
+                                TargetEnvironment=&quot;3&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCCLCompilerTool&quot;
+                                UsePrecompiledHeader=&quot;0&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManagedResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCResourceCompilerTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPreLinkEventTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCLinkerTool&quot;
+                                OutputFile=&quot;$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll&quot;
+                                RandomizedBaseAddress=&quot;1&quot;
+                                DataExecutionPrevention=&quot;0&quot;
+                                TargetMachine=&quot;17&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCALinkTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCManifestTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCXDCMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCBscMakeTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCFxCopTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCAppVerifierTool&quot;
+                        /&gt;
+                        &lt;Tool
+                                Name=&quot;VCPostBuildEventTool&quot;
+                        /&gt;
+                &lt;/Configuration&gt;
+        &lt;/Configurations&gt;
+        &lt;References&gt;
+        &lt;/References&gt;
+        &lt;Files&gt;
+                &lt;File
+                        RelativePath=&quot;.\mod_snapshot.c&quot;
+                        &gt;
+                &lt;/File&gt;
+        &lt;/Files&gt;
+        &lt;Globals&gt;
+        &lt;/Globals&gt;
+&lt;/VisualStudioProject&gt;
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_snapshotmod_snapshotc"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c (0 => 15298)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c                                (rev 0)
+++ freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c        2009-10-30 22:56:08 UTC (rev 15298)
</span><span class="lines">@@ -0,0 +1,341 @@
</span><ins>+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2009, Anthony Minessale II &lt;anthm@freeswitch.org&gt;
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the &quot;License&quot;); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an &quot;AS IS&quot; basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II &lt;anthm@freeswitch.org&gt;
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II &lt;anthm@freeswitch.org&gt;
+ *
+ *
+ * mod_snapshot.c -- record a sliding window of audio and take snapshots to disk
+ *
+ */
+#include &lt;switch.h&gt;
+
+/* Prototypes */
+SWITCH_MODULE_RUNTIME_FUNCTION(mod_snapshot_runtime);
+SWITCH_MODULE_LOAD_FUNCTION(mod_snapshot_load);
+
+/* SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) 
+ * Defines a switch_loadable_module_function_table_t and a static const char[] modname
+ */
+SWITCH_MODULE_DEFINITION(mod_snapshot, mod_snapshot_load, NULL, NULL);
+
+struct cap_cb {
+        switch_buffer_t *buffer;
+        switch_mutex_t *mutex;
+        char *base;
+};
+
+static switch_bool_t capture_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+{
+        switch_core_session_t *session = switch_core_media_bug_get_session(bug);
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        struct cap_cb *cb = (struct cap_cb *) user_data;
+
+        switch (type) {
+        case SWITCH_ABC_TYPE_INIT:
+                break;
+        case SWITCH_ABC_TYPE_CLOSE:
+                {
+                        if (cb-&gt;buffer) {
+                                switch_buffer_destroy(&amp;cb-&gt;buffer);
+                        }
+                        switch_channel_set_private(channel, &quot;snapshot&quot;, NULL);
+                }
+
+                break;
+        case SWITCH_ABC_TYPE_READ:
+                
+                if (cb-&gt;buffer) {
+                        uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
+                        switch_frame_t frame = { 0 };
+
+                        frame.data = data;
+                        frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+                        
+                        if (switch_mutex_trylock(cb-&gt;mutex) == SWITCH_STATUS_SUCCESS) {
+                                while (switch_core_media_bug_read(bug, &amp;frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS &amp;&amp; !switch_test_flag((&amp;frame), SFF_CNG)) {
+                                        if (frame.datalen) switch_buffer_slide_write(cb-&gt;buffer, frame.data, frame.datalen);
+                                }
+                                switch_mutex_unlock(cb-&gt;mutex);
+                        }
+
+                }
+                break;
+        case SWITCH_ABC_TYPE_WRITE:
+        default:
+                break;
+        }
+
+        return SWITCH_TRUE;
+}
+
+static switch_status_t start_capture(switch_core_session_t *session, unsigned int seconds, switch_media_bug_flag_t flags, const char *base)
+{
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        switch_media_bug_t *bug;
+        switch_status_t status;
+        switch_codec_implementation_t read_impl = {0};
+        struct cap_cb *cb;
+        switch_size_t bytes;
+        switch_bind_flag_t bind_flags = 0;
+
+        if (switch_channel_get_private(channel, &quot;snapshot&quot;)) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Already Running.\n&quot;);
+                return SWITCH_STATUS_FALSE;
+        }
+
+        if (seconds &lt; 5) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Must be at least 5 seconds!\n&quot;);
+                return SWITCH_STATUS_FALSE;
+        }
+        
+    switch_core_session_get_read_impl(session, &amp;read_impl);
+
+        if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+                return SWITCH_STATUS_FALSE;
+        }
+
+        cb = switch_core_session_alloc(session, sizeof(*cb));
+        cb-&gt;base = switch_core_session_strdup(session, base);
+        
+        bytes = read_impl.samples_per_second * seconds * 2;
+
+        switch_buffer_create_dynamic(&amp;cb-&gt;buffer, bytes, bytes, bytes);
+        switch_mutex_init(&amp;cb-&gt;mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+
+        if ((status = switch_core_media_bug_add(session, capture_callback, cb, 0, flags, &amp;bug)) != SWITCH_STATUS_SUCCESS) {
+                return status;
+        }
+
+        bind_flags = SBF_DIAL_ALEG | SBF_EXEC_ALEG | SBF_EXEC_SAME;
+        switch_ivr_bind_dtmf_meta_session(session, 7, bind_flags, &quot;snapshot::snap&quot;);
+
+        switch_channel_set_private(channel, &quot;snapshot&quot;, bug);
+        
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static void do_snap(switch_core_session_t *session)
+{
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        switch_media_bug_t *bug = switch_channel_get_private(channel, &quot;snapshot&quot;);
+        char *file;
+        switch_file_handle_t fh = {0};
+        switch_codec_implementation_t read_impl = {0};
+        switch_size_t bytes_read;
+        int16_t pdata[4096] = {0};
+                
+        if (bug) {
+                switch_time_exp_t tm;
+                switch_size_t retsize;
+                char date[80] = &quot;&quot;;
+                struct cap_cb *cb = (struct cap_cb *) switch_core_media_bug_get_user_data(bug);
+
+                if (!cb) {
+                        return;
+                }
+
+                switch_time_exp_lt(&amp;tm, switch_time_make(switch_epoch_time_now(NULL), 0));
+                switch_strftime(date, &amp;retsize, sizeof(date), &quot;%Y_%m_%d_%H_%M_%S&quot;, &amp;tm);
+                        
+                file = switch_core_session_sprintf(session, &quot;%s%ssounds%s%s_%s.wav&quot;, SWITCH_GLOBAL_dirs.base_dir, 
+                                                                                   SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, cb-&gt;base, date);
+
+                switch_core_session_get_read_impl(session, &amp;read_impl);
+                fh.channels = 0;
+                fh.native_rate = read_impl.actual_samples_per_second;
+                        
+                if (switch_core_file_open(&amp;fh,
+                                                                  file,
+                                                                  0,
+                                                                  read_impl.actual_samples_per_second,
+                                                                  SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error opening %s\n&quot;, file);
+                        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+                        switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
+                        return;
+                }
+
+                switch_mutex_lock(cb-&gt;mutex);
+                while ((bytes_read = switch_buffer_read(cb-&gt;buffer, pdata, sizeof(pdata)))) {
+                        switch_size_t samples = bytes_read / 2;
+                                
+                        if (switch_core_file_write(&amp;fh, pdata, &amp;samples) != SWITCH_STATUS_SUCCESS) {
+                                break;
+                        }
+                }
+                switch_mutex_unlock(cb-&gt;mutex);
+                switch_core_file_close(&amp;fh);
+                switch_core_set_variable(&quot;file&quot;, file);
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Wrote %s\n&quot;, file);
+        }
+
+}
+
+#define SNAP_SYNTAX &quot;start &lt;sec&gt; &lt;read|write&gt;&quot;
+SWITCH_STANDARD_APP(snapshot_app_function)
+{
+        char *argv[4] = { 0 };
+        int argc = 0;
+        char *lbuf = NULL;
+        switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING;
+        if (!zstr(data) &amp;&amp; (lbuf = switch_core_session_strdup(session, data))) {
+                argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+        } 
+        
+        if (argc &lt; 1) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Usage: %s\n&quot;, SNAP_SYNTAX);
+        }
+
+        if (!strcasecmp(argv[0], &quot;start&quot;)) {
+                char *sec = argv[1];
+                char *fl = argv[2];
+                const char *base = argv[3];
+                int seconds = 5;
+
+                if (sec) {
+                        int tmp = atoi(sec);
+                        if (tmp &gt; 5) {
+                                seconds = tmp;
+                        }
+                }
+
+                if (fl) {
+                        flags = SMBF_READ_PING;
+                        if (switch_stristr(&quot;read&quot;, fl)) {
+                                flags |= SMBF_READ_STREAM;
+                        }
+                        if (switch_stristr(&quot;write&quot;, fl)) {
+                                flags |= SMBF_WRITE_STREAM;
+                        }
+                }
+
+                if (!base) {
+                        base = &quot;mod_snapshot&quot;;
+                }
+
+                start_capture(session, seconds, flags, base);
+                
+        }
+
+        if (!strcasecmp(argv[0], &quot;snap&quot;)) {
+                do_snap(session);
+                return;
+        }
+
+}
+
+
+#define SNAP_API_SYNTAX &quot;&lt;uuid&gt; &lt;warning&gt;&quot;
+SWITCH_STANDARD_API(snapshot_function)
+{
+        char *mycmd = NULL, *argv[5] = { 0 };
+        int argc = 0;
+        switch_status_t status = SWITCH_STATUS_FALSE;
+
+        if (!zstr(cmd) &amp;&amp; (mycmd = strdup(cmd))) {
+                argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+        }
+
+        if (zstr(cmd) || argc &lt; 1 || zstr(argv[0])) {
+                stream-&gt;write_function(stream, &quot;-USAGE: %s\n&quot;, SNAP_API_SYNTAX);
+        } else {
+                switch_core_session_t *lsession = NULL;
+
+                if ((lsession = switch_core_session_locate(argv[0]))) {
+                        if (!strcasecmp(argv[1], &quot;snap&quot;)) {
+                                do_snap(lsession);
+                        } else if (!strcasecmp(argv[1], &quot;start&quot;)) {
+                                char *sec = argv[1];
+                                char *fl = argv[2];
+                                const char *base = argv[3];
+                                int seconds = 5;
+                                switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING;
+                                
+                                if (sec) {
+                                        int tmp = atoi(sec);
+                                        if (tmp &gt; 5) {
+                                                seconds = tmp;
+                                        }
+                                }
+
+                                if (fl) {
+                                        flags = SMBF_READ_PING;
+                                        if (switch_stristr(&quot;read&quot;, fl)) {
+                                                flags |= SMBF_READ_STREAM;
+                                        }
+                                        if (switch_stristr(&quot;write&quot;, fl)) {
+                                                flags |= SMBF_WRITE_STREAM;
+                                        }
+                                }
+
+                                if (!base) {
+                                        base = &quot;mod_snapshot&quot;;
+                                }
+
+                                start_capture(lsession, seconds, flags, base);
+                        }
+
+                        switch_core_session_rwunlock(lsession);
+                }
+        }
+
+        if (status == SWITCH_STATUS_SUCCESS) {
+                stream-&gt;write_function(stream, &quot;+OK Success\n&quot;);
+        } else {
+                stream-&gt;write_function(stream, &quot;-ERR Operation Failed\n&quot;);
+        }
+
+        switch_safe_free(mycmd);
+        return SWITCH_STATUS_SUCCESS;
+}
+
+/* Macro expands to: switch_status_t mod_snapshot_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
+SWITCH_MODULE_LOAD_FUNCTION(mod_snapshot_load)
+{
+        switch_api_interface_t *api_interface;
+        switch_application_interface_t *app_interface;
+
+        /* connect my internal structure to the blank pointer passed to me */
+        *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Hello World!\n&quot;);
+        
+        SWITCH_ADD_API(api_interface, &quot;uuid_snapshot&quot;, &quot;Snapshot API&quot;, snapshot_function, SNAP_API_SYNTAX);
+        SWITCH_ADD_APP(app_interface, &quot;snapshot&quot;, &quot;&quot;, &quot;&quot;, snapshot_app_function, SNAP_SYNTAX, SAF_SUPPORT_NOMEDIA);
+
+        /* indicate that the module should continue to be loaded */
+        return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>