<!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][14800] </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=14800">14800</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-09-09 19:46:24 -0500 (Wed, 09 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>try to improve autoflush and other silly audio glitches from edge cases and help <a href="http://jira.freeswitch.org/browse/FSCORE-416">FSCORE-416</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_rtph">freeswitch/trunk/src/include/switch_rtp.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_core_ioc">freeswitch/trunk/src/switch_core_io.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_rtpc">freeswitch/trunk/src/switch_rtp.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_timec">freeswitch/trunk/src/switch_time.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeswitch_rtph"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_rtp.h (14799 => 14800)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_rtp.h        2009-09-09 20:57:09 UTC (rev 14799)
+++ freeswitch/trunk/src/include/switch_rtp.h        2009-09-10 00:46:24 UTC (rev 14800)
</span><span class="lines">@@ -112,6 +112,8 @@
</span><span class="cx"> SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip);
</span><span class="cx"> SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port);
</span><span class="cx"> 
</span><ins>+SWITCH_DECLARE(switch_status_t) switch_rtp_set_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval);
+
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval);
</span><span class="cx"> /*! 
</span><span class="cx">   \brief create a new RTP session handle
</span><span class="lines">@@ -249,13 +251,6 @@
</span><span class="cx"> SWITCH_DECLARE(switch_socket_t *) switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session);
</span><span class="cx"> 
</span><span class="cx"> /*! 
</span><del>-  \brief Set the default samples per interval for a given RTP session
-  \param rtp_session the RTP session to set the samples per interval on
-  \param samples_per_interval the new default samples per interval 
-*/
-SWITCH_DECLARE(void) switch_rtp_set_default_samples_per_interval(switch_rtp_t *rtp_session, uint32_t samples_per_interval);
-
-/*! 
</del><span class="cx">   \brief Get the default samples per interval for a given RTP session
</span><span class="cx">   \param rtp_session the RTP session to get the samples per interval from
</span><span class="cx">   \return the default samples per interval of the RTP session
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (14799 => 14800)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-09-09 20:57:09 UTC (rev 14799)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-09-10 00:46:24 UTC (rev 14800)
</span><span class="lines">@@ -2076,7 +2076,9 @@
</span><span class="cx"> 
</span><span class="cx">         if (switch_rtp_ready(tech_pvt-&gt;rtp_session)) {
</span><span class="cx">                 switch_assert(tech_pvt-&gt;read_codec.implementation);
</span><del>-                switch_rtp_set_default_samples_per_interval(tech_pvt-&gt;rtp_session, tech_pvt-&gt;read_impl.samples_per_packet);
</del><ins>+                switch_rtp_set_interval(tech_pvt-&gt;rtp_session,
+                                                                   tech_pvt-&gt;write_codec.implementation-&gt;microseconds_per_packet,
+                                                                   tech_pvt-&gt;read_impl.samples_per_packet);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         tech_pvt-&gt;read_frame.rate = tech_pvt-&gt;rm_rate;
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_ioc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_io.c (14799 => 14800)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_io.c        2009-09-09 20:57:09 UTC (rev 14799)
+++ freeswitch/trunk/src/switch_core_io.c        2009-09-10 00:46:24 UTC (rev 14800)
</span><span class="lines">@@ -402,6 +402,7 @@
</span><span class="cx">                                                                           (uint32_t) bytes, (uint32_t) (*frame)-&gt;datalen);
</span><span class="cx">                                         switch_buffer_create_dynamic(&amp;session-&gt;raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, 0);
</span><span class="cx">                                 }
</span><ins>+
</ins><span class="cx">                                 if (!switch_buffer_write(session-&gt;raw_read_buffer, read_frame-&gt;data, read_frame-&gt;datalen)) {
</span><span class="cx">                                         status = SWITCH_STATUS_MEMERR;
</span><span class="cx">                                         goto done;
</span><span class="lines">@@ -883,10 +884,6 @@
</span><span class="cx">                         status = perform_write(session, write_frame, flags, stream_id);
</span><span class="cx">                         goto error;
</span><span class="cx">                 } else {
</span><del>-                        switch_size_t used;
-                        uint32_t bytes;
-                        switch_size_t frames;
-
</del><span class="cx">                         if (!session-&gt;raw_write_buffer) {
</span><span class="cx">                                 switch_size_t bytes_per_packet = session-&gt;write_impl.decoded_bytes_per_packet;
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
</span><span class="lines">@@ -905,140 +902,139 @@
</span><span class="cx">                                 status = SWITCH_STATUS_MEMERR; goto error;
</span><span class="cx">                         }
</span><span class="cx">                         
</span><del>-                        used = switch_buffer_inuse(session-&gt;raw_write_buffer);
-                        bytes = session-&gt;write_impl.decoded_bytes_per_packet;
-                        frames = (used / bytes);
-
</del><span class="cx">                         status = SWITCH_STATUS_SUCCESS;
</span><del>-                        if (!frames) {
-                                goto error;
-                        } else {
-                                switch_size_t x;
-                                for (x = 0; x &lt; frames; x++) {
-                                        if (switch_channel_down(session-&gt;channel) || !session-&gt;raw_write_buffer) {
-                                                goto error;
-                                        }
-                                        if ((session-&gt;raw_write_frame.datalen = (uint32_t)
-                                                 switch_buffer_read(session-&gt;raw_write_buffer, session-&gt;raw_write_frame.data, bytes)) != 0) {
-                                                int rate;
-                                                enc_frame = &amp;session-&gt;raw_write_frame;
-                                                session-&gt;raw_write_frame.rate = session-&gt;write_impl.actual_samples_per_second;
-                                                session-&gt;enc_write_frame.datalen = session-&gt;enc_write_frame.buflen;
-                                                session-&gt;enc_write_frame.timestamp = 0;
-                                                
-                                                
-                                                if (frame-&gt;codec &amp;&amp; frame-&gt;codec-&gt;implementation &amp;&amp; switch_core_codec_ready(frame-&gt;codec)) {
-                                                        rate = frame-&gt;codec-&gt;implementation-&gt;actual_samples_per_second;
-                                                } else {
-                                                        rate = session-&gt;write_impl.actual_samples_per_second;
-                                                }
-                                                
-                                                status = switch_core_codec_encode(session-&gt;write_codec,
-                                                                                                                  frame-&gt;codec,
-                                                                                                                  enc_frame-&gt;data,
-                                                                                                                  enc_frame-&gt;datalen,
-                                                                                                                  rate,
-                                                                                                                  session-&gt;enc_write_frame.data,
-                                                                                                                  &amp;session-&gt;enc_write_frame.datalen, 
-                                                                                                                  &amp;session-&gt;enc_write_frame.rate, &amp;flag);
</del><span class="cx"> 
</span><ins>+                        while(switch_buffer_inuse(session-&gt;raw_write_buffer) &gt;= session-&gt;write_impl.decoded_bytes_per_packet) {
+                                int rate;
+
+                                if (switch_channel_down(session-&gt;channel) || !session-&gt;raw_write_buffer) {
+                                        goto error;
+                                }
+                                if ((session-&gt;raw_write_frame.datalen = (uint32_t)
+                                         switch_buffer_read(session-&gt;raw_write_buffer, session-&gt;raw_write_frame.data, session-&gt;write_impl.decoded_bytes_per_packet)) == 0) {
+                                        goto error;
+                                }
+                                
+                                enc_frame = &amp;session-&gt;raw_write_frame;
+                                session-&gt;raw_write_frame.rate = session-&gt;write_impl.actual_samples_per_second;
+                                session-&gt;enc_write_frame.datalen = session-&gt;enc_write_frame.buflen;
+                                session-&gt;enc_write_frame.timestamp = 0;
+                                
+                                
+                                if (frame-&gt;codec &amp;&amp; frame-&gt;codec-&gt;implementation &amp;&amp; switch_core_codec_ready(frame-&gt;codec)) {
+                                        rate = frame-&gt;codec-&gt;implementation-&gt;actual_samples_per_second;
+                                } else {
+                                        rate = session-&gt;write_impl.actual_samples_per_second;
+                                }
</ins><span class="cx">                                                 
</span><del>-                                                
</del><ins>+                                status = switch_core_codec_encode(session-&gt;write_codec,
+                                                                                                  frame-&gt;codec,
+                                                                                                  enc_frame-&gt;data,
+                                                                                                  enc_frame-&gt;datalen,
+                                                                                                  rate,
+                                                                                                  session-&gt;enc_write_frame.data,
+                                                                                                  &amp;session-&gt;enc_write_frame.datalen, 
+                                                                                                  &amp;session-&gt;enc_write_frame.rate, &amp;flag);
</ins><span class="cx"> 
</span><del>-                                                switch (status) {
-                                                case SWITCH_STATUS_RESAMPLE:
-                                                        resample++;
-                                                        session-&gt;enc_write_frame.codec = session-&gt;write_codec;
-                                                        session-&gt;enc_write_frame.samples = enc_frame-&gt;datalen / sizeof(int16_t);
-                                                        session-&gt;enc_write_frame.m = frame-&gt;m;
-                                                        session-&gt;enc_write_frame.ssrc = frame-&gt;ssrc;
-                                                        session-&gt;enc_write_frame.payload = session-&gt;write_impl.ianacode;
-                                                        write_frame = &amp;session-&gt;enc_write_frame;
-                                                        if (!session-&gt;write_resampler) {
-                                                                switch_mutex_lock(session-&gt;resample_mutex);
-                                                                if (!session-&gt;write_resampler) {
-                                                                        status = switch_resample_create(&amp;session-&gt;write_resampler,
-                                                                                                                                        frame-&gt;codec-&gt;implementation-&gt;actual_samples_per_second,
-                                                                                                                                        session-&gt;write_impl.actual_samples_per_second, 
-                                                                                                                                        session-&gt;write_impl.decoded_bytes_per_packet,
-                                                                                                                                        SWITCH_RESAMPLE_QUALITY, 1);
-                                                                }
-                                                                switch_mutex_unlock(session-&gt;resample_mutex);
</del><ins>+                                
+                                switch (status) {
+                                case SWITCH_STATUS_RESAMPLE:
+                                        resample++;
+                                        session-&gt;enc_write_frame.codec = session-&gt;write_codec;
+                                        session-&gt;enc_write_frame.samples = enc_frame-&gt;datalen / sizeof(int16_t);
+                                        session-&gt;enc_write_frame.m = frame-&gt;m;
+                                        session-&gt;enc_write_frame.ssrc = frame-&gt;ssrc;
+                                        session-&gt;enc_write_frame.payload = session-&gt;write_impl.ianacode;
+                                        write_frame = &amp;session-&gt;enc_write_frame;
+                                        if (!session-&gt;write_resampler) {
+                                                switch_mutex_lock(session-&gt;resample_mutex);
+                                                if (!session-&gt;write_resampler) {
+                                                        status = switch_resample_create(&amp;session-&gt;write_resampler,
+                                                                                                                        frame-&gt;codec-&gt;implementation-&gt;actual_samples_per_second,
+                                                                                                                        session-&gt;write_impl.actual_samples_per_second, 
+                                                                                                                        session-&gt;write_impl.decoded_bytes_per_packet,
+                                                                                                                        SWITCH_RESAMPLE_QUALITY, 1);
+                                                }
+                                                switch_mutex_unlock(session-&gt;resample_mutex);
</ins><span class="cx"> 
</span><span class="cx">                                                                 
</span><span class="cx"> 
</span><del>-                                                                if (status != SWITCH_STATUS_SUCCESS) {
-                                                                        goto done;
-                                                                }
-                                                        }
-                                                        break;
-                                                case SWITCH_STATUS_SUCCESS:
-                                                        session-&gt;enc_write_frame.codec = session-&gt;write_codec;
-                                                        session-&gt;enc_write_frame.samples = enc_frame-&gt;datalen / sizeof(int16_t);
-                                                        session-&gt;enc_write_frame.m = frame-&gt;m;
-                                                        session-&gt;enc_write_frame.ssrc = frame-&gt;ssrc;
-                                                        session-&gt;enc_write_frame.payload = session-&gt;write_impl.ianacode;
-                                                        write_frame = &amp;session-&gt;enc_write_frame;
-                                                        break;
-                                                case SWITCH_STATUS_NOOP:
-                                                        if (session-&gt;write_resampler) {
-                                                                switch_mutex_lock(session-&gt;resample_mutex);
-                                                                if (session-&gt;write_resampler) {
-                                                                        switch_resample_destroy(&amp;session-&gt;write_resampler);
-                                                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, &quot;Deactivating write resampler\n&quot;);
-                                                                }
-                                                                switch_mutex_unlock(session-&gt;resample_mutex);
-                                                        }
-                                                        enc_frame-&gt;codec = session-&gt;write_codec;
-                                                        enc_frame-&gt;samples = enc_frame-&gt;datalen / sizeof(int16_t);
-                                                        enc_frame-&gt;m = frame-&gt;m;
-                                                        enc_frame-&gt;ssrc = frame-&gt;ssrc;
-                                                        enc_frame-&gt;payload = enc_frame-&gt;codec-&gt;implementation-&gt;ianacode;
-                                                        write_frame = enc_frame;
-                                                        status = SWITCH_STATUS_SUCCESS;
-                                                        break;
-                                                case SWITCH_STATUS_NOT_INITALIZED:
-                                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Codec init error!\n&quot;);
-                                                        write_frame = NULL;
-                                                        goto error;
-                                                default:
-                                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Codec %s encoder error %d!\n&quot;,
-                                                                                          session-&gt;read_codec-&gt;codec_interface-&gt;interface_name, status);
-                                                        write_frame = NULL;
-                                                        goto error;
</del><ins>+                                                if (status != SWITCH_STATUS_SUCCESS) {
+                                                        goto done;
</ins><span class="cx">                                                 }
</span><ins>+                                        }
+                                        break;
+                                case SWITCH_STATUS_SUCCESS:
+                                        session-&gt;enc_write_frame.codec = session-&gt;write_codec;
+                                        session-&gt;enc_write_frame.samples = enc_frame-&gt;datalen / sizeof(int16_t);
+                                        session-&gt;enc_write_frame.m = frame-&gt;m;
+                                        session-&gt;enc_write_frame.ssrc = frame-&gt;ssrc;
+                                        session-&gt;enc_write_frame.payload = session-&gt;write_impl.ianacode;
+                                        write_frame = &amp;session-&gt;enc_write_frame;
+                                        break;
+                                case SWITCH_STATUS_NOOP:
+                                        if (session-&gt;write_resampler) {
+                                                switch_mutex_lock(session-&gt;resample_mutex);
+                                                if (session-&gt;write_resampler) {
+                                                        switch_resample_destroy(&amp;session-&gt;write_resampler);
+                                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, &quot;Deactivating write resampler\n&quot;);
+                                                }
+                                                switch_mutex_unlock(session-&gt;resample_mutex);
+                                        }
+                                        enc_frame-&gt;codec = session-&gt;write_codec;
+                                        enc_frame-&gt;samples = enc_frame-&gt;datalen / sizeof(int16_t);
+                                        enc_frame-&gt;m = frame-&gt;m;
+                                        enc_frame-&gt;ssrc = frame-&gt;ssrc;
+                                        enc_frame-&gt;payload = enc_frame-&gt;codec-&gt;implementation-&gt;ianacode;
+                                        write_frame = enc_frame;
+                                        status = SWITCH_STATUS_SUCCESS;
+                                        break;
+                                case SWITCH_STATUS_NOT_INITALIZED:
+                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Codec init error!\n&quot;);
+                                        write_frame = NULL;
+                                        goto error;
+                                default:
+                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Codec %s encoder error %d!\n&quot;,
+                                                                          session-&gt;read_codec-&gt;codec_interface-&gt;interface_name, status);
+                                        write_frame = NULL;
+                                        goto error;
+                                }
</ins><span class="cx"> 
</span><del>-                                                if (!did_write_resample &amp;&amp; session-&gt;read_resampler) {
-                                                        short *data = write_frame-&gt;data;
-                                                        switch_mutex_lock(session-&gt;resample_mutex);
-                                                        if (session-&gt;read_resampler) {
-                                                                switch_resample_process(session-&gt;read_resampler, data, write_frame-&gt;datalen / 2);
-                                                                memcpy(data, session-&gt;read_resampler-&gt;to, session-&gt;read_resampler-&gt;to_len * 2);
-                                                                write_frame-&gt;samples = session-&gt;read_resampler-&gt;to_len;
-                                                                write_frame-&gt;datalen = session-&gt;read_resampler-&gt;to_len * 2;
-                                                                write_frame-&gt;rate = session-&gt;read_resampler-&gt;to_rate;
-                                                        }
-                                                        switch_mutex_unlock(session-&gt;resample_mutex);
</del><ins>+                                if (!did_write_resample &amp;&amp; session-&gt;read_resampler) {
+                                        short *data = write_frame-&gt;data;
+                                        switch_mutex_lock(session-&gt;resample_mutex);
+                                        if (session-&gt;read_resampler) {
+                                                switch_resample_process(session-&gt;read_resampler, data, write_frame-&gt;datalen / 2);
+                                                memcpy(data, session-&gt;read_resampler-&gt;to, session-&gt;read_resampler-&gt;to_len * 2);
+                                                write_frame-&gt;samples = session-&gt;read_resampler-&gt;to_len;
+                                                write_frame-&gt;datalen = session-&gt;read_resampler-&gt;to_len * 2;
+                                                write_frame-&gt;rate = session-&gt;read_resampler-&gt;to_rate;
+                                        }
+                                        switch_mutex_unlock(session-&gt;resample_mutex);
</ins><span class="cx"> 
</span><del>-                                                }
</del><ins>+                                }
</ins><span class="cx"> 
</span><del>-                                                if (flag &amp; SFF_CNG) {
-                                                        switch_set_flag(write_frame, SFF_CNG);
-                                                }
</del><ins>+                                if (flag &amp; SFF_CNG) {
+                                        switch_set_flag(write_frame, SFF_CNG);
+                                }
</ins><span class="cx">                                                 
</span><del>-                                                if (ptime_mismatch || resample) {
-                                                        write_frame-&gt;timestamp = 0;
-                                                }
</del><ins>+                                if (ptime_mismatch || resample) {
+                                        write_frame-&gt;timestamp = 0;
+                                }
</ins><span class="cx"> 
</span><del>-                                                if ((status = perform_write(session, write_frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
-                                                        break;
-                                                }
-                                        }
</del><ins>+                                if ((status = perform_write(session, write_frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
+                                        break;
</ins><span class="cx">                                 }
</span><del>-                                goto error;
</del><ins>+
</ins><span class="cx">                         }
</span><ins>+                        
+                        goto error;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+                
+
+
+
</ins><span class="cx">         
</span><span class="cx">  done:
</span><span class="cx"> 
</span><span class="lines">@@ -1047,12 +1043,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (do_write) {
</span><del>-
-                
-
-                status = perform_write(session, write_frame, flags, stream_id);
-
-                
</del><ins>+                status = perform_write(session, write_frame, flags, stream_id);                
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">  error:
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_rtpc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_rtp.c (14799 => 14800)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_rtp.c        2009-09-09 20:57:09 UTC (rev 14799)
+++ freeswitch/trunk/src/switch_rtp.c        2009-09-10 00:46:24 UTC (rev 14800)
</span><span class="lines">@@ -182,6 +182,7 @@
</span><span class="cx">         char *remote_host_str;
</span><span class="cx">         switch_time_t last_stun;
</span><span class="cx">         uint32_t samples_per_interval;
</span><ins>+        uint32_t samples_per_second;
</ins><span class="cx">         uint32_t conf_samples_per_interval;
</span><span class="cx">         uint32_t rsamples_per_interval;
</span><span class="cx">         uint32_t ms_per_packet;
</span><span class="lines">@@ -213,6 +214,7 @@
</span><span class="cx">         switch_rtp_bug_flag_t rtp_bugs;
</span><span class="cx">         switch_rtp_stats_t stats;
</span><span class="cx">         int hot_hits;
</span><ins>+        int sync_packets;
</ins><span class="cx"> 
</span><span class="cx"> #ifdef ENABLE_ZRTP
</span><span class="cx">         zrtp_session_t *zrtp_session;
</span><span class="lines">@@ -1038,12 +1040,21 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SWITCH_DECLARE(switch_status_t) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
</del><ins>+SWITCH_DECLARE(switch_status_t) switch_rtp_set_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
</ins><span class="cx"> {
</span><span class="cx">         rtp_session-&gt;ms_per_packet = ms_per_packet;
</span><span class="cx">         rtp_session-&gt;samples_per_interval = rtp_session-&gt;conf_samples_per_interval = samples_per_interval;
</span><span class="cx">         rtp_session-&gt;missed_count = 0;
</span><ins>+        rtp_session-&gt;samples_per_second = (uint32_t)((double)(1000.0f / (double)(rtp_session-&gt;ms_per_packet / 1000)) * (double)rtp_session-&gt;samples_per_interval);
</ins><span class="cx"> 
</span><ins>+        return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
+{
+
+        switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
+        
</ins><span class="cx">         if (rtp_session-&gt;timer_name) {
</span><span class="cx">                 if (rtp_session-&gt;timer.timer_interface) {
</span><span class="cx">                         switch_core_timer_destroy(&amp;rtp_session-&gt;timer);
</span><span class="lines">@@ -1123,9 +1134,10 @@
</span><span class="cx">         rtp_session-&gt;recv_msg.header.cc = 0;
</span><span class="cx"> 
</span><span class="cx">         rtp_session-&gt;payload = payload;
</span><del>-        rtp_session-&gt;ms_per_packet = ms_per_packet;
-        rtp_session-&gt;samples_per_interval = rtp_session-&gt;conf_samples_per_interval = samples_per_interval;
</del><span class="cx"> 
</span><ins>+        switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
+        rtp_session-&gt;conf_samples_per_interval = samples_per_interval;
+
</ins><span class="cx">         if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) &amp;&amp; switch_strlen_zero(timer_name)) {
</span><span class="cx">                 timer_name = &quot;soft&quot;;
</span><span class="cx">         }
</span><span class="lines">@@ -1490,11 +1502,6 @@
</span><span class="cx">         return rtp_session-&gt;sock_input;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SWITCH_DECLARE(void) switch_rtp_set_default_samples_per_interval(switch_rtp_t *rtp_session, uint32_t samples_per_interval)
-{
-        rtp_session-&gt;samples_per_interval = samples_per_interval;
-}
-
</del><span class="cx"> SWITCH_DECLARE(uint32_t) switch_rtp_get_default_samples_per_interval(switch_rtp_t *rtp_session)
</span><span class="cx"> {
</span><span class="cx">         return rtp_session-&gt;samples_per_interval;
</span><span class="lines">@@ -1783,7 +1790,9 @@
</span><span class="cx">                         if ((switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOFLUSH) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_STICKY_FLUSH)) &amp;&amp;
</span><span class="cx">                                 rtp_session-&gt;read_pollfd) {
</span><span class="cx">                                 if (switch_poll(rtp_session-&gt;read_pollfd, 1, &amp;fdr, 1) == SWITCH_STATUS_SUCCESS) {
</span><del>-                                        if (++rtp_session-&gt;hot_hits &gt;= 10) {
</del><ins>+                                        rtp_session-&gt;hot_hits += rtp_session-&gt;samples_per_interval;
+                                        
+                                        if (rtp_session-&gt;hot_hits &gt;= rtp_session-&gt;samples_per_second * 60) {
</ins><span class="cx">                                                 hot_socket = 1;
</span><span class="cx">                                         }
</span><span class="cx">                                 } else {
</span><span class="lines">@@ -1792,8 +1801,17 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         if (hot_socket) {
</span><ins>+                                rtp_session-&gt;sync_packets++;
</ins><span class="cx">                                 switch_core_timer_sync(&amp;rtp_session-&gt;timer);
</span><span class="cx">                         } else {
</span><ins>+                                if (rtp_session-&gt;sync_packets) {
+#if 0
+                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
+                                                                          &quot;Auto-Flush catching up %d packets (%d)ms.\n&quot;, 
+                                                                          rtp_session-&gt;sync_packets, rtp_session-&gt;ms_per_packet * rtp_session-&gt;sync_packets);
+#endif
+                                        rtp_session-&gt;sync_packets = 0;
+                                }
</ins><span class="cx">                                 switch_core_timer_next(&amp;rtp_session-&gt;timer);
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -2440,6 +2458,7 @@
</span><span class="cx">                         rtp_session-&gt;ts = (uint32_t) timestamp;
</span><span class="cx">                 } else if (rtp_session-&gt;timer.timer_interface) {
</span><span class="cx">                         rtp_session-&gt;ts = rtp_session-&gt;timer.samplecount;
</span><ins>+                        
</ins><span class="cx">                         if (rtp_session-&gt;ts &lt;= rtp_session-&gt;last_write_ts) {
</span><span class="cx">                                 rtp_session-&gt;ts = rtp_session-&gt;last_write_ts + rtp_session-&gt;samples_per_interval;
</span><span class="cx">                         }
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_timec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_time.c (14799 => 14800)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_time.c        2009-09-09 20:57:09 UTC (rev 14799)
+++ freeswitch/trunk/src/switch_time.c        2009-09-10 00:46:24 UTC (rev 14800)
</span><span class="lines">@@ -307,8 +307,8 @@
</span><span class="cx"> 
</span><span class="cx">         /* apply timestamp */
</span><span class="cx">         if (timer_step(timer) == SWITCH_STATUS_SUCCESS) {
</span><del>-                /* push the reference into the future 2 more intervals to prevent collision */
-                private_info-&gt;reference += 2;
</del><ins>+                /* push the reference into the future to prevent collision */
+                private_info-&gt;reference++;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>