]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more crazy black magic
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 19 Sep 2008 19:58:01 +0000 (19:58 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 19 Sep 2008 19:58:01 +0000 (19:58 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9603 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/switch_ivr.c
src/switch_ivr_bridge.c
src/switch_rtp.c

index 23227e1d54bb48af11d82d04b014a88080a62462..832b338d24d02dea18a327f64dee7eaf77fb81fe 100644 (file)
@@ -291,7 +291,8 @@ typedef enum {
        SMF_ECHO_BLEG = (1 << 2),
        SMF_FORCE = (1 << 3),
        SMF_LOOP = (1 << 4),
-       SMF_HOLD_BLEG = (1 << 5)
+       SMF_HOLD_BLEG = (1 << 5),
+       SMF_IMMEDIATE = (1 << 6)
 } switch_media_flag_enum_t;
 typedef uint32_t switch_media_flag_t;
 
index e719fa261ff03fc5c2bab9049434b4c0d8ee433f..4c9177c6532a5fb0a2d76149cd65753baf07bd4e 100644 (file)
@@ -498,6 +498,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
                }
        }
 
+       if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+               return SWITCH_STATUS_FALSE;
+       }
+       
        read_codec = switch_core_session_get_read_codec(session);
 
        if (!read_codec || !read_codec->implementation) {
@@ -906,9 +910,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_
                if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
                        status = SWITCH_STATUS_SUCCESS;
                        switch_core_session_receive_message(session, &msg);
-
-                       switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
-                       switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
+                       
+                       if (!(flags & SMF_IMMEDIATE)) {
+                               switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
+                               switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
+                       }
 
                        if ((flags & SMF_REBRIDGE)
                                && (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
index 4b4a2a7990395b0710570a6733d8cc8492d69c34..c6c1f43a37dcbaa52c41a4cca9ce9471964253ee 100644 (file)
@@ -651,16 +651,21 @@ static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session)
        if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
                && (other_session = switch_core_session_locate(uuid))) {
                switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+               const char *sbv = switch_channel_get_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE);
+               
+               if (!switch_strlen_zero(sbv) && !strcmp(sbv, switch_core_session_get_uuid(session))) {
+                       
+                       switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
 
-               switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
-               switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
-
-               switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
-               switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
+                       switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
+                       switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
 
-               if (switch_channel_get_state(other_channel) < CS_HANGUP) {
-                       switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
+                       if (switch_channel_get_state(other_channel) < CS_HANGUP) {
+                               switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
+                       }
                }
+               
+               switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
 
                switch_core_session_rwunlock(other_session);
        }
@@ -725,13 +730,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
                switch_channel_event_set_data(caller_channel, event);
                switch_event_fire(&event);
        }
-
+       
        switch_channel_set_state_flag(caller_channel, CF_TRANSFER);
        switch_channel_set_state_flag(peer_channel, CF_TRANSFER);
 
-
        switch_channel_set_state(caller_channel, CS_HIBERNATE);
        switch_channel_set_state(peer_channel, CS_HIBERNATE);
+       
+       if (switch_channel_test_flag(caller_channel, CF_BRIDGED)) {
+               switch_channel_set_flag(caller_channel, CF_TRANSFER);
+               switch_channel_set_flag(peer_channel, CF_TRANSFER);
+       }
 
        return SWITCH_STATUS_SUCCESS;
 }
@@ -901,6 +910,33 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
        return status;
 }
 
+static void cleanup_proxy_mode(switch_core_session_t *session)
+{
+       switch_core_session_t *sbsession;
+
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+
+
+       if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+               const char *sbv = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
+               
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Restore media to %s\n", switch_channel_get_name(channel));
+               switch_ivr_media(switch_core_session_get_uuid(session), SMF_IMMEDIATE);
+
+               if (!switch_strlen_zero(sbv) && (sbsession = switch_core_session_locate(sbv))) {
+                       switch_channel_t *sbchannel = switch_core_session_get_channel(sbsession);
+                       switch_channel_hangup(sbchannel, SWITCH_CAUSE_ATTENDED_TRANSFER);
+                       switch_core_session_rwunlock(sbsession);
+               }
+       }
+
+       switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
+       switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
+       switch_channel_set_variable(channel, SWITCH_BRIDGE_UUID_VARIABLE, NULL);
+
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uuid, const char *originatee_uuid)
 {
        switch_core_session_t *originator_session, *originatee_session, *swap_session;
@@ -939,6 +975,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
                                }
                        }
 
+                       cleanup_proxy_mode(originator_session);
+                       cleanup_proxy_mode(originatee_session);
+                       
                        /* override transmit state for originator_channel to bridge to originatee_channel 
                         * install pointer to originatee_session into originator_channel
                         * set CF_TRANSFER on both channels and change state to CS_SOFT_EXECUTE to
@@ -961,7 +1000,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
                        switch_channel_set_variable(originatee_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(originator_session));
                        switch_channel_set_variable(originatee_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(originator_session));
 
-
+                       
                        originator_cp = switch_channel_get_caller_profile(originator_channel);
                        originatee_cp = switch_channel_get_caller_profile(originatee_channel);
 
index 024525fd8f34982cfe9b333d7d73dc4c9f742f17..21503f76f497e0ece445bce93e774a78f72ca280 100644 (file)
@@ -1256,7 +1256,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
                        ret = (int) bytes;
                        goto end;
                }
-
+               
                if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
                        const char *tx_host;
                        const char *old_host;