<!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][16810] </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=16810">16810</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2010-02-25 04:29:19 -0600 (Thu, 25 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>skypiax: timing and load tweaking, let's see if compile on windoz</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxmod_skypiaxc">freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxskypiax_protocolc">freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxmod_skypiaxc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (16809 => 16810)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c        2010-02-25 10:07:52 UTC (rev 16809)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c        2010-02-25 10:29:19 UTC (rev 16810)
</span><span class="lines">@@ -496,6 +496,8 @@
</span><span class="cx">                 switch_core_timer_destroy(&amp;tech_pvt-&gt;timer_write);
</span><span class="cx"> #endif // TIMER_WRITE
</span><span class="cx"> 
</span><ins>+                switch_buffer_destroy(&amp;tech_pvt-&gt;read_buffer);
+                switch_buffer_destroy(&amp;tech_pvt-&gt;write_buffer);
</ins><span class="cx"> 
</span><span class="cx">                 *tech_pvt-&gt;session_uuid_str = '\0';
</span><span class="cx">                 tech_pvt-&gt;interface_state = SKYPIAX_STATE_IDLE;
</span><span class="lines">@@ -691,201 +693,17 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#ifdef OLDTCP
-#if 0
</del><span class="cx"> static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
</span><span class="cx"> {
</span><span class="cx">         switch_channel_t *channel = NULL;
</span><span class="cx">         private_t *tech_pvt = NULL;
</span><span class="cx">         switch_byte_t *data;
</span><del>-        char digit_str[256];
-        short *frame_16_khz;
-        short frame_8_khz[160];        
-        int i;
-        int a;
-
-
-        channel = switch_core_session_get_channel(session);
-        switch_assert(channel != NULL);
-
-        tech_pvt = switch_core_session_get_private(session);
-        switch_assert(tech_pvt != NULL);
-
-        if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
-                ERRORA(&quot;channel not ready \n&quot;, SKYPIAX_P_LOG);
-                //TODO: kill the bastard
-                return SWITCH_STATUS_FALSE;
-        }
-
-tech_pvt-&gt;begin_to_read=1;
-        tech_pvt-&gt;read_frame.flags = SFF_NONE;
-        *frame = NULL;
-
-        //switch_core_timer_next(&amp;tech_pvt-&gt;timer_read);
-
-        if (!skypiax_audio_read(tech_pvt)) {
-
-                ERRORA(&quot;skypiax_audio_read ERROR\n&quot;, SKYPIAX_P_LOG);
-
-        } else {
-                switch_set_flag(tech_pvt, TFLAG_VOICE);
-        }
-
-        while (switch_test_flag(tech_pvt, TFLAG_IO)) {
-                if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
-                        switch_clear_flag(tech_pvt, TFLAG_BREAK);
-                        DEBUGA_SKYPE(&quot;CHANNEL READ FRAME goto CNG\n&quot;, SKYPIAX_P_LOG);
-                        goto cng;
-                }
-
-                if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
-                        DEBUGA_SKYPE(&quot;CHANNEL READ FRAME not IO\n&quot;, SKYPIAX_P_LOG);
-                        return SWITCH_STATUS_FALSE;
-                }
-
-                if (switch_test_flag(tech_pvt, TFLAG_IO) &amp;&amp; switch_test_flag(tech_pvt, TFLAG_VOICE)) {
-                        switch_clear_flag(tech_pvt, TFLAG_VOICE);
-                        if (!tech_pvt-&gt;read_frame.datalen) {
-                                DEBUGA_SKYPE(&quot;CHANNEL READ CONTINUE\n&quot;, SKYPIAX_P_LOG);
-                                continue;
-                        }
-                        *frame = &amp;tech_pvt-&gt;read_frame;
-
-
-                        if (switch_true(switch_channel_get_variable(channel, &quot;skype_get_inband_dtmf&quot;))) {
-
-                                frame_16_khz = tech_pvt-&gt;read_frame.data;
-
-                                a = 0;
-                                for (i = 0; i &lt; tech_pvt-&gt;read_frame.datalen / sizeof(short); i++) {
-                                        frame_8_khz[a] = frame_16_khz[i];
-                                        i++;
-                                        a++;
-                                }
-                                //DEBUGA_SKYPE(&quot;a=%d i=%d\n&quot;, SKYPIAX_P_LOG, a, i);
-
-                                memset(digit_str, 0, sizeof(digit_str));
-                                //dtmf_rx(&amp;tech_pvt-&gt;dtmf_state, (int16_t *) tech_pvt-&gt;read_frame.data,tech_pvt-&gt;read_frame.datalen/sizeof(short) );
-                                dtmf_rx(&amp;tech_pvt-&gt;dtmf_state, (int16_t *) frame_8_khz, 160);
-                                dtmf_rx_get(&amp;tech_pvt-&gt;dtmf_state, digit_str, sizeof(digit_str));
-
-
-                                if (digit_str[0]) {
-                                        switch_time_t new_dtmf_timestamp = switch_time_now();
-                                        if ((new_dtmf_timestamp - tech_pvt-&gt;old_dtmf_timestamp) &gt; 350000) {     //FIXME: make it configurable
-                                                char *p = digit_str;
-                                                switch_channel_t *channel = switch_core_session_get_channel(session);
-
-                                                while (p &amp;&amp; *p) {
-                                                        switch_dtmf_t dtmf;
-                                                        dtmf.digit = *p;
-                                                        dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
-                                                        switch_channel_queue_dtmf(channel, &amp;dtmf);
-                                                        p++;
-                                                }
-                                                NOTICA(&quot;DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n&quot;, SKYPIAX_P_LOG, digit_str, (unsigned int) new_dtmf_timestamp,
-                                                                (unsigned int) (new_dtmf_timestamp - tech_pvt-&gt;old_dtmf_timestamp));
-                                                tech_pvt-&gt;old_dtmf_timestamp = new_dtmf_timestamp;
-                                        }
-                                }
-                        }
-
-
-
-
-
-#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
-                        if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
-                                switch_swap_linear((*frame)-&gt;data, (int) (*frame)-&gt;datalen / 2);
-                        }
-#endif
-                        return SWITCH_STATUS_SUCCESS;
-                }
-
-                DEBUGA_SKYPE(&quot;CHANNEL READ no TFLAG_IO\n&quot;, SKYPIAX_P_LOG);
-                return SWITCH_STATUS_FALSE;
-
-        }
-
-        DEBUGA_SKYPE(&quot;CHANNEL READ FALSE\n&quot;, SKYPIAX_P_LOG);
-        return SWITCH_STATUS_FALSE;
-
-  cng:
-        data = (switch_byte_t *) tech_pvt-&gt;read_frame.data;
-        data[0] = 65;
-        data[1] = 0;
-        tech_pvt-&gt;read_frame.datalen = 2;
-        tech_pvt-&gt;read_frame.flags = SFF_CNG;
-        *frame = &amp;tech_pvt-&gt;read_frame;
-        return SWITCH_STATUS_SUCCESS;
-
-}
-
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
-{
-        switch_channel_t *channel = NULL;
-        private_t *tech_pvt = NULL;
-        unsigned int sent;
-//cicopet
-        channel = switch_core_session_get_channel(session);
-        switch_assert(channel != NULL);
-
-        tech_pvt = switch_core_session_get_private(session);
-        switch_assert(tech_pvt != NULL);
-
-        if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
-                ERRORA(&quot;channel not ready \n&quot;, SKYPIAX_P_LOG);
-                //TODO: kill the bastard
-                return SWITCH_STATUS_FALSE;
-        }
-#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
-        if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
-                switch_swap_linear(frame-&gt;data, (int) frame-&gt;datalen / 2);
-        }
-#endif
-
-tech_pvt-&gt;begin_to_write=1;
-        sent = frame-&gt;datalen;
-#ifdef WIN32
-        //switch_file_write(tech_pvt-&gt;audiopipe_cli[1], frame-&gt;data, &amp;sent);
-#else /* WIN32 */
-        //sent = write(tech_pvt-&gt;audiopipe_cli[1], frame-&gt;data, sent);
-#endif /* WIN32 */
-        //if (tech_pvt-&gt;flag_audio_cli == 1) {
-                //switch_sleep(1000);                //1 millisec
-        //}
-        //if (tech_pvt-&gt;flag_audio_cli == 0) {
-#ifdef TIMER_WRITE
-                //switch_core_timer_next(&amp;tech_pvt-&gt;timer_write);
-#endif // TIMER_WRITE
-
-memset(tech_pvt-&gt;audiobuf_cli, 255, sizeof(tech_pvt-&gt;audiobuf_cli));
-                                                        switch_mutex_lock(tech_pvt-&gt;mutex_audio_cli);
-                memcpy(tech_pvt-&gt;audiobuf_cli, frame-&gt;data, frame-&gt;datalen);
-                tech_pvt-&gt;flag_audio_cli = 1;
-                                                        switch_mutex_unlock(tech_pvt-&gt;mutex_audio_cli);
-        //}
-        //NOTICA(&quot;write \n&quot;, SKYPIAX_P_LOG);
-
-        if (sent != frame-&gt;datalen &amp;&amp; sent != -1) {
-                DEBUGA_SKYPE(&quot;CLI PIPE write %d\n&quot;, SKYPIAX_P_LOG, sent);
-        }
-
-        return SWITCH_STATUS_SUCCESS;
-}
-#endif //0
-#else
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
-{
-        switch_channel_t *channel = NULL;
-        private_t *tech_pvt = NULL;
-        switch_byte_t *data;
</del><span class="cx">         char digit_str[256];
</span><span class="cx">         short *frame_16_khz;
</span><span class="cx">         short frame_8_khz[160];        
</span><span class="cx">         unsigned int i;
</span><span class="cx">         unsigned int a;
</span><del>-size_t bytes_read;
</del><ins>+size_t bytes_read=0;
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         channel = switch_core_session_get_channel(session);
</span><span class="lines">@@ -903,14 +721,16 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (!tech_pvt-&gt;read_buffer) {
</span><del>-                int32_t len = 640 * 2;
</del><ins>+                int32_t max_len = 640 * 10;
</ins><span class="cx"> 
</span><del>-                switch_buffer_create(skypiax_module_pool, &amp;tech_pvt-&gt;read_buffer, len);
</del><ins>+                switch_buffer_create(skypiax_module_pool, &amp;tech_pvt-&gt;read_buffer, max_len);
</ins><span class="cx">                 switch_assert(tech_pvt-&gt;read_buffer);
</span><ins>+                switch_buffer_zero(tech_pvt-&gt;read_buffer);
+                tech_pvt-&gt;begin_to_read=1;
+                //switch_sleep(40000);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-        tech_pvt-&gt;begin_to_read=1;
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -921,14 +741,15 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_lock(tech_pvt-&gt;mutex_audio_srv);
</span><del>-        if ((bytes_read = switch_buffer_read(tech_pvt-&gt;read_buffer, tech_pvt-&gt;read_frame.data, SAMPLES_PER_FRAME * sizeof(short)))) {
</del><ins>+        if(switch_buffer_inuse(tech_pvt-&gt;read_buffer)){
+                bytes_read = switch_buffer_read(tech_pvt-&gt;read_buffer, tech_pvt-&gt;read_frame.data, 640);
</ins><span class="cx">                 tech_pvt-&gt;read_frame.datalen = bytes_read;
</span><span class="cx">         }
</span><span class="cx">         switch_mutex_unlock(tech_pvt-&gt;mutex_audio_srv);
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (!bytes_read) {
</span><del>-                DEBUGA_SKYPE(&quot;skypiax_audio_read Silence\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                //NOTICA(&quot;skypiax_audio_read Silence\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">                 memset(tech_pvt-&gt;read_frame.data, 255, SAMPLES_PER_FRAME * sizeof(short));
</span><span class="cx">                 tech_pvt-&gt;read_frame.datalen = SAMPLES_PER_FRAME * sizeof(short);
</span><span class="cx"> 
</span><span class="lines">@@ -1029,7 +850,6 @@
</span><span class="cx"> {
</span><span class="cx">         switch_channel_t *channel = NULL;
</span><span class="cx">         private_t *tech_pvt = NULL;
</span><del>-        unsigned int sent;
</del><span class="cx"> 
</span><span class="cx">         channel = switch_core_session_get_channel(session);
</span><span class="cx">         switch_assert(channel != NULL);
</span><span class="lines">@@ -1049,29 +869,25 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">         if (!tech_pvt-&gt;write_buffer) {
</span><del>-                int32_t len = 320 * 4;
</del><ins>+                int32_t max_len = 640 * 3;
</ins><span class="cx"> 
</span><del>-                switch_buffer_create(skypiax_module_pool, &amp;tech_pvt-&gt;write_buffer, len);
</del><ins>+                switch_buffer_create(skypiax_module_pool, &amp;tech_pvt-&gt;write_buffer, max_len);
</ins><span class="cx">                 switch_assert(tech_pvt-&gt;write_buffer);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-
-
-        sent = frame-&gt;datalen;
-
</del><span class="cx">         switch_mutex_lock(tech_pvt-&gt;mutex_audio_cli);
</span><ins>+        if(switch_buffer_freespace(tech_pvt-&gt;write_buffer) &lt; frame-&gt;datalen){
+                //WARNINGA(&quot;NO SPACE WRITE: %d\n&quot;, SKYPIAX_P_LOG, frame-&gt;datalen);
+                switch_buffer_toss(tech_pvt-&gt;write_buffer, frame-&gt;datalen);
+        }
</ins><span class="cx">         switch_buffer_write(tech_pvt-&gt;write_buffer, frame-&gt;data, frame-&gt;datalen);
</span><span class="cx">         switch_mutex_unlock(tech_pvt-&gt;mutex_audio_cli);
</span><span class="cx"> 
</span><span class="cx">         tech_pvt-&gt;begin_to_write=1;
</span><del>-        if (sent != frame-&gt;datalen &amp;&amp; sent != -1) {
-                DEBUGA_SKYPE(&quot;CLI PIPE write %d\n&quot;, SKYPIAX_P_LOG, sent);
-        }
</del><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#endif //OLDTCP
</del><span class="cx"> static switch_status_t channel_answer_channel(switch_core_session_t *session)
</span><span class="cx"> {
</span><span class="cx">         private_t *tech_pvt;
</span><span class="lines">@@ -2105,7 +1921,8 @@
</span><span class="cx">         switch_core_timer_sync(&amp;tech_pvt-&gt;timer_read);
</span><span class="cx"> 
</span><span class="cx"> #ifdef TIMER_WRITE
</span><del>-        if (switch_core_timer_init(&amp;tech_pvt-&gt;timer_write, &quot;soft&quot;, 10, 320, skypiax_module_pool) !=
</del><ins>+        //if (switch_core_timer_init(&amp;tech_pvt-&gt;timer_write, &quot;soft&quot;, 10, 320, skypiax_module_pool) !=
+        if (switch_core_timer_init(&amp;tech_pvt-&gt;timer_write, &quot;soft&quot;, 20, 320, skypiax_module_pool) !=
</ins><span class="cx">                 SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                 ERRORA(&quot;setup timer failed\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                 return SWITCH_STATUS_FALSE;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxskypiax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (16809 => 16810)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c        2010-02-25 10:07:52 UTC (rev 16809)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c        2010-02-25 10:29:19 UTC (rev 16810)
</span><span class="lines">@@ -104,7 +104,7 @@
</span><span class="cx">         sockbufsize = SAMPLES_PER_FRAME * 8;
</span><span class="cx"> #endif //WIN32
</span><span class="cx">         size = sizeof(int);
</span><del>-        setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &amp;sockbufsize, size);
</del><ins>+        //setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &amp;sockbufsize, size);
</ins><span class="cx"> 
</span><span class="cx">         sockbufsize = 0;
</span><span class="cx">         size = sizeof(int);
</span><span class="lines">@@ -121,7 +121,7 @@
</span><span class="cx">         sockbufsize = SAMPLES_PER_FRAME * 8;
</span><span class="cx"> #endif //WIN32
</span><span class="cx">         size = sizeof(int);
</span><del>-        setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &amp;sockbufsize, size);
</del><ins>+        //setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &amp;sockbufsize, size);
</ins><span class="cx"> 
</span><span class="cx">         sockbufsize = 0;
</span><span class="cx">         size = sizeof(int);
</span><span class="lines">@@ -746,568 +746,11 @@
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#ifdef OLDTCP
-#if 0
</del><span class="cx"> void *skypiax_do_tcp_srv_thread_func(void *obj)
</span><span class="cx"> {
</span><span class="cx">         private_t *tech_pvt = obj;
</span><span class="cx">         int s;
</span><span class="cx">         unsigned int len;
</span><del>-        unsigned int i;
-        unsigned int a;
-#if defined(WIN32) &amp;&amp; !defined(__CYGWIN__)
-        int sin_size;
-#else /* WIN32 */
-        unsigned int sin_size;
-#endif /* WIN32 */
-        unsigned int fd;
-        short srv_in[SAMPLES_PER_FRAME];
-        short srv_out[SAMPLES_PER_FRAME / 2];
-        //struct sockaddr_in my_addr;
-        struct sockaddr_in remote_addr;
-        //int exit = 0;
-        unsigned int kill_cli_size;
-        short kill_cli_buff[SAMPLES_PER_FRAME];
-        short totalbuf[SAMPLES_PER_FRAME];
-        int sockbufsize = 0;
-        unsigned int size = sizeof(int);
-
-        s = skypiax_socket_create_and_bind(tech_pvt, &amp;tech_pvt-&gt;tcp_srv_port);
-        if (s &lt; 0) {
-                ERRORA(&quot;skypiax_socket_create_and_bind error!\n&quot;, SKYPIAX_P_LOG);
-                return NULL;
-        }
-        DEBUGA_SKYPE(&quot;started tcp_srv_thread thread.\n&quot;, SKYPIAX_P_LOG);
-
-        listen(s, 6);
-
-        sin_size = sizeof(remote_addr);
-
-  /****************************/
-        while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
-                   &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
-                           || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-                           || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
-
-                unsigned int fdselectgio;
-                int rtgio;
-                fd_set fsgio;
-                struct timeval togio;
-
-                if (!(running &amp;&amp; tech_pvt-&gt;running))
-                        break;
-                FD_ZERO(&amp;fsgio);
-                togio.tv_usec = 20000;        //20msec
-                togio.tv_sec = 0;
-                fdselectgio = s;
-                FD_SET(fdselectgio, &amp;fsgio);
-
-                rtgio = select(fdselectgio + 1, &amp;fsgio, NULL, NULL, &amp;togio);
-
-                if (rtgio) {
-
-  /****************************/
-
-                        while (s &gt; 0 &amp;&amp; (fd = accept(s, (struct sockaddr *) &amp;remote_addr, &amp;sin_size)) &gt; 0) {
-                                DEBUGA_SKYPE(&quot;ACCEPTED here I send you %d\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;tcp_srv_port);
-
-                                sockbufsize = 0;
-                                size = sizeof(int);
-                                getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &amp;sockbufsize, &amp;size);
-                                DEBUGA_SKYPE(&quot;3 SO_RCVBUF is %d, size is %d\n&quot;, SKYPIAX_P_LOG, sockbufsize, size);
-                                sockbufsize = 0;
-                                size = sizeof(int);
-                                getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &amp;sockbufsize, &amp;size);
-                                DEBUGA_SKYPE(&quot;3 SO_SNDBUF is %d, size is %d\n&quot;, SKYPIAX_P_LOG, sockbufsize, size);
-
-
-                                if (!(running &amp;&amp; tech_pvt-&gt;running))
-                                        break;
-                                while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
-                                           &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
-                                                   || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-                                                   || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
-
-                                        unsigned int fdselect;
-                                        int rt;
-                                        fd_set fs;
-                                        struct timeval to;
-
-                                        if (!(running &amp;&amp; tech_pvt-&gt;running))
-                                                break;
-                                        //exit = 1;
-
-                                        fdselect = fd;
-                                        FD_ZERO(&amp;fs);
-                                        FD_SET(fdselect, &amp;fs);
-                                        //to.tv_usec = 2000000;     //2000 msec
-                                        to.tv_usec = 60000;        //60 msec
-                                        to.tv_sec = 0;
-
-if(tech_pvt-&gt;begin_to_read==0){
-skypiax_sleep(1000);
-continue;
-}
-                                         if (tech_pvt-&gt;timer_read.timer_interface &amp;&amp; tech_pvt-&gt;timer_read.timer_interface-&gt;timer_next) {
-        switch_core_timer_next(&amp;tech_pvt-&gt;timer_read);
-                                         }
-                                        //rt = select(fdselect + 1, &amp;fs, NULL, NULL, &amp;to);
-rt=1;
-                                        if (rt &gt; 0) {
-
-                                                if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                                                        len = recv(fd, (char *) srv_in, 640, 0);        //seems that Skype only sends 320 bytes at time
-                                                } else {
-                                                        len = 0;
-                                                }
-
-                                                if (len == 320) {
-                                                        unsigned int howmany;
-
-                                                                DEBUGA_SKYPE(&quot;320!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n&quot;, SKYPIAX_P_LOG);
-                                                        if (samplerate_skypiax == 8000) {
-                                                                /* we're downsampling from 16khz to 8khz, srv_out will contain each other sample from srv_in */
-                                                                a = 0;
-                                                                for (i = 0; i &lt; len / sizeof(short); i++) {
-                                                                        srv_out[a] = srv_in[i];
-                                                                        i++;
-                                                                        a++;
-                                                                }
-                                                        } else if (samplerate_skypiax == 16000) {
-                                                                /* we're NOT downsampling, srv_out will contain ALL samples from srv_in */
-                                                                for (i = 0; i &lt; len / sizeof(short); i++) {
-                                                                        srv_out[i] = srv_in[i];
-                                                                }
-                                                        } else {
-                                                                ERRORA(&quot;SAMPLERATE_SKYPIAX can only be 8000 or 16000\n&quot;, SKYPIAX_P_LOG);
-                                                        }
-                                                        /* if not yet done, let's store the half incoming frame */
-                                                        if (!tech_pvt-&gt;audiobuf_is_loaded) {
-                                                                for (i = 0; i &lt; SAMPLES_PER_FRAME / 2; i++) {
-                                                                        tech_pvt-&gt;audiobuf[i] = srv_out[i];
-                                                                }
-                                                                tech_pvt-&gt;audiobuf_is_loaded = 1;
-                                                        } else {
-                                                                /* we got a stored half frame, build a complete frame in totalbuf using the stored half frame and the current half frame */
-                                                                for (i = 0; i &lt; SAMPLES_PER_FRAME / 2; i++) {
-                                                                        totalbuf[i] = tech_pvt-&gt;audiobuf[i];
-                                                                }
-                                                                for (a = 0; a &lt; SAMPLES_PER_FRAME / 2; a++) {
-                                                                        totalbuf[i] = srv_out[a];
-                                                                        i++;
-                                                                }
-                                                                /* send the complete frame through the pipe to our code waiting for incoming audio */
-                                                                //howmany = skypiax_pipe_write(tech_pvt-&gt;audiopipe_srv[1], totalbuf, SAMPLES_PER_FRAME * sizeof(short));
-                                                                //FIXME while(tech_pvt-&gt;flag_audio_srv == 1){
-                                                                //FIXME switch_sleep(100); //1 millisec
-                                                                //NOTICA(&quot;read now is 1\n&quot;, SKYPIAX_P_LOG);
-                                                                //FIXME }
-                                                                //WARNINGA(&quot;read is now 0\n&quot;, SKYPIAX_P_LOG);
-
-
-                                                                howmany = SAMPLES_PER_FRAME * sizeof(short);
-                                                                if (tech_pvt-&gt;flag_audio_srv == 1) {
-                                                                        switch_sleep(1000);        //1 millisec
-                                                                }
-                                                                //if (tech_pvt-&gt;flag_audio_srv == 0) {
-                        switch_mutex_lock(tech_pvt-&gt;mutex_audio_srv);
-                                                                        memcpy(tech_pvt-&gt;audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short));
-                                                                        tech_pvt-&gt;flag_audio_srv = 1;
-                        switch_mutex_unlock(tech_pvt-&gt;mutex_audio_srv);
-                                                                //}
-                                                                //NOTICA(&quot;read \n&quot;, SKYPIAX_P_LOG);
-                                                                if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
-                                                                        ERRORA(&quot;howmany is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG,
-                                                                                   howmany, (int) (SAMPLES_PER_FRAME * sizeof(short)));
-                                                                }
-                                                                /* done with the stored half frame */
-                                                                tech_pvt-&gt;audiobuf_is_loaded = 0;
-                                                        }
-
-                                                } else if (len == 640) {
-#if 0
-                                                        int waitin;
-                                                        int max_waitin=20;
-
-                                                        waitin=0;
-                                                        while (tech_pvt-&gt;flag_audio_srv == 1) {
-                                                                switch_sleep(1000);        //1 millisec
-                                                                waitin++;
-                                                                if(waitin == max_waitin){
-                                                                ERRORA(&quot;waitin is %d\n&quot;, SKYPIAX_P_LOG, waitin);
-                                                                        break;
-                                                                }
-                                                        }
-
-                                                        if(waitin &gt; 10){
-                                                                ERRORA(&quot;waitin is %d\n&quot;, SKYPIAX_P_LOG, waitin);
-                                                        }
-#endif//0
-                                                        switch_mutex_lock(tech_pvt-&gt;mutex_audio_srv);
-                                                        memcpy(tech_pvt-&gt;audiobuf_srv, srv_in, SAMPLES_PER_FRAME * sizeof(short));
-                                                        tech_pvt-&gt;flag_audio_srv = 1;
-                                                        switch_mutex_unlock(tech_pvt-&gt;mutex_audio_srv);
-                                                } else if (len == 0) {
-                                                        skypiax_sleep(1000);
-                                                } else {
-                                                        DEBUGA_SKYPE(&quot;len=%d, expected 640\n&quot;, SKYPIAX_P_LOG, len);
-                                                }
-
-                                        } else {
-                                                if (rt)
-                                                        ERRORA(&quot;SRV rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
-                                                skypiax_sleep(10000);
-                                        }
-
-                                }
-
-                                /* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
-                                kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-                                len = skypiax_pipe_write(tech_pvt-&gt;audiopipe_srv[1], kill_cli_buff, kill_cli_size);
-                                kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-                                len = skypiax_pipe_write(tech_pvt-&gt;audiopipe_cli[1], kill_cli_buff, kill_cli_size);
-                                //tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
-                                kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-                                len = skypiax_pipe_write(tech_pvt-&gt;audiopipe_srv[1], kill_cli_buff, kill_cli_size);
-                                kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-                                len = skypiax_pipe_write(tech_pvt-&gt;audiopipe_cli[1], kill_cli_buff, kill_cli_size);
-
-                                tech_pvt-&gt;flag_audio_cli = 1;        //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
-                                skypiax_sleep(2000);
-                                tech_pvt-&gt;flag_audio_srv = 1;        //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
-                                skypiax_sleep(2000);
-                                tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
-                                tech_pvt-&gt;flag_audio_cli = 1;        //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
-                                skypiax_sleep(2000);
-                                tech_pvt-&gt;flag_audio_srv = 1;        //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
-                                skypiax_sleep(2000);
-                                DEBUGA_SKYPE(&quot;Skype incoming audio GONE\n&quot;, SKYPIAX_P_LOG);
-                                skypiax_close_socket(fd);
-                                break;
-                        }
-                break;
-                }
-        }
-
-        DEBUGA_SKYPE(&quot;incoming audio server (I am it) EXITING\n&quot;, SKYPIAX_P_LOG);
-        skypiax_close_socket(s);
-        s = -1;
-        tech_pvt-&gt;tcp_srv_thread = NULL;
-        return NULL;
-}
-
-void *skypiax_do_tcp_cli_thread_func(void *obj)
-{
-        private_t *tech_pvt = obj;
-        int s;
-        //struct sockaddr_in my_addr;
-        struct sockaddr_in remote_addr;
-        unsigned int got;
-        unsigned int len;
-        unsigned int i;
-        unsigned int a;
-        unsigned int fd;
-        short cli_out[SAMPLES_PER_FRAME * 2];
-        short cli_in[SAMPLES_PER_FRAME];
-#ifdef WIN32
-        int sin_size;
-#else
-        unsigned int sin_size;
-#endif /* WIN32 */
-        int sockbufsize = 0;
-        unsigned int size = sizeof(int);
-
-        s = skypiax_socket_create_and_bind(tech_pvt, &amp;tech_pvt-&gt;tcp_cli_port);
-        if (s &lt; 0) {
-                ERRORA(&quot;skypiax_socket_create_and_bind error!\n&quot;, SKYPIAX_P_LOG);
-                return NULL;
-        }
-
-
-
-        DEBUGA_SKYPE(&quot;started tcp_cli_thread thread.\n&quot;, SKYPIAX_P_LOG);
-
-        listen(s, 6);
-
-        sin_size = sizeof(remote_addr);
-
-        /****************************/
-        while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
-                        &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
-                                || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-                                || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
-
-                unsigned int fdselectgio;
-                int rtgio;
-                fd_set fsgio;
-                struct timeval togio;
-
-                if (!(running &amp;&amp; tech_pvt-&gt;running))
-                        break;
-                FD_ZERO(&amp;fsgio);
-                togio.tv_usec = 20000;        //20msec
-                togio.tv_sec = 0;
-                fdselectgio = s;
-                FD_SET(fdselectgio, &amp;fsgio);
-
-                rtgio = select(fdselectgio + 1, &amp;fsgio, NULL, NULL, &amp;togio);
-
-                if (rtgio) {
-
-                        /****************************/
-
-                        while (s &gt; 0 &amp;&amp; (fd = accept(s, (struct sockaddr *) &amp;remote_addr, &amp;sin_size)) &gt; 0) {
-                                DEBUGA_SKYPE(&quot;ACCEPTED here you send me %d\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;tcp_cli_port);
-
-                                sockbufsize = 0;
-                                size = sizeof(int);
-                                getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &amp;sockbufsize, &amp;size);
-                                DEBUGA_SKYPE(&quot;4 SO_RCVBUF is %d, size is %d\n&quot;, SKYPIAX_P_LOG, sockbufsize, size);
-                                sockbufsize = 0;
-                                size = sizeof(int);
-                                getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &amp;sockbufsize, &amp;size);
-                                DEBUGA_SKYPE(&quot;4 SO_SNDBUF is %d, size is %d\n&quot;, SKYPIAX_P_LOG, sockbufsize, size);
-
-
-
-#ifndef WIN32
-                                fcntl(tech_pvt-&gt;audiopipe_cli[0], F_SETFL, O_NONBLOCK);
-                                fcntl(tech_pvt-&gt;audiopipe_cli[1], F_SETFL, O_NONBLOCK);
-#endif //WIN32
-
-                                if (!(running &amp;&amp; tech_pvt-&gt;running))
-                                        break;
-                                while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
-                                                &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
-                                                        || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-                                                        || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
-                                        unsigned int fdselect;
-                                        int rt;
-                                        fd_set fs;
-                                        struct timeval to;
-#if 0
-                                        int waitin;
-                                        int big_waitin=40;
-                                        int lil_waitin=20;
-                                        int big_waited;
-#endif//0
-
-                                        if (!(running &amp;&amp; tech_pvt-&gt;running))
-                                                break;
-                                        FD_ZERO(&amp;fs);
-                                        to.tv_usec = 120000;        //120msec
-                                        to.tv_sec = 0;
-#if defined(WIN32) &amp;&amp; !defined(__CYGWIN__)
-                                        /* on win32 we cannot select from the apr &quot;pipe&quot;, so we select on socket writability */
-                                        fdselect = fd;
-                                        FD_SET(fdselect, &amp;fs);
-
-                                        //rt = select(fdselect + 1, NULL, &amp;fs, NULL, &amp;to);
-#else
-                                        /* on *unix and cygwin we select from the real pipe */
-                                        //XXX fdselect = tech_pvt-&gt;audiopipe_cli[0];
-                                        //XXX FD_SET(fdselect, &amp;fs);
-
-                                        //rt = select(fdselect + 1, &amp;fs, NULL, NULL, &amp;to);
-#endif
-                                        fdselect = fd;
-                                        FD_SET(fdselect, &amp;fs);
-
-#if 0
-                                        //rt = select(fdselect + 1, NULL, &amp;fs, NULL, &amp;to);
-                                        waitin=0;
-                                        big_waited=0;
-                                        while (tech_pvt-&gt;flag_audio_cli == 0) {
-#ifdef WIN32
-                                                skypiax_sleep(1000);        //0.1 millisec
-#else
-                                                skypiax_sleep(1000);        //1 millisec
-#endif //WIN32
-                                                waitin++;
-                                                if(big_waited == 1 &amp;&amp; waitin==lil_waitin &amp;&amp; tech_pvt-&gt;flag_audio_cli == 0){
-                                                        memset(cli_out, 255, SAMPLES_PER_FRAME * sizeof(short));
-                                                        send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
-                                                        WARNINGA(&quot;write buffer filled at %d\n&quot;, SKYPIAX_P_LOG, waitin);
-                                                        waitin=0;
-                                                        continue;
-                                                }
-                                                if(big_waited == 0 &amp;&amp; waitin==big_waitin &amp;&amp; tech_pvt-&gt;flag_audio_cli == 0){
-                                                        memset(cli_out, 255, SAMPLES_PER_FRAME * sizeof(short));
-                                                        send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
-                                                        send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
-                                                        NOTICA(&quot;write buffer filled at %d\n&quot;, SKYPIAX_P_LOG, waitin);
-                                                        waitin=0;
-                                                        big_waited=1;
-                                                        continue;
-                                                }
-                                        }
-                                        if(waitin &gt; 21){
-                                                NOTICA(&quot;waitin is now %d\n&quot;, SKYPIAX_P_LOG, waitin);
-                                        }
-#endif //0
-
-
-#if 0
-if(tech_pvt-&gt;begin_to_write==0){
-skypiax_sleep(1000);
-continue;
-}
-#endif//0
-                                         if (tech_pvt-&gt;timer_write.timer_interface &amp;&amp; tech_pvt-&gt;timer_write.timer_interface-&gt;timer_next) {
-                switch_core_timer_next(&amp;tech_pvt-&gt;timer_write);
-}
-                                        rt = 1;
-
-                                        if (rt &gt; 0) {
-
-                                                /* until we drained the pipe to empty */
-                                                /* read from the pipe the audio frame we are supposed to send out */
-                                                //got = skypiax_pipe_read(tech_pvt-&gt;audiopipe_cli[0], cli_in, SAMPLES_PER_FRAME * sizeof(short));
-
-
-                                                got = SAMPLES_PER_FRAME * sizeof(short);
-                                                        switch_mutex_lock(tech_pvt-&gt;mutex_audio_cli);
-#ifndef WIN32
-if(tech_pvt-&gt;flag_audio_cli == 0){
-memset(tech_pvt-&gt;audiobuf_cli, 255, sizeof(tech_pvt-&gt;audiobuf_cli));
-} 
-#endif
-                                                memcpy(cli_in, tech_pvt-&gt;audiobuf_cli, SAMPLES_PER_FRAME * sizeof(short));
-                                                tech_pvt-&gt;flag_audio_cli = 0;
-                                                        switch_mutex_unlock(tech_pvt-&gt;mutex_audio_cli);
-
-
-
-
-                                                if (got == -1)
-                                                        break;
-
-                                                if (got != SAMPLES_PER_FRAME * sizeof(short)) {
-                                                        WARNINGA(&quot;got is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
-                                                }
-
-                                                if (got == SAMPLES_PER_FRAME * sizeof(short)) {
-                                                        if (samplerate_skypiax == 8000) {
-
-                                                                /* we're upsampling from 8khz to 16khz, cli_out will contain two times each sample from cli_in */
-                                                                a = 0;
-                                                                for (i = 0; i &lt; got / sizeof(short); i++) {
-                                                                        cli_out[a] = cli_in[i];
-                                                                        a++;
-                                                                        cli_out[a] = cli_in[i];
-                                                                        a++;
-                                                                }
-                                                                got = got * 2;
-                                                        } else if (samplerate_skypiax == 16000) {
-                                                                /* we're NOT upsampling, cli_out will contain just ALL samples from cli_in */
-                                                                for (i = 0; i &lt; got / sizeof(short); i++) {
-                                                                        cli_out[i] = cli_in[i];
-                                                                }
-                                                        } else {
-                                                                ERRORA(&quot;SAMPLERATE_SKYPIAX can only be 8000 or 16000\n&quot;, SKYPIAX_P_LOG);
-                                                        }
-
-                                                        /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
-                                                        if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                                                                len = send(fd, (char *) cli_out, got, 0);
-                                                                //skypiax_sleep(5000);  //5 msec
-
-                                                                if (len == -1) {
-                                                                        DEBUGA_SKYPE(&quot;len=%d\n&quot;, SKYPIAX_P_LOG, len);
-                                                                        break;
-                                                                } else if (len != got) {
-                                                                        DEBUGA_SKYPE(&quot;len=%d\n&quot;, SKYPIAX_P_LOG, len);
-                                                                        skypiax_sleep(1000);
-                                                                        break;
-                                                                }
-                                                        }
-
-                                                } else {
-
-                                                        WARNINGA(&quot;got is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
-                                                }
-                                        } else {
-                                                if (rt)
-                                                        ERRORA(&quot;CLI rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
-                                                memset(cli_out, 0, sizeof(cli_out));
-                                                if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                                                        len = send(fd, (char *) cli_out, sizeof(cli_out), 0);
-                                                        len = send(fd, (char *) cli_out, sizeof(cli_out) / 2, 0);
-                                                        //WARNINGA(&quot;sent %d of zeros to keep the Skype client socket busy\n&quot;, SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
-                                                } else {
-                                                        /*
-                                                           XXX do nothing 
-                                                         */
-                                                        //WARNINGA(&quot;we don't send it\n&quot;, SKYPIAX_P_LOG);
-                                                }
-                                                skypiax_sleep(1000);
-                                        }
-
-                                }
-                                DEBUGA_SKYPE(&quot;Skype outbound audio GONE\n&quot;, SKYPIAX_P_LOG);
-                                skypiax_close_socket(fd);
-                                break;
-                        }
-                        break;
-                }
-        }
-
-        DEBUGA_SKYPE(&quot;outbound audio server (I am it) EXITING\n&quot;, SKYPIAX_P_LOG);
-        skypiax_close_socket(s);
-        s = -1;
-        tech_pvt-&gt;tcp_cli_thread = NULL;
-        return NULL;
-}
-
-int skypiax_audio_read(private_t * tech_pvt)
-{
-        unsigned int samples;
-        int waitin;
-        int max_waitin=30;
-
-        waitin=0;
-        while (tech_pvt-&gt;flag_audio_srv == 0) {
-#ifdef WIN32
-                skypiax_sleep(1000);                //0.1 millisec
-#else
-                skypiax_sleep(1000);        //1 millisec
-#endif //WIN32
-                waitin++;
-
-                if(waitin == max_waitin){
-                        DEBUGA_SKYPE(&quot;read is now at max_waitin: %d\n&quot;, SKYPIAX_P_LOG, waitin);
-                        break;
-                }
-                //WARNINGA(&quot;read now is 0\n&quot;, SKYPIAX_P_LOG);
-        }
-        if(waitin &gt; 22){
-                DEBUGA_SKYPE(&quot;read is now %d\n&quot;, SKYPIAX_P_LOG, waitin);
-        }
-        //samples = skypiax_pipe_read(tech_pvt-&gt;audiopipe_srv[0], tech_pvt-&gt;read_frame.data, SAMPLES_PER_FRAME * sizeof(short));
-                        switch_mutex_lock(tech_pvt-&gt;mutex_audio_srv);
-        memcpy(tech_pvt-&gt;read_frame.data, tech_pvt-&gt;audiobuf_srv, SAMPLES_PER_FRAME * sizeof(short));
-        tech_pvt-&gt;flag_audio_srv = 0;
-                        switch_mutex_unlock(tech_pvt-&gt;mutex_audio_srv);
-
-        samples = SAMPLES_PER_FRAME * sizeof(short);
-        if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
-                if (samples)
-                        WARNINGA(&quot;read samples=%u expected=%u\n&quot;, SKYPIAX_P_LOG, samples, (int) (SAMPLES_PER_FRAME * sizeof(short)));
-                return 0;
-        } else {
-                /* A real frame */
-                tech_pvt-&gt;read_frame.datalen = samples;
-        }
-        return 1;
-}
-#endif//0
-#else
-
-void *skypiax_do_tcp_srv_thread_func(void *obj)
-{
-        private_t *tech_pvt = obj;
-        int s;
-        unsigned int len;
</del><span class="cx">         //unsigned int i;
</span><span class="cx">         //unsigned int a;
</span><span class="cx"> #if defined(WIN32) &amp;&amp; !defined(__CYGWIN__)
</span><span class="lines">@@ -1318,7 +761,7 @@
</span><span class="cx">         unsigned int size = sizeof(int);
</span><span class="cx"> #endif /* WIN32 */
</span><span class="cx">         unsigned int fd;
</span><del>-        short srv_in[SAMPLES_PER_FRAME];
</del><ins>+        short srv_in[SAMPLES_PER_FRAME*10];
</ins><span class="cx">         //short srv_out[SAMPLES_PER_FRAME / 2];
</span><span class="cx">         //struct sockaddr_in my_addr;
</span><span class="cx">         struct sockaddr_in remote_addr;
</span><span class="lines">@@ -1340,7 +783,7 @@
</span><span class="cx">         sin_size = sizeof(remote_addr);
</span><span class="cx"> 
</span><span class="cx">         /****************************/
</span><del>-        while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</del><ins>+        while (tech_pvt &amp;&amp; tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</ins><span class="cx">                         &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
</span><span class="cx">                                 || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
</span><span class="cx">                                 || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
</span><span class="lines">@@ -1379,8 +822,7 @@
</span><span class="cx"> 
</span><span class="cx">                                 if (!(running &amp;&amp; tech_pvt-&gt;running))
</span><span class="cx">                                         break;
</span><del>-                                skypiax_sleep(2000);
-                                while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</del><ins>+                                while (tech_pvt &amp;&amp; tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</ins><span class="cx">                                                 &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
</span><span class="cx">                                                         || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
</span><span class="cx">                                                         || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
</span><span class="lines">@@ -1389,6 +831,7 @@
</span><span class="cx">                                         int rt;
</span><span class="cx">                                         fd_set fs;
</span><span class="cx">                                         struct timeval to;
</span><ins>+                                        int nospace;
</ins><span class="cx"> 
</span><span class="cx">                                         if (!(running &amp;&amp; tech_pvt-&gt;running))
</span><span class="cx">                                                 break;
</span><span class="lines">@@ -1406,30 +849,36 @@
</span><span class="cx">                                                 } else {
</span><span class="cx">                                                         continue;
</span><span class="cx">                                                 }
</span><del>-#if 1
-                                        if(tech_pvt-&gt;begin_to_read==0){
-                                                        DEBUGA_SKYPE(&quot;len=%d, expected 640\n&quot;, SKYPIAX_P_LOG, len);
-                                                continue;
-                                        }
-#endif //0
</del><ins>+                                                if(tech_pvt-&gt;begin_to_read==0){
+                                                        DEBUGA_SKYPE(&quot;len=%d\n&quot;, SKYPIAX_P_LOG, len);
+                                                        continue;
+                                                }
</ins><span class="cx"> 
</span><span class="cx">                                                 if (len == -1) {
</span><span class="cx">                                                         DEBUGA_SKYPE(&quot;len=%d, error: %s\n&quot;, SKYPIAX_P_LOG, len,  strerror(errno));
</span><span class="cx">                                                         break;
</span><span class="cx">                                                 }
</span><ins>+                                                nospace=0;
</ins><span class="cx">                                                 if (len &gt; 0) {
</span><span class="cx">                                                         switch_mutex_lock(tech_pvt-&gt;mutex_audio_srv);
</span><ins>+                                                        if(switch_buffer_freespace(tech_pvt-&gt;read_buffer) &lt; len){
+                                                                //switch_buffer_zero(tech_pvt-&gt;read_buffer);
+                                                                nospace=1;
+                                                                switch_buffer_toss(tech_pvt-&gt;read_buffer, len);
+                                                        }
</ins><span class="cx">                                                         switch_buffer_write(tech_pvt-&gt;read_buffer, srv_in, len);
</span><span class="cx">                                                         switch_mutex_unlock(tech_pvt-&gt;mutex_audio_srv);
</span><ins>+                                                        if(nospace){
+                                                                //WARNINGA(&quot;NO SPACE READ: there was no space for: %d\n&quot;, SKYPIAX_P_LOG, len);
+                                                        }
</ins><span class="cx">                                                 } else if (len == 0) {
</span><del>-                                                        DEBUGA_SKYPE(&quot;CLOSED, len=%d, expected 640\n&quot;, SKYPIAX_P_LOG, len);
</del><ins>+                                                        DEBUGA_SKYPE(&quot;CLOSED\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">                                                         break;
</span><span class="cx">                                                 } else {
</span><del>-                                                        DEBUGA_SKYPE(&quot;len=%d, expected 640\n&quot;, SKYPIAX_P_LOG, len);
</del><ins>+                                                        DEBUGA_SKYPE(&quot;len=%d\n&quot;, SKYPIAX_P_LOG, len);
</ins><span class="cx">                                                 }
</span><span class="cx"> 
</span><span class="cx">                                         } else if(rt==0){
</span><del>-                                                DEBUGA_SKYPE(&quot;SRV rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
</del><span class="cx">                                                 continue;
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 DEBUGA_SKYPE(&quot;SRV rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
</span><span class="lines">@@ -1440,7 +889,6 @@
</span><span class="cx"> 
</span><span class="cx">                                 DEBUGA_SKYPE(&quot;Skype incoming audio GONE\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                                 tech_pvt-&gt;skype_callflow = CALLFLOW_INCOMING_HANGUP;
</span><del>-                                //skypiax_sleep(20000);
</del><span class="cx">                                 skypiax_close_socket(fd);
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span><span class="lines">@@ -1466,7 +914,7 @@
</span><span class="cx">         //unsigned int i;
</span><span class="cx">         //unsigned int a;
</span><span class="cx">         unsigned int fd;
</span><del>-        short cli_out[SAMPLES_PER_FRAME * 2];
</del><ins>+        short cli_out[SAMPLES_PER_FRAME * 2 * 10];
</ins><span class="cx">         //short cli_in[SAMPLES_PER_FRAME];
</span><span class="cx"> #ifdef WIN32
</span><span class="cx">         int sin_size;
</span><span class="lines">@@ -1492,7 +940,7 @@
</span><span class="cx">         sin_size = sizeof(remote_addr);
</span><span class="cx"> 
</span><span class="cx">         /****************************/
</span><del>-        while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</del><ins>+        while (tech_pvt &amp;&amp; tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</ins><span class="cx">                         &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
</span><span class="cx">                                 || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
</span><span class="cx">                                 || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
</span><span class="lines">@@ -1505,7 +953,7 @@
</span><span class="cx">                 if (!(running &amp;&amp; tech_pvt-&gt;running))
</span><span class="cx">                         break;
</span><span class="cx">                 FD_ZERO(&amp;fsgio);
</span><del>-                togio.tv_usec = 20000;        //20msec
</del><ins>+                togio.tv_usec = 60000;        //20msec
</ins><span class="cx">                 togio.tv_sec = 0;
</span><span class="cx">                 fdselectgio = s;
</span><span class="cx">                 FD_SET(fdselectgio, &amp;fsgio);
</span><span class="lines">@@ -1532,7 +980,7 @@
</span><span class="cx"> 
</span><span class="cx">                                 if (!(running &amp;&amp; tech_pvt-&gt;running))
</span><span class="cx">                                         break;
</span><del>-                                while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</del><ins>+                                while (tech_pvt &amp;&amp; tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
</ins><span class="cx">                                                 &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
</span><span class="cx">                                                         || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
</span><span class="cx">                                                         || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
</span><span class="lines">@@ -1541,13 +989,11 @@
</span><span class="cx">                                         fd_set fs;
</span><span class="cx">                                         struct timeval to;
</span><span class="cx">                                         size_t bytes_to_write;
</span><del>-                                        int waitin;
-                                        int waited_max;
</del><span class="cx"> 
</span><span class="cx">                                         if (!(running &amp;&amp; tech_pvt-&gt;running))
</span><span class="cx">                                                 break;
</span><span class="cx">                                         FD_ZERO(&amp;fs);
</span><del>-                                        to.tv_usec = 1000;        //1msec
</del><ins>+                                        to.tv_usec = 60000;        //60msec
</ins><span class="cx">                                         to.tv_sec = 0;
</span><span class="cx"> 
</span><span class="cx">                                         fdselect = fd;
</span><span class="lines">@@ -1560,7 +1006,7 @@
</span><span class="cx"> 
</span><span class="cx">                                         if(tech_pvt-&gt;begin_to_write==0){
</span><span class="cx">                                                         memset(cli_out, 255, sizeof(cli_out));
</span><del>-                                                        bytes_to_write = 320;
</del><ins>+                                                        bytes_to_write = 640;
</ins><span class="cx">                                                         len = send(fd, (char *)cli_out, bytes_to_write, 0);
</span><span class="cx">                                                         if (len == -1) {
</span><span class="cx">                                                                 DEBUGA_SKYPE(&quot;len=%d, error: %s\n&quot;, SKYPIAX_P_LOG, len,  strerror(errno));
</span><span class="lines">@@ -1570,35 +1016,27 @@
</span><span class="cx">                                         }
</span><span class="cx"> #endif//0
</span><span class="cx"> 
</span><del>-                                        //rt = select(fdselect + 1, NULL, &amp;fs, NULL, &amp;to);
-                                        //if(rt==-1)
-                                                //break;
</del><span class="cx">                                         rt=1;
</span><span class="cx"> 
</span><span class="cx">                                         if (rt &gt; 0) {
</span><span class="cx"> 
</span><del>-                                                        //DEBUGA_SKYPE(&quot;before!\n&quot;, SKYPIAX_P_LOG);
-                                                //if (tech_pvt-&gt;timer_write.timer_interface &amp;&amp; tech_pvt-&gt;timer_write.timer_interface-&gt;timer_next &amp;&amp; tech_pvt-&gt;interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-                                                        //switch_core_timer_next(&amp;tech_pvt-&gt;timer_write);
-                                                //}
-                                                        //DEBUGA_SKYPE(&quot;after!\n&quot;, SKYPIAX_P_LOG);
</del><span class="cx">                                                 bytes_to_write=0;
</span><del>-                                                waitin=0;
-                                                waited_max=1;
</del><span class="cx"> 
</span><span class="cx">                                                 if(tech_pvt-&gt;skype_callflow == CALLFLOW_INCOMING_HANGUP){
</span><span class="cx">                                                         break;
</span><span class="cx">                                                 }
</span><del>-                                                if(!switch_buffer_inuse(tech_pvt-&gt;write_buffer)){
-                                                        memset(cli_out, 255, sizeof(cli_out));
-                                                        bytes_to_write = 320;
-                                                        //DEBUGA_SKYPE(&quot;Silence!\n&quot;, SKYPIAX_P_LOG);
-                                                }else {
-                                                        switch_mutex_lock(tech_pvt-&gt;mutex_audio_cli);
-                                                        bytes_to_write = switch_buffer_read(tech_pvt-&gt;write_buffer, cli_out, 320);
-                                                        switch_mutex_unlock(tech_pvt-&gt;mutex_audio_cli);
</del><ins>+                                                switch_mutex_lock(tech_pvt-&gt;mutex_audio_cli);
+                                                if(switch_buffer_inuse(tech_pvt-&gt;write_buffer)){
+                                                        bytes_to_write = switch_buffer_read(tech_pvt-&gt;write_buffer, cli_out, 640);
</ins><span class="cx">                                                 }
</span><ins>+                                                switch_mutex_unlock(tech_pvt-&gt;mutex_audio_cli);
</ins><span class="cx"> 
</span><ins>+                                                if (!bytes_to_write) {
+                                                        memset(cli_out, 255, sizeof(cli_out));
+                                                        bytes_to_write = 640;
+                                                        //NOTICA(&quot;WRITE Silence!\n&quot;, SKYPIAX_P_LOG);
+
+                                                }
</ins><span class="cx">                                                 /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
</span><span class="cx">                                                 if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
</span><span class="cx">                                                         len = send(fd, (char *)cli_out, bytes_to_write, 0);
</span><span class="lines">@@ -1621,7 +1059,6 @@
</span><span class="cx">                                 }
</span><span class="cx">                                 DEBUGA_SKYPE(&quot;Skype outbound audio GONE\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                                 tech_pvt-&gt;skype_callflow = CALLFLOW_INCOMING_HANGUP;
</span><del>-                                //skypiax_sleep(20000);
</del><span class="cx">                                 skypiax_close_socket(fd);
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span><span class="lines">@@ -1678,9 +1115,6 @@
</span><span class="cx">         return 1;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
-
-#endif //OLDTCP
</del><span class="cx"> int skypiax_senddigit(private_t * tech_pvt, char digit)
</span><span class="cx"> {
</span><span class="cx">         char msg_to_skype[1024];
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>