]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 3 Jan 2008 00:50:53 +0000 (00:50 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 3 Jan 2008 00:50:53 +0000 (00:50 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7067 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_iax/mod_iax.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index 2206eaaf55a9d25ad345368e169dc48bdef8ad9f..9278c95759186ce57fd0096a49bf8f20e4d785d9 100644 (file)
@@ -428,7 +428,7 @@ typedef enum {
        SWITCH_MESSAGE_INDICATE_HOLD      - indicate hold
        SWITCH_MESSAGE_INDICATE_UNHOLD    - indicate unhold
        SWITCH_MESSAGE_INDICATE_REDIRECT  - indicate redirect
-       SWITCH_MESSAGE_INDICATE_REJECT    - indicate reject
+       SWITCH_MESSAGE_INDICATE_RESPOND    - indicate reject
        SWITCH_MESSAGE_INDICATE_BROADCAST - indicate media broadcast
        SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT - indicate media broadcast
 </pre>
@@ -447,7 +447,7 @@ typedef enum {
        SWITCH_MESSAGE_INDICATE_HOLD,
        SWITCH_MESSAGE_INDICATE_UNHOLD,
        SWITCH_MESSAGE_INDICATE_REDIRECT,
-       SWITCH_MESSAGE_INDICATE_REJECT,
+       SWITCH_MESSAGE_INDICATE_RESPOND,
        SWITCH_MESSAGE_INDICATE_BROADCAST,
        SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT
 } switch_core_session_message_types_t;
index bc1b9bdae72b954d76f979a82d637d8025954fd5..030f0d289cca414bdb3a0f863a020b7c819fd2b9 100644 (file)
@@ -416,14 +416,14 @@ SWITCH_STANDARD_APP(redirect_function)
 
 }
 
-SWITCH_STANDARD_APP(reject_function)
+SWITCH_STANDARD_APP(respond_function)
 {
        switch_core_session_message_t msg = { 0 };
 
-       /* Tell the channel to reject the call */
+       /* Tell the channel to respond the call */
        msg.from = __FILE__;
        msg.string_arg = data;
-       msg.message_id = SWITCH_MESSAGE_INDICATE_REJECT;
+       msg.message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
        switch_core_session_receive_message(session, &msg);
 
 }
@@ -1631,7 +1631,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "detect_speech", "Detect speech", "Detect speech on a channel.", detect_speech_function, DETECT_SPEECH_SYNTAX, SAF_NONE);
        SWITCH_ADD_APP(app_interface, "ivr", "Run an ivr menu", "Run an ivr menu.", ivr_application_function, "<menu_name>", SAF_NONE);
        SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "<redirect_data>", SAF_SUPPORT_NOMEDIA);
-       SWITCH_ADD_APP(app_interface, "reject", "Send session reject", "Send a reject message to a session.", reject_function, "<reject_data>", SAF_SUPPORT_NOMEDIA);
+       SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
+       SWITCH_ADD_APP(app_interface, "reject", "Send session reject (depricated)", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
index a913e72521d2466848143f489ebc0a9253daf917..0d99ff91761f1ec779704e362c8f7bf4f2bed2ec 100644 (file)
@@ -761,7 +761,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
        switch_assert(tech_pvt != NULL);
 
        switch (msg->message_id) {
-       case SWITCH_MESSAGE_INDICATE_REJECT:
+       case SWITCH_MESSAGE_INDICATE_RESPOND:
                {
                        if (tech_pvt->iax_session) {
                                iax_reject(tech_pvt->iax_session, msg->string_arg ? msg->string_arg : "Call Rejected");
index f82a79edc8ce1ed1c9677aa7e9fa73ce75bda979..135f0ec74212f9795444e6b2a91dbac33cd9ced2 100644 (file)
@@ -415,6 +415,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
        }
 
        nua_respond(tech_pvt->nh, SIP_200_OK,
+                               NUTAG_AUTOANSWER(0),
                                NUTAG_SESSION_TIMER(session_timeout),
                                SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
                                SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
@@ -932,46 +933,45 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                        nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END());
                }
                break;
-       case SWITCH_MESSAGE_INDICATE_REJECT:
-               if (msg->string_arg) {
-                       int code = 0;
-                       char *reason = NULL;
-                       
-                       if (switch_channel_test_flag(channel, CF_ANSWERED)) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call is already answered, Rejecting with hangup\n");
-                               switch_channel_hangup(channel, SWITCH_CAUSE_CALL_REJECTED);
-                       } else {
+       case SWITCH_MESSAGE_INDICATE_RESPOND:
+               if (msg->numeric_arg || msg->string_arg) {
+                       int code = msg->numeric_arg;
+                       const char *reason = NULL;
 
+                       if (code) {
+                               reason = msg->string_arg;
+                       } else {
                                if (!switch_strlen_zero(msg->string_arg)){
                                        code = atoi(msg->string_arg);
                                        if ((reason = strchr(msg->string_arg, ' '))) {
                                                reason++;
-                                       }                       
+                                       }
                                }
+                       }
 
-                               if (!reason && code != 407) {
-                                       reason = "Call Refused";
-                               }
+                       if (!reason && code != 407) {
+                               reason = "Call Refused";
+                       }
 
-                               if (!(code > 400 && code < 700)) {
-                                       code = 488;
-                               }
+                       if (!(code > 400 && code < 700)) {
+                               code = 488;
+                       }
 
-                               if (code == 407) {
-                                       const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
-                                       const char *to_host = reason;
+                       if (code == 407) {
+                               const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
+                               const char *to_host = reason;
                                        
-                                       if (switch_strlen_zero(to_host)) {
-                                               to_host = switch_channel_get_variable(channel, "sip_to_host");
-                                       }
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
-                                       sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0); 
-                                       switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Rejecting with %d %s\n", code, reason);
-                                       nua_respond(tech_pvt->nh, code, reason, TAG_END());
+                               if (switch_strlen_zero(to_host)) {
+                                       to_host = switch_channel_get_variable(channel, "sip_to_host");
                                }
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
+                               sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0); 
+                               switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Rejecting with %d %s\n", code, reason);
+                               nua_respond(tech_pvt->nh, code, reason, TAG_END());
                        }
+                       
                }
                break;
        case SWITCH_MESSAGE_INDICATE_RINGING:
@@ -1023,6 +1023,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                                switch_channel_mark_pre_answered(channel);
                                nua_respond(tech_pvt->nh,
                                                        SIP_183_SESSION_PROGRESS,
+                                                       NUTAG_AUTOANSWER(0),
                                                        SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
                                                        SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
                        }
index f78fc310324db35b6054302337548787b50b1e0c..9c5f3b808b4d62447509626c0848b08d2ddf19c2 100644 (file)
@@ -436,27 +436,27 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created agent for %s\n", profile->name);
 
        nua_set_params(profile->nua,
-                                       NUTAG_APPL_METHOD("OPTIONS"),
-                                       NUTAG_APPL_METHOD("NOTIFY"),
-                                       NUTAG_APPL_METHOD("INFO"),
-                                       NUTAG_AUTOANSWER(0),
-                                       NUTAG_AUTOALERT(0),
-                                       NUTAG_ALLOW("REGISTER"),
-                                       NUTAG_ALLOW("REFER"),
-                                       NUTAG_ALLOW("INFO"),
-                                       NUTAG_ALLOW("NOTIFY"),
-                                       NUTAG_ALLOW_EVENTS("talk"),
-                                       NUTAG_SESSION_TIMER(profile->session_timeout),
-                                       NTATAG_MAX_PROCEEDING(profile->max_proceeding),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("SUBSCRIBE")),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence")),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("dialog")),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("call-info")),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence.winfo")),
-                                       TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("message-summary")),
-                                       SIPTAG_SUPPORTED_STR("100rel, precondition, timer"), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
+                                  NUTAG_APPL_METHOD("OPTIONS"),
+                                  NUTAG_APPL_METHOD("NOTIFY"),
+                                  NUTAG_APPL_METHOD("INFO"),
+                                  NUTAG_AUTOANSWER(0),
+                                  NUTAG_AUTOALERT(0),
+                                  NUTAG_ALLOW("REGISTER"),
+                                  NUTAG_ALLOW("REFER"),
+                                  NUTAG_ALLOW("INFO"),
+                                  NUTAG_ALLOW("NOTIFY"),
+                                  NUTAG_ALLOW_EVENTS("talk"),
+                                  NUTAG_SESSION_TIMER(profile->session_timeout),
+                                  NTATAG_MAX_PROCEEDING(profile->max_proceeding),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("SUBSCRIBE")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("dialog")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("call-info")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence.winfo")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("message-summary")),
+                                  SIPTAG_SUPPORTED_STR("100rel, precondition, timer"), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set params for %s\n", profile->name);
 
@@ -1260,79 +1260,102 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
 {
 
 
-       if (sip && session && (status == 180 || status == 183 || status == 200)) {
+       if (sip && session) {
                switch_channel_t *channel = switch_core_session_get_channel(session);
-               const char *astate = "early";
-               url_t *from = NULL, *to = NULL, *contact = NULL;
-
-               if (sip->sip_to) {
-                       to = sip->sip_to->a_url;
-               }
-               if (sip->sip_from) {
-                       from = sip->sip_from->a_url;
-               }
-               if (sip->sip_contact) {
-                       contact = sip->sip_contact->m_url;
-               }
-
-               if (status == 200) {
-                       astate = "confirmed";
+               const char *uuid;
+               switch_core_session_t *other_session;
+               
+               if (switch_channel_test_flag(channel, CF_BYPASS_MEDIA)) {
+                       if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+                               switch_core_session_message_t msg;
+
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Passing %d %s to other leg\n", status, phrase);
+
+                               msg.message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
+                               msg.from = __FILE__;
+                               msg.numeric_arg = status;
+                               msg.string_arg = phrase;
+                               switch_core_session_receive_message(other_session, &msg);
+                               switch_core_session_rwunlock(other_session);
+                       }
+                       
+                       return;
                }
 
-               if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) && 
-                       !switch_channel_test_flag(channel, CF_RING_READY)) {
-                       const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
-                       const char *user_agent = "", *call_id = "";
-                       char *sql = NULL;
+               if ((status == 180 || status == 183 || status == 200)) {
+                       switch_channel_t *channel = switch_core_session_get_channel(session);
+                       const char *astate = "early";
+                       url_t *from = NULL, *to = NULL, *contact = NULL;
 
-                       if (sip->sip_user_agent) {
-                               user_agent = switch_str_nil(sip->sip_user_agent->g_string);
+                       if (sip->sip_to) {
+                               to = sip->sip_to->a_url;
                        }
-
-                       if (sip->sip_call_id) {
-                               call_id = switch_str_nil(sip->sip_call_id->i_id);
+                       if (sip->sip_from) {
+                               from = sip->sip_from->a_url;
                        }
-
-                       if (to) {
-                               from_user = switch_str_nil(to->url_user);
+                       if (sip->sip_contact) {
+                               contact = sip->sip_contact->m_url;
                        }
 
-                       if (from) {
-                               from_host = switch_str_nil(from->url_host);
-                               to_user = switch_str_nil(from->url_user);
-                               to_host = switch_str_nil(from->url_host);
+                       if (status == 200) {
+                               astate = "confirmed";
                        }
 
-                       if (contact) {
-                               contact_user = switch_str_nil(contact->url_user);
-                               contact_host = switch_str_nil(contact->url_host);
-                       }
+                       if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) && 
+                               !switch_channel_test_flag(channel, CF_RING_READY)) {
+                               const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
+                               const char *user_agent = "", *call_id = "";
+                               char *sql = NULL;
+
+                               if (sip->sip_user_agent) {
+                                       user_agent = switch_str_nil(sip->sip_user_agent->g_string);
+                               }
+
+                               if (sip->sip_call_id) {
+                                       call_id = switch_str_nil(sip->sip_call_id->i_id);
+                               }
+
+                               if (to) {
+                                       from_user = switch_str_nil(to->url_user);
+                               }
+
+                               if (from) {
+                                       from_host = switch_str_nil(from->url_host);
+                                       to_user = switch_str_nil(from->url_user);
+                                       to_host = switch_str_nil(from->url_host);
+                               }
 
-                       sql = switch_mprintf(
-                                                                "insert into sip_dialogs values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
-                                                                call_id,
-                                                                switch_core_session_get_uuid(session),
-                                                                to_user,
-                                                                to_host,
-                                                                from_user,
-                                                                from_host,
-                                                                contact_user,
-                                                                contact_host,
-                                                                astate,
-                                                                "outbound",
-                                                                user_agent
-                                                                );
-
-                       switch_assert(sql);
-
-                       sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
-                       free(sql);
-               } else if (status == 200) { 
-                       char *sql = NULL;
-                       sql = switch_mprintf("update sip_dialogs set state='%s' where uuid='%s';\n", astate, switch_core_session_get_uuid(session));
-                       switch_assert(sql); 
-                       sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex); 
-                       free(sql);
+                               if (contact) {
+                                       contact_user = switch_str_nil(contact->url_user);
+                                       contact_host = switch_str_nil(contact->url_host);
+                               }
+
+                               sql = switch_mprintf(
+                                                                        "insert into sip_dialogs values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+                                                                        call_id,
+                                                                        switch_core_session_get_uuid(session),
+                                                                        to_user,
+                                                                        to_host,
+                                                                        from_user,
+                                                                        from_host,
+                                                                        contact_user,
+                                                                        contact_host,
+                                                                        astate,
+                                                                        "outbound",
+                                                                        user_agent
+                                                                        );
+
+                               switch_assert(sql);
+
+                               sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
+                               free(sql);
+                       } else if (status == 200) { 
+                               char *sql = NULL;
+                               sql = switch_mprintf("update sip_dialogs set state='%s' where uuid='%s';\n", astate, switch_core_session_get_uuid(session));
+                               switch_assert(sql); 
+                               sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex); 
+                               free(sql);
+                       }
                }
        }
 }
@@ -1390,6 +1413,8 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
                }
        }
 
+ state_process:
+       
        switch ((enum nua_callstate) ss_state) {
        case nua_callstate_init:
                break;
@@ -1537,6 +1562,10 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
                                        goto done;
                                }
                        }
+
+               } else {
+                       ss_state = nua_callstate_completed;
+                       goto state_process;
                }
 
                break;
@@ -1589,6 +1618,14 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
                                                switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
                                        }
                                }
+
+
+                               nua_respond(tech_pvt->nh, SIP_200_OK,
+                                                       SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
+                                                       SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
+                                                       SOATAG_AUDIO_AUX("cn telephone-event"),
+                                                       NUTAG_INCLUDE_EXTRA_SDP(1),
+                                                       TAG_END());
                        }
                }
                break;
index 6053cd1903f301b6c2944071865fe7442af16e18..bc77f8203c175c873b64b1c0b729af6ec50143d0 100644 (file)
@@ -836,6 +836,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
        }
 
        nua_invite(tech_pvt->nh,
+                          NUTAG_AUTOANSWER(0),
                           NUTAG_SESSION_TIMER(session_timeout),
                           TAG_IF(!switch_strlen_zero(tech_pvt->rpid), SIPTAG_HEADER_STR(tech_pvt->rpid)),
                           TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)),
@@ -1069,6 +1070,10 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
        switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
        tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
 
+       if (switch_rtp_ready(tech_pvt->rtp_session)) {
+               switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt);
+       }
+
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1428,20 +1433,39 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                        
                greed:
                        x = 0;
+
+                       //xxxxxx
+                       if (tech_pvt->rm_encoding) {
+                               for (map = m->m_rtpmaps; map; map = map->rm_next) {
+                                       if (map->rm_pt < 96) {
+                                               match = (map->rm_pt == tech_pvt->pt) ? 1 : 0;
+                                       } else {
+                                               match = strcasecmp(switch_str_nil(map->rm_encoding), tech_pvt->iananame) ? 0 : 1;
+                                       }
+                               
+                                       if (match) {
+                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec is still good, let's keep it\n");
+                                               goto end;
+                                       }
+                               }
+                       }
+
+
+
                        for (map = m->m_rtpmaps; map; map = map->rm_next) {
                                int32_t i;
                                const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
                                const char *rm_encoding;
                                
                                if (x++ < skip) {
-                                       printf("skip %s\n", map->rm_encoding);
+                                       //printf("skip %s\n", map->rm_encoding);
                                        continue;
                                }
 
                                if (!(rm_encoding = map->rm_encoding)) {
                                        rm_encoding = "";
                                }
-
+                               
                                if (!te && !strcasecmp(rm_encoding, "telephone-event")) {
                                        te = tech_pvt->te = (switch_payload_t) map->rm_pt;
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set 2833 dtmf payload to %u\n", te);
@@ -1632,6 +1656,8 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                }
        }
 
+ end:
+
        switch_set_flag_locked(tech_pvt, TFLAG_SDP);
 
        return match;