]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
port over revovery code
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 24 Dec 2012 03:20:03 +0000 (21:20 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Apr 2013 02:27:16 +0000 (21:27 -0500)
src/include/switch_core_media.h
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_media.c
src/switch_core_media.c

index 47d5606531e5e24e99e990ad21cc98983663127c..f8c5cf8f2eeb78ce72a6f4d1ff92d6c6490ad83f 100644 (file)
@@ -189,7 +189,7 @@ SWITCH_DECLARE(const char *) switch_core_media_get_zrtp_hash(switch_core_session
 SWITCH_DECLARE(void) switch_core_media_pass_zrtp_hash2(switch_core_session_t *aleg_session, switch_core_session_t *bleg_session);
 SWITCH_DECLARE(int) switch_core_media_toggle_hold(switch_core_session_t *session, int sendonly);
 SWITCH_DECLARE(void) switch_core_media_copy_t38_options(switch_t38_options_t *t38_options, switch_core_session_t *session);
-SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed, int reinvite, int codec_flags, switch_payload_t default_te);
+SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed);
 SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_codec(switch_core_session_t *session, int force);
 SWITCH_DECLARE(switch_status_t) switch_core_media_set_codec(switch_core_session_t *session, int force, uint32_t codec_flags);
 SWITCH_DECLARE(void) switch_core_media_check_video_codecs(switch_core_session_t *session);
@@ -240,6 +240,7 @@ SWITCH_DECLARE(void) switch_core_media_set_sdp_codec_string(switch_core_session_
 SWITCH_DECLARE(void) switch_core_media_reset_autofix_timing(switch_core_session_t *session, switch_media_type_t type);
 SWITCH_DECLARE(void) switch_core_media_check_outgoing_proxy(switch_core_session_t *session);
 SWITCH_DECLARE(switch_status_t) switch_core_media_codec_chosen(switch_core_session_t *session, switch_media_type_t media);
+SWITCH_DECLARE (void) switch_core_media_recover_session(switch_core_session_t *session);
 
 SWITCH_END_EXTERN_C
 #endif
index a9b6568f2deb7718e7b056bc24046db4a6bd54e2..edda7ccecc5f5250ca64a075db9a315dc0ae8992 100644 (file)
@@ -1782,12 +1782,6 @@ void sofia_glue_del_profile(sofia_profile_t *profile)
        switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 }
 
-#if 1
-int sofia_recover_callback(switch_core_session_t *session) 
-{
-       return -1;
-}
-#else 
 int sofia_recover_callback(switch_core_session_t *session) 
 {
 
@@ -1818,7 +1812,7 @@ int sofia_recover_callback(switch_core_session_t *session)
        switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 
        tech_pvt->mparams.remote_ip = (char *) switch_channel_get_variable(channel, "sip_network_ip");
-       tech_pvt->remote_port = atoi(switch_str_nil(switch_channel_get_variable(channel, "sip_network_port")));
+       tech_pvt->mparams.remote_port = atoi(switch_str_nil(switch_channel_get_variable(channel, "sip_network_port")));
        tech_pvt->caller_profile = switch_channel_get_caller_profile(channel);
 
        if ((tmp = switch_channel_get_variable(tech_pvt->channel, "sip_2833_send_payload"))) {
@@ -1881,7 +1875,7 @@ int sofia_recover_callback(switch_core_session_t *session)
        }
 
        if ((tmp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE))) {
-               tech_pvt->remote_sdp_str = switch_core_session_strdup(session, tmp);
+               tech_pvt->mparams.remote_sdp_str = switch_core_session_strdup(session, tmp);
        }
 
        switch_channel_set_variable(channel, "sip_invite_call_id", switch_channel_get_variable(channel, "sip_call_id"));
@@ -1894,11 +1888,6 @@ int sofia_recover_callback(switch_core_session_t *session)
        }
 
        if (session) {
-               const char *ip = switch_channel_get_variable(channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
-               const char *a_ip = switch_channel_get_variable(channel, SWITCH_ADVERTISED_MEDIA_IP_VARIABLE);
-               const char *port = switch_channel_get_variable(channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
-               const char *r_ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
-               const char *r_port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
                const char *use_uuid;
 
                switch_channel_set_flag(channel, CF_RECOVERING);
@@ -1912,113 +1901,17 @@ int sofia_recover_callback(switch_core_session_t *session)
                                                                  switch_channel_get_name(channel), use_uuid);
                        }
                }
-
-               if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && ip && port) {
-                       const char *tmp;
-                       tech_pvt->iananame = tech_pvt->rm_encoding = (char *) switch_channel_get_variable(channel, "sip_use_codec_name");
-                       tech_pvt->rm_fmtp = (char *) switch_channel_get_variable(channel, "sip_use_codec_fmtp");
-
-                       if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_rate"))) {
-                               tech_pvt->rm_rate = atoi(tmp);
-                       }
-
-                       if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_ptime"))) {
-                               tech_pvt->codec_ms = atoi(tmp);
-                       }
-
-                       if ((tmp = switch_channel_get_variable(channel, "sip_use_pt"))) {
-                               tech_pvt->pt = tech_pvt->agreed_pt = (switch_payload_t)atoi(tmp);
-                       }
-                       
-                       switch_core_media_set_codec(tech_pvt->session, 1, tech_pvt->profile->codec_flags);
-
-                       tech_pvt->mparams.adv_sdp_audio_ip = tech_pvt->extrtpip = (char *) ip;
-                       tech_pvt->adv_sdp_audio_port = tech_pvt->local_sdp_audio_port = (switch_port_t)atoi(port);
-
-                       if (!zstr(ip)) {
-                               tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(session, ip);
-                               tech_pvt->rtpip = tech_pvt->local_sdp_audio_ip;
-                       }
-
-                       if (!zstr(a_ip)) {
-                               tech_pvt->mparams.adv_sdp_audio_ip = switch_core_session_strdup(session, a_ip);
-                       }
-
-                       if (r_ip && r_port) {
-                               tech_pvt->remote_sdp_audio_ip = (char *) r_ip;
-                               tech_pvt->remote_sdp_audio_port = (switch_port_t)atoi(r_port);
-                       }
-
-                       if (switch_channel_test_flag(channel, CF_VIDEO)) {
-                               if ((tmp = switch_channel_get_variable(channel, "sip_use_video_pt"))) {
-                                       tech_pvt->video_pt = tech_pvt->video_agreed_pt = (switch_payload_t)atoi(tmp);
-                               }
-
-
-                               tech_pvt->video_rm_encoding = (char *) switch_channel_get_variable(channel, "sip_use_video_codec_name");
-                               tech_pvt->video_rm_fmtp = (char *) switch_channel_get_variable(channel, "sip_use_video_codec_fmtp");
-
-                               ip = switch_channel_get_variable(channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE);
-                               port = switch_channel_get_variable(channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE);
-                               r_ip = switch_channel_get_variable(channel, SWITCH_REMOTE_VIDEO_IP_VARIABLE);
-                               r_port = switch_channel_get_variable(channel, SWITCH_REMOTE_VIDEO_PORT_VARIABLE);
-
-                               switch_channel_set_flag(tech_pvt->channel, CF_VIDEO_POSSIBLE);
-
-                               if ((tmp = switch_channel_get_variable(channel, "sip_use_video_codec_rate"))) {
-                                       tech_pvt->video_rm_rate = atoi(tmp);
-                               }
-
-                               if ((tmp = switch_channel_get_variable(channel, "sip_use_video_codec_ptime"))) {
-                                       tech_pvt->video_codec_ms = atoi(tmp);
-                               }
-
-                               tech_pvt->adv_sdp_video_port = tech_pvt->local_sdp_video_port = (switch_port_t)atoi(port);
-
-                               if (r_ip && r_port) {
-                                       tech_pvt->remote_sdp_video_ip = (char *) r_ip;
-                                       tech_pvt->remote_sdp_video_port = (switch_port_t)atoi(r_port);
-                               }
-                               //sofia_media_tech_set_video_codec(tech_pvt, 1);
-                       }
-
-                       switch_core_media_gen_local_sdp(session, NULL, 0, NULL, 1);
-
-                       if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                               goto end;
-                       }
-                       
-                       if (switch_core_media_ready(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO)) {
-                               if ((tmp = switch_channel_get_variable(channel, "sip_audio_recv_pt"))) {
-                                       switch_core_media_set_recv_pt(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, (switch_payload_t)atoi(tmp));
-                               }
-                       }
-
-                       if (switch_core_media_ready(tech_pvt->session, SWITCH_MEDIA_TYPE_VIDEO)) {
-                               if ((tmp = switch_channel_get_variable(channel, "sip_video_recv_pt"))) {
-                                       switch_core_media_set_recv_pt(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, (switch_payload_t)atoi(tmp));
-                               }
-                       }
-
-                       if (tech_pvt->te) {
-                               switch_core_media_set_telephony_event(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, tech_pvt->te);
-                       }
-
-                       if (tech_pvt->recv_te) {
-                               switch_core_media_set_telephony_recv_event(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, tech_pvt->recv_te);
-                       }
-
-               }
+       
+               switch_core_media_recover_session(session);
+       
        }
 
        r++;
 
- end:
-
        return r;
 
 }
-#endif
+
 
 
 int sofia_glue_recover(switch_bool_t flush)
index 048cdf70e13121ad8d7f6ffc468dcb9c4c5b46ff..2d8cc97e258827b1095e41e2ff6c97d40fb800e3 100644 (file)
@@ -39,8 +39,7 @@ uint8_t sofia_media_negotiate_sdp(switch_core_session_t *session, const char *r_
        uint8_t t, p = 0;
        private_object_t *tech_pvt = switch_core_session_get_private(session);
 
-       if ((t = switch_core_media_negotiate_sdp(session, r_sdp, &p, switch_channel_test_flag(tech_pvt->channel, CF_REINVITE), 
-                                                                          tech_pvt->profile->codec_flags, tech_pvt->profile->te))) {
+       if ((t = switch_core_media_negotiate_sdp(session, r_sdp, &p))) {
                sofia_set_flag_locked(tech_pvt, TFLAG_SDP);
        }
 
index ab5532d86d96ea2da9be8f4dd087d8835fba6ac0..6fb16745768d677e5985f742dc03e73fe9439f13 100644 (file)
@@ -61,7 +61,7 @@ typedef struct secure_settings_s {
        char *remote_crypto_key;
 } switch_secure_settings_t;
 
-typedef struct codec_params_s {//x:tmp
+typedef struct codec_params_s {
        char *rm_encoding;
        char *iananame;
        switch_payload_t pt;
@@ -382,6 +382,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_process_t38_passthru(switch_co
        switch_rtp_engine_t *a_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -433,6 +435,8 @@ SWITCH_DECLARE(const char *)switch_core_media_get_codec_string(switch_core_sessi
        const char *preferred = NULL, *fallback = NULL;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                preferred = "PCMU";
                fallback = "PCMU";
@@ -824,6 +828,8 @@ SWITCH_DECLARE(void) switch_media_handle_destroy(switch_core_session_t *session)
        switch_media_handle_t *smh;
        switch_rtp_engine_t *a_engine, *v_engine;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -948,6 +954,8 @@ SWITCH_DECLARE(void) switch_core_media_prepare_codecs(switch_core_session_t *ses
        const char *ocodec = NULL;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -1019,6 +1027,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session
        switch_status_t status;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -1302,6 +1312,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_write_frame(switch_core_sessio
        switch_rtp_engine_t *engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -1386,6 +1398,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_get_offered_pt(switch_core_ses
        int i = 0;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -1412,6 +1426,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_codec(switch_core_se
        switch_media_handle_t *smh;
        switch_rtp_engine_t *v_engine;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -1519,6 +1535,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_codec(switch_core_session_
        switch_media_handle_t *smh;
        switch_rtp_engine_t *a_engine;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -1661,6 +1679,8 @@ SWITCH_DECLARE(void) switch_core_media_check_video_codecs(switch_core_session_t
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -1683,8 +1703,7 @@ SWITCH_DECLARE(void) switch_core_media_check_video_codecs(switch_core_session_t
 
 
 //?
-SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed, 
-                                                                                                               int reinvite, int codec_flags, switch_payload_t default_te)
+SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed)
 {
        uint8_t match = 0;
        switch_payload_t best_te = 0, te = 0, cng_pt = 0;
@@ -1707,6 +1726,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return 0;
        }
@@ -2260,7 +2281,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
                                }
                                
                                if (match) {
-                                       if (switch_core_media_set_codec(session, 1, codec_flags) == SWITCH_STATUS_SUCCESS) {
+                                       if (switch_core_media_set_codec(session, 1, smh->mparams->codec_flags) == SWITCH_STATUS_SUCCESS) {
                                                got_audio = 1;
                                        } else {
                                                match = 0;
@@ -2270,8 +2291,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
 
                        if (!best_te && (switch_media_handle_test_media_flag(smh, SCMF_LIBERAL_DTMF) || switch_channel_test_flag(session->channel, CF_LIBERAL_DTMF))) {
                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, 
-                                                                 "No 2833 in SDP. Liberal DTMF mode adding %d as telephone-event.\n", default_te);
-                               best_te = default_te;
+                                                                 "No 2833 in SDP. Liberal DTMF mode adding %d as telephone-event.\n", smh->mparams->te);
+                               best_te = smh->mparams->te;
                        }
 
                        if (best_te) {
@@ -2453,6 +2474,8 @@ SWITCH_DECLARE(int) switch_core_media_toggle_hold(switch_core_session_t *session
        switch_rtp_engine_t *a_engine;//, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return 0;
        }
@@ -2563,6 +2586,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_proxy_remote_addr(switch_core_
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -2745,6 +2770,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_ext_address_lookup(switch_core
        switch_media_handle_t *smh;
        switch_memory_pool_t *pool = switch_core_session_get_pool(session);
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -2817,6 +2844,8 @@ SWITCH_DECLARE(void) switch_core_media_reset_autofix_timing(switch_core_session_
        switch_rtp_engine_t *engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -2840,6 +2869,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_choose_port(switch_core_sessio
        const char *tstr = switch_media_type2str(type);
        char vname[128] = "";
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -2924,6 +2955,8 @@ SWITCH_DECLARE(void) switch_core_media_deactivate_rtp(switch_core_session_t *ses
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -2981,6 +3014,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -3674,6 +3709,8 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
        const char *local_sdp_audio_zrtp_hash;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -3835,6 +3872,8 @@ SWITCH_DECLARE(void) switch_core_media_check_dtmf_type(switch_core_session_t *se
        const char *val;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -3914,6 +3953,8 @@ SWITCH_DECLARE(void)switch_core_media_set_local_sdp(switch_core_session_t *sessi
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -3956,6 +3997,8 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -4380,6 +4423,8 @@ SWITCH_DECLARE(void) switch_core_media_absorb_sdp(switch_core_session_t *session
        switch_rtp_engine_t *a_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -4443,6 +4488,8 @@ SWITCH_DECLARE(void) switch_core_media_set_image_sdp(switch_core_session_t *sess
        switch_media_handle_t *smh;
        switch_rtp_engine_t *a_engine;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -4580,6 +4627,8 @@ SWITCH_DECLARE(void) switch_core_media_patch_sdp(switch_core_session_t *session)
        switch_media_handle_t *smh;
        switch_rtp_engine_t *a_engine, *v_engine;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -4859,6 +4908,8 @@ SWITCH_DECLARE(void) switch_core_media_start_udptl(switch_core_session_t *sessio
        switch_media_handle_t *smh;
        switch_rtp_engine_t *a_engine;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -4915,6 +4966,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_status_t status = SWITCH_STATUS_SUCCESS;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -5283,6 +5336,8 @@ SWITCH_DECLARE(void) switch_core_media_break(switch_core_session_t *session, swi
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5297,6 +5352,8 @@ SWITCH_DECLARE(void) switch_core_media_kill_socket(switch_core_session_t *sessio
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5311,6 +5368,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_queue_rfc2833(switch_core_sess
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -5327,6 +5386,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_queue_rfc2833_in(switch_core_s
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -5343,6 +5404,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_ready(switch_core_session_t *session,
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return 0;
        }       
@@ -5355,6 +5418,8 @@ SWITCH_DECLARE(void) switch_core_media_set_rtp_flag(switch_core_session_t *sessi
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5369,6 +5434,8 @@ SWITCH_DECLARE(void) switch_core_media_clear_rtp_flag(switch_core_session_t *ses
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5383,6 +5450,8 @@ SWITCH_DECLARE(void) switch_core_media_set_recv_pt(switch_core_session_t *sessio
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5397,6 +5466,8 @@ SWITCH_DECLARE(void) switch_core_media_set_telephony_event(switch_core_session_t
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }       
@@ -5411,6 +5482,8 @@ SWITCH_DECLARE(void) switch_core_media_set_telephony_recv_event(switch_core_sess
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5425,6 +5498,8 @@ SWITCH_DECLARE(switch_rtp_stats_t *) switch_core_media_get_stats(switch_core_ses
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return NULL;
        }
@@ -5441,6 +5516,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_udptl_mode(switch_core_session
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -5457,6 +5534,8 @@ SWITCH_DECLARE(stfu_instance_t *) switch_core_media_get_jb(switch_core_session_t
 {
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return NULL;
        }
@@ -5476,6 +5555,8 @@ SWITCH_DECLARE(void) switch_core_media_set_sdp_codec_string(switch_core_session_
        sdp_session_t *sdp;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5564,6 +5645,8 @@ SWITCH_DECLARE(void) switch_core_media_set_r_sdp_codec_string(switch_core_sessio
        const char *var;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5736,6 +5819,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_codec_chosen(switch_core_sessi
        switch_rtp_engine_t *engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return SWITCH_STATUS_FALSE;
        }
@@ -5756,6 +5841,8 @@ SWITCH_DECLARE(void) switch_core_media_check_outgoing_proxy(switch_core_session_
        switch_rtp_engine_t *a_engine, *v_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5793,6 +5880,8 @@ SWITCH_DECLARE(void) switch_core_media_proxy_codec(switch_core_session_t *sessio
        switch_rtp_engine_t *a_engine;
        switch_media_handle_t *smh;
 
+       switch_assert(session);
+
        if (!(smh = session->media_handle)) {
                return;
        }
@@ -5851,7 +5940,125 @@ SWITCH_DECLARE(void) switch_core_media_proxy_codec(switch_core_session_t *sessio
 
 }
 
+SWITCH_DECLARE (void) switch_core_media_recover_session(switch_core_session_t *session)
+{
+       const char *ip;
+       const char *port;
+       const char *a_ip;
+       const char *r_ip;
+       const char *r_port;
+       const char *tmp;        
+       switch_rtp_engine_t *a_engine, *v_engine;
+       switch_media_handle_t *smh;
+
+       switch_assert(session);
+
+       if (!(smh = session->media_handle)) {
+               return;
+       }
+       
+       ip = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
+       port = switch_channel_get_variable(session->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
+
+
+       if (switch_channel_test_flag(session->channel, CF_PROXY_MODE)  || !(ip && port)) {
+               return;
+       } else {
+               a_ip = switch_channel_get_variable(session->channel, SWITCH_ADVERTISED_MEDIA_IP_VARIABLE);
+               r_ip = switch_channel_get_variable(session->channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
+               r_port = switch_channel_get_variable(session->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
+       }
+
+       a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
+       v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
+
+
+       a_engine->codec_params.iananame = a_engine->codec_params.rm_encoding = (char *) switch_channel_get_variable(session->channel, "sip_use_codec_name");
+       a_engine->codec_params.rm_fmtp = (char *) switch_channel_get_variable(session->channel, "sip_use_codec_fmtp");
+
+       if ((tmp = switch_channel_get_variable(session->channel, "sip_use_codec_rate"))) {
+               a_engine->codec_params.rm_rate = atoi(tmp);
+       }
+
+       if ((tmp = switch_channel_get_variable(session->channel, "sip_use_codec_ptime"))) {
+               a_engine->codec_params.codec_ms = atoi(tmp);
+       }
+
+       if ((tmp = switch_channel_get_variable(session->channel, "sip_use_pt"))) {
+               a_engine->codec_params.pt = a_engine->codec_params.agreed_pt = (switch_payload_t)atoi(tmp);
+       }
+                       
+       switch_core_media_set_codec(session, 1, smh->mparams->codec_flags);
+
+       a_engine->codec_params.adv_sdp_ip = smh->mparams->extrtpip = (char *) ip;
+       a_engine->codec_params.adv_sdp_port = a_engine->codec_params.local_sdp_port = (switch_port_t)atoi(port);
+
+       if (!zstr(ip)) {
+               a_engine->codec_params.local_sdp_ip = switch_core_session_strdup(session, ip);
+               smh->mparams->rtpip = a_engine->codec_params.local_sdp_ip;
+       }
+
+       if (!zstr(a_ip)) {
+               a_engine->codec_params.adv_sdp_ip = switch_core_session_strdup(session, a_ip);
+       }
+
+       if (r_ip && r_port) {
+               a_engine->codec_params.remote_sdp_ip = (char *) r_ip;
+               a_engine->codec_params.remote_sdp_port = (switch_port_t)atoi(r_port);
+       }
+
+       if (switch_channel_test_flag(session->channel, CF_VIDEO)) {
+               if ((tmp = switch_channel_get_variable(session->channel, "sip_use_video_pt"))) {
+                       v_engine->codec_params.pt = v_engine->codec_params.agreed_pt = (switch_payload_t)atoi(tmp);
+               }
+
+
+               v_engine->codec_params.rm_encoding = (char *) switch_channel_get_variable(session->channel, "sip_use_video_codec_name");
+               v_engine->codec_params.rm_fmtp = (char *) switch_channel_get_variable(session->channel, "sip_use_video_codec_fmtp");
+
+               ip = switch_channel_get_variable(session->channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE);
+               port = switch_channel_get_variable(session->channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE);
+               r_ip = switch_channel_get_variable(session->channel, SWITCH_REMOTE_VIDEO_IP_VARIABLE);
+               r_port = switch_channel_get_variable(session->channel, SWITCH_REMOTE_VIDEO_PORT_VARIABLE);
+
+               switch_channel_set_flag(session->channel, CF_VIDEO_POSSIBLE);
+
+               if ((tmp = switch_channel_get_variable(session->channel, "sip_use_video_codec_rate"))) {
+                       v_engine->codec_params.rm_rate = atoi(tmp);
+               }
+
+               if ((tmp = switch_channel_get_variable(session->channel, "sip_use_video_codec_ptime"))) {
+                       v_engine->codec_params.codec_ms = atoi(tmp);
+               }
+
+               v_engine->codec_params.adv_sdp_port = v_engine->codec_params.local_sdp_port = (switch_port_t)atoi(port);
+
+               if (r_ip && r_port) {
+                       v_engine->codec_params.remote_sdp_ip = (char *) r_ip;
+                       v_engine->codec_params.remote_sdp_port = (switch_port_t)atoi(r_port);
+               }
+               //sofia_media_tech_set_video_codec(tech_pvt, 1);
+       }
 
+       switch_core_media_gen_local_sdp(session, NULL, 0, NULL, 1);
+
+       if (switch_core_media_activate_rtp(session) != SWITCH_STATUS_SUCCESS) {
+               return;
+       }
+                       
+       if (switch_core_media_ready(session, SWITCH_MEDIA_TYPE_AUDIO)) {
+               if ((tmp = switch_channel_get_variable(session->channel, "sip_audio_recv_pt"))) {
+                       switch_core_media_set_recv_pt(session, SWITCH_MEDIA_TYPE_AUDIO, (switch_payload_t)atoi(tmp));
+               }
+       }
+
+       if (switch_core_media_ready(session, SWITCH_MEDIA_TYPE_VIDEO)) {
+               if ((tmp = switch_channel_get_variable(session->channel, "sip_video_recv_pt"))) {
+                       switch_core_media_set_recv_pt(session, SWITCH_MEDIA_TYPE_AUDIO, (switch_payload_t)atoi(tmp));
+               }
+       }
+
+}
 
 
 /* For Emacs: