]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3688 some more general changes during proxy media
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 28 Nov 2011 19:38:00 +0000 (13:38 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 28 Nov 2011 19:38:05 +0000 (13:38 -0600)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia.c
src/switch_ivr_bridge.c
src/switch_ivr_originate.c

index 2f9958a33554267831a314438f0c276a669a96c5..52c2b3cb542e098eed6cd04aede8237b088e146f 100644 (file)
@@ -1796,7 +1796,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                        }
 
                        sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
-                       switch_channel_set_flag(channel, CF_REQ_MEDIA);
+
+                       if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+                               switch_channel_set_flag(channel, CF_REQ_MEDIA);
+                       }
                        sofia_glue_do_invite(session);
                }
                break;
@@ -1857,7 +1860,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
 
                        sofia_glue_set_image_sdp(tech_pvt, t38_options, msg->numeric_arg);
 
-                       switch_channel_set_flag(channel, CF_REQ_MEDIA);
+                       if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+                               switch_channel_set_flag(channel, CF_REQ_MEDIA);
+                       }
                        sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
                        sofia_glue_do_invite(session);
                }
@@ -1895,7 +1900,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                        sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
 
                        if (send_invite) {
-                               switch_channel_set_flag(channel, CF_REQ_MEDIA);
+                               if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+                                       switch_channel_set_flag(channel, CF_REQ_MEDIA);
+                               }
                                sofia_glue_do_invite(session);
                        } else {
                                status = SWITCH_STATUS_FALSE;
index 16ff599d50fb28b480b47ec40407d971766fe9b1..b00913bd1ccc9d6f37c5a1485aa1d181e274e494 100644 (file)
@@ -1312,10 +1312,6 @@ void sofia_event_callback(nua_event_t event,
 {
        sofia_dispatch_event_t *de;
 
-       if (event == nua_r_invite && status >= 900) {
-               return;
-       }
-
 
        switch_mutex_lock(profile->flag_mutex);
        profile->queued_events++;
@@ -4615,6 +4611,14 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
                switch_caller_profile_t *caller_profile = NULL;
                int has_t38 = 0;
 
+               switch_channel_clear_flag(channel, CF_REQ_MEDIA);
+
+               if (status >= 900) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s status %d received.\n", 
+                                                         switch_channel_get_name(channel), status);
+                       return;
+               }
+
                sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
 
                switch_channel_set_variable_printf(channel, "sip_local_network_addr", "%s", profile->extsipip ? profile->extsipip : profile->sipip);
@@ -4628,8 +4632,6 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
                        caller_profile->network_addr = switch_core_strdup(caller_profile->pool, network_ip);
                }
 
-               switch_channel_clear_flag(channel, CF_REQ_MEDIA);
-
                tech_pvt->last_sdp_str = NULL;
                if (!sofia_use_soa(tech_pvt) && sip->sip_payload && sip->sip_payload->pl_data) {
                        tech_pvt->last_sdp_str = switch_core_session_strdup(session, sip->sip_payload->pl_data);
index 88b3f0f58dec3d1e3b2e686ac1756344041048f7..c2ad565cdb2e29c16fb3778ee8a287c4a86885d6 100644 (file)
@@ -663,7 +663,11 @@ static switch_status_t audio_bridge_on_exchange_media(switch_core_session_t *ses
                        if (switch_channel_test_flag(channel, CF_INTERCEPT)) {
                                switch_channel_hangup(channel, SWITCH_CAUSE_PICKED_OFF);
                        } else {
-                               switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                               if (!switch_channel_test_flag(channel, CF_ANSWERED)) {
+                                       switch_channel_hangup(channel, SWITCH_CAUSE_ORIGINATOR_CANCEL);
+                               } else {
+                                       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                               }
                        }
                }
        }
@@ -1175,10 +1179,25 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                switch_channel_test_flag(peer_channel, CF_RING_READY)) {
                const char *app, *data;
                
+               if (switch_channel_get_state(peer_channel) == CS_CONSUME_MEDIA) {
+                       switch_channel_set_state(peer_channel, CS_RESET);
+                       switch_channel_wait_for_state(peer_channel, caller_channel, CS_RESET);
+               }
+
+               if (!switch_channel_ready(caller_channel)) {
+                       switch_call_cause_t cause = switch_channel_get_cause(caller_channel);
+
+                       if (cause) {
+                               switch_channel_hangup(peer_channel, cause);
+                               goto done;
+                       }
+               }
+
+
                switch_channel_set_state(peer_channel, CS_CONSUME_MEDIA);
 
                switch_channel_set_variable(peer_channel, "call_uuid", switch_core_session_get_uuid(session));
-
+               
                if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session));
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", switch_core_session_get_uuid(peer_session));
index 71cdfacde545c2aaafcd2ad0f73f68e556f787e3..aeb41e5e43ede1fa02e99c8fb59c87fdf27f7402 100644 (file)
@@ -3510,6 +3510,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
        if (*bleg) {
                switch_channel_t *bchan = switch_core_session_get_channel(*bleg);
 
+               if (switch_channel_get_state(bchan) == CS_CONSUME_MEDIA) {
+                       switch_channel_set_state(bchan, CS_RESET);
+                       switch_channel_wait_for_state(bchan, caller_channel, CS_RESET);
+               }
+
                if (session && caller_channel) {
                        switch_caller_profile_t *cloned_profile, *peer_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(*bleg));