<!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][15190] </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=15190">15190</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-10-21 18:01:37 -0500 (Wed, 21 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre><a href="http://jira.freeswitch.org/browse/SFSIP-180">SFSIP-180</a> report hack in sofia lib to pekka for better answer</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunklibssofiasiplibsofiasipuanuanua_sessionc">freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunklibssofiasiplibsofiasipuanuanua_sessionc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c (15189 => 15190)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c        2009-10-21 20:57:46 UTC (rev 15189)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c        2009-10-21 23:01:37 UTC (rev 15190)
</span><span class="lines">@@ -943,14 +943,19 @@
</span><span class="cx">   SU_DEBUG_5((&quot;nua(%p): %s: %s %s in %u %s\n&quot;, \
</span><span class="cx">               (void *)nh, cr-&gt;cr_method_name, (m), received, status, phrase))
</span><span class="cx"> 
</span><ins>+ retry:
+
</ins><span class="cx">   if (!ss || !sip || 300 &lt;= status)
</span><span class="cx">     /* Xyzzy */;
</span><span class="cx">   else if (!session_get_description(sip, &amp;sdp, &amp;len))
</span><span class="cx">     /* No SDP */;
</span><span class="cx">   else if (cr-&gt;cr_answer_recv) {
</span><span class="cx">     /* Ignore spurious answers after completing O/A */
</span><del>-    LOG3(&quot;ignoring duplicate&quot;);
-    sdp = NULL;
</del><ins>+          //LOG3(&quot;ignoring duplicate&quot;);
+          //sdp = NULL;
+          // we need to make sure its *actually* a dup, so we can't assume for now.
+          cr-&gt;cr_answer_recv = 0;
+          goto retry;
</ins><span class="cx">   }
</span><span class="cx">   else if (cr-&gt;cr_offer_sent) {
</span><span class="cx">     /* case 1: answer to our offer */
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15189 => 15190)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-10-21 20:57:46 UTC (rev 15189)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-10-21 23:01:37 UTC (rev 15190)
</span><span class="lines">@@ -3474,6 +3474,7 @@
</span><span class="cx">         switch_core_session_t *other_session = NULL;
</span><span class="cx">         switch_channel_t *other_channel = NULL;
</span><span class="cx">         char st[80] = &quot;&quot;;
</span><ins>+        int is_dup_sdp = 0;
</ins><span class="cx"> 
</span><span class="cx">         tl_gets(tags,
</span><span class="cx">                         NUTAG_CALLSTATE_REF(ss_state),
</span><span class="lines">@@ -3519,18 +3520,23 @@
</span><span class="cx">                 if (r_sdp) {
</span><span class="cx">                         sdp_parser_t *parser;
</span><span class="cx">                         sdp_session_t *sdp;
</span><ins>+                        
+                        if (!switch_strlen_zero(tech_pvt-&gt;remote_sdp_str) &amp;&amp; !strcmp(tech_pvt-&gt;remote_sdp_str, r_sdp)) {
+                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Duplicate SDP\n%s\n&quot;, r_sdp);
+                                is_dup_sdp = 1;
+                        } else {
+                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Remote SDP:\n%s\n&quot;, r_sdp);
+                                tech_pvt-&gt;remote_sdp_str = switch_core_session_strdup(session, r_sdp);
+                                switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, r_sdp);
</ins><span class="cx"> 
</span><del>-                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Remote SDP:\n%s\n&quot;, r_sdp);
-                        tech_pvt-&gt;remote_sdp_str = switch_core_session_strdup(session, r_sdp);
-                        switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, r_sdp);
-
-                        if ( sofia_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) &amp;&amp; (parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
-                                if ((sdp = sdp_session(parser))) {
-                                        sofia_glue_set_r_sdp_codec_string(channel, (tech_pvt-&gt;profile?tech_pvt-&gt;profile-&gt;codec_string:NULL), sdp);
</del><ins>+                                if (sofia_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) &amp;&amp; (parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
+                                        if ((sdp = sdp_session(parser))) {
+                                                sofia_glue_set_r_sdp_codec_string(channel, (tech_pvt-&gt;profile?tech_pvt-&gt;profile-&gt;codec_string:NULL), sdp);
+                                        }
+                                        sdp_parser_free(parser);
</ins><span class="cx">                                 }
</span><del>-                                sdp_parser_free(parser);
</del><ins>+                                sofia_glue_pass_sdp(tech_pvt, (char *) r_sdp);
</ins><span class="cx">                         }
</span><del>-                        sofia_glue_pass_sdp(tech_pvt, (char *) r_sdp);
</del><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -3848,6 +3854,8 @@
</span><span class="cx">                                         }
</span><span class="cx">                                         goto done;
</span><span class="cx">                                 } else {
</span><ins>+                                        sofia_set_flag_locked(tech_pvt, TFLAG_REINVITE);
+
</ins><span class="cx">                                         if (tech_pvt-&gt;num_codecs) {
</span><span class="cx">                                                 if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
</span><span class="cx">                                                         if ((sdp = sdp_session(parser))) {
</span><span class="lines">@@ -3861,14 +3869,15 @@
</span><span class="cx">                                                         goto done;
</span><span class="cx">                                                 }
</span><span class="cx">                                                 sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
</span><del>-                                                sofia_set_flag_locked(tech_pvt, TFLAG_REINVITE);
</del><ins>+                                                
</ins><span class="cx">                                                 if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Reinvite RTP Error!\n&quot;);
</span><span class="cx">                                                         is_ok = 0;
</span><span class="cx">                                                         switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
</span><span class="cx">                                                 }
</span><del>-                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Processing Reinvite\n&quot;);
</del><ins>+                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Processing updated SDP\n&quot;);
</ins><span class="cx">                                         } else {
</span><ins>+                                                sofia_clear_flag_locked(tech_pvt, TFLAG_REINVITE);
</ins><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Reinvite Codec Error!\n&quot;);
</span><span class="cx">                                                 is_ok = 0;
</span><span class="cx">                                         }
</span><span class="lines">@@ -3891,6 +3900,10 @@
</span><span class="cx">                 }
</span><span class="cx">                 break;
</span><span class="cx">         case nua_callstate_ready:
</span><ins>+                if (r_sdp &amp;&amp; !is_dup_sdp &amp;&amp; switch_rtp_ready(tech_pvt-&gt;rtp_session)) {
+                        ss_state = nua_callstate_completed;
+                        goto state_process;
+                }
</ins><span class="cx"> 
</span><span class="cx">                 if (r_sdp &amp;&amp; sofia_test_flag(tech_pvt, TFLAG_NOSDP_REINVITE)) {
</span><span class="cx">                         sdp_parser_t *parser;
</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 (15189 => 15190)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-10-21 20:57:46 UTC (rev 15189)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-10-21 23:01:37 UTC (rev 15190)
</span><span class="lines">@@ -2321,7 +2321,7 @@
</span><span class="cx">                 //const char *port = switch_channel_get_variable(tech_pvt-&gt;channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
</span><span class="cx">                 char *remote_host = switch_rtp_get_remote_host(tech_pvt-&gt;rtp_session);
</span><span class="cx">                 switch_port_t remote_port = switch_rtp_get_remote_port(tech_pvt-&gt;rtp_session);
</span><del>-                
</del><ins>+
</ins><span class="cx">                 if (remote_host &amp;&amp; remote_port &amp;&amp; !strcmp(remote_host, tech_pvt-&gt;remote_sdp_audio_ip) &amp;&amp; remote_port == tech_pvt-&gt;remote_sdp_audio_port) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt-&gt;session), SWITCH_LOG_DEBUG, &quot;Audio params are unchanged for %s.\n&quot;, switch_channel_get_name(tech_pvt-&gt;channel));
</span><span class="cx">                         goto video;
</span><span class="lines">@@ -2970,7 +2970,6 @@
</span><span class="cx"> 
</span><span class="cx">                 } else if (m-&gt;m_type == sdp_media_audio &amp;&amp; m-&gt;m_port &amp;&amp; !got_audio) {
</span><span class="cx">                         sdp_rtpmap_t *map;
</span><del>-
</del><span class="cx">                         for (attr = m-&gt;m_attributes; attr; attr = attr-&gt;a_next) {
</span><span class="cx">                                 if (!strcasecmp(attr-&gt;a_name, &quot;ptime&quot;) &amp;&amp; attr-&gt;a_value) {
</span><span class="cx">                                         ptime = atoi(attr-&gt;a_value);
</span><span class="lines">@@ -3065,26 +3064,43 @@
</span><span class="cx">                   greed:
</span><span class="cx">                         x = 0;
</span><span class="cx"> 
</span><del>-                        if (tech_pvt-&gt;rm_encoding) {
</del><ins>+                        if (tech_pvt-&gt;rm_encoding) {// &amp;&amp; !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
+                                char *remote_host = tech_pvt-&gt;remote_sdp_audio_ip;
+                                switch_port_t remote_port = tech_pvt-&gt;remote_sdp_audio_port;
+                                int same = 0;
+
+                                if (switch_rtp_ready(tech_pvt-&gt;rtp_session)) {
+                                        remote_host = switch_rtp_get_remote_host(tech_pvt-&gt;rtp_session);
+                                        remote_port = switch_rtp_get_remote_port(tech_pvt-&gt;rtp_session);
+                                }
+                                
</ins><span class="cx">                                 for (map = m-&gt;m_rtpmaps; map; map = map-&gt;rm_next) {
</span><del>-                                        if (map-&gt;rm_pt &lt; 96) {
</del><ins>+                                        if (switch_strlen_zero(map-&gt;rm_encoding) &amp;&amp; map-&gt;rm_pt &lt; 96) {
</ins><span class="cx">                                                 match = (map-&gt;rm_pt == tech_pvt-&gt;pt) ? 1 : 0;
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 match = strcasecmp(switch_str_nil(map-&gt;rm_encoding), tech_pvt-&gt;iananame) ? 0 : 1;
</span><span class="cx">                                         }
</span><span class="cx"> 
</span><del>-                                        if (match &amp;&amp; connection-&gt;c_address &amp;&amp; tech_pvt-&gt;remote_sdp_audio_ip &amp;&amp; 
-                                                !strcmp(connection-&gt;c_address, tech_pvt-&gt;remote_sdp_audio_ip) &amp;&amp; m-&gt;m_port == tech_pvt-&gt;remote_sdp_audio_port) {
-                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Our existing sdp is still good [%s %s:%d], let's keep it.\n&quot;,
-                                                                                  tech_pvt-&gt;rm_encoding, tech_pvt-&gt;remote_sdp_audio_ip, tech_pvt-&gt;remote_sdp_audio_port);
-                                                got_audio = 1;
</del><ins>+                                        if (match &amp;&amp; connection-&gt;c_address &amp;&amp; remote_host &amp;&amp;
+                                                !strcmp(connection-&gt;c_address, remote_host) &amp;&amp; m-&gt;m_port == remote_port) {
+                                                same = 1;
+                                        } else {
+                                                same = 0;
</ins><span class="cx">                                                 break;
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><ins>+
+                                if (same) {
+                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, 
+                                                                          &quot;Our existing sdp is still good [%s %s:%d], let's keep it.\n&quot;,
+                                                                          tech_pvt-&gt;rm_encoding, tech_pvt-&gt;remote_sdp_audio_ip, tech_pvt-&gt;remote_sdp_audio_port);
+                                        got_audio = 1;
+                                } else {
+                                        match = 0;
+                                        got_audio = 0;
+                                }
</ins><span class="cx">                         }
</span><del>-
-
-
</del><ins>+                        
</ins><span class="cx">                         for (map = m-&gt;m_rtpmaps; map; map = map-&gt;rm_next) {
</span><span class="cx">                                 int32_t i;
</span><span class="cx">                                 uint32_t near_rate = 0;
</span><span class="lines">@@ -3144,7 +3160,7 @@
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Audio Codec Compare [%s:%d:%u:%d]/[%s:%d:%u:%d]\n&quot;,
</span><span class="cx">                                                                           rm_encoding, map-&gt;rm_pt, (int) map-&gt;rm_rate, ptime,
</span><span class="cx">                                                                           imp-&gt;iananame, imp-&gt;ianacode, codec_rate, imp-&gt;microseconds_per_packet / 1000);
</span><del>-                                        if (map-&gt;rm_pt &lt; 96) {
</del><ins>+                                        if (switch_strlen_zero(map-&gt;rm_encoding) &amp;&amp; map-&gt;rm_pt &lt; 96) {
</ins><span class="cx">                                                 match = (map-&gt;rm_pt == imp-&gt;ianacode) ? 1 : 0;
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 match = strcasecmp(rm_encoding, imp-&gt;iananame) ? 0 : 1;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>