]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix issue in monitor_early_media_fail issue
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 25 Feb 2009 03:41:18 +0000 (03:41 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 25 Feb 2009 03:41:18 +0000 (03:41 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12271 d0543943-73ff-0310-b7d9-9358b9ac24b2

17 files changed:
src/include/switch_channel.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_dingaling/mod_dingaling.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/event_handlers/mod_erlang_event/mod_erlang_event.c
src/mod/event_handlers/mod_event_socket/mod_event_socket.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_channel.c
src/switch_core_io.c
src/switch_core_rwlock.c
src/switch_core_session.c
src/switch_core_state_machine.c
src/switch_ivr_async.c
src/switch_ivr_bridge.c
src/switch_ivr_originate.c

index eb0290bb4a206978e163e95b3890d0f957aca7df..4824a0c8a33808b802ce76a1ad69f77191e477e8 100644 (file)
@@ -78,7 +78,8 @@ SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_
 
 #define switch_channel_ready(_channel) switch_channel_test_ready(_channel, SWITCH_FALSE)
 #define switch_channel_media_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE)
-
+#define switch_channel_up(_channel) (switch_channel_get_state(_channel) < CS_HANGUP)
+#define switch_channel_down(_channel) (switch_channel_get_state(_channel) >= CS_HANGUP)
 
 SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state);
 SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel, 
index 18b05af868a9ce0a1e73949dfb7749de64e6974e..1a1df50fcf538b8f6a7bff7cdf2493f297b31ad6 100644 (file)
@@ -1532,7 +1532,7 @@ SWITCH_STANDARD_APP(att_xfer_function)
        switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE);
        switch_channel_clear_flag(channel, CF_INNER_BRIDGE);
 
-       if (!switch_channel_get_state(peer_channel) >= CS_HANGUP) {
+       if (!switch_channel_down(peer_channel)) {
                switch_core_session_rwunlock(peer_session);
                goto end;
        }
index f8435cf4ab278d39912728be1204b6d51ba3ac8d..c9a5eed172aabdc567c26aecf6b7e832c8301e53 100644 (file)
@@ -1091,7 +1091,7 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
                now = switch_micro_time_now();
                elapsed = (unsigned int) ((now - started) / 1000);
 
-               if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
+               if (switch_channel_down(channel) || switch_test_flag(tech_pvt, TFLAG_BYE)) {
                        goto out;
                }
 
@@ -1119,7 +1119,7 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
                switch_cond_next();
        }
 
-       if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
+       if (switch_channel_down(channel) || switch_test_flag(tech_pvt, TFLAG_BYE)) {
                goto out;
        }
 
@@ -2542,7 +2542,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
 
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using Existing session for %s\n", ldl_session_get_id(dlsession));
 
-               if (switch_channel_get_state(channel) >= CS_HANGUP) {
+               if (switch_channel_down(channel)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call %s is already over\n", switch_channel_get_name(channel));
                        status = LDL_STATUS_FALSE;
                        goto done;
index 4fb019ad3abcf6ac676adcaf18818aac74a57e45..a7e4b8d0b1dc9d6b11f892e66f968b5f4b3825fc 100644 (file)
@@ -1081,7 +1081,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
                                break;
                        case IAX_EVENT_VOICE:
                                if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen) != 0) {
-                                       if (channel && switch_channel_get_state(channel) <= CS_HANGUP) {
+                                       if (channel && switch_channel_up(channel)) {
                                                int bytes = 0, frames = 1;
 
                                                if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation) {
index df048c199a5a00459d1e498b2132aec144a8655e..6751078f007d6bd925d4afe6561fc3e292fcb841 100644 (file)
@@ -959,7 +959,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
        private_object_t *tech_pvt = switch_core_session_get_private(session);
        switch_status_t status = SWITCH_STATUS_SUCCESS;
 
-       if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) {
+       if (switch_channel_down(channel) || !tech_pvt) {
                status = SWITCH_STATUS_FALSE;
                goto end;
        }
@@ -997,7 +997,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
        /* ones that do need to lock sofia mutex */
        switch_mutex_lock(tech_pvt->sofia_mutex);
 
-       if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) {
+       if (switch_channel_down(channel) || !tech_pvt) {
                status = SWITCH_STATUS_FALSE;
                goto end_lock;
        }
index 076f5fe7861cf75dea32d833f57f6e0db9a50db3..f42f1dc8da30de757b3268254042629db52f45c3 100644 (file)
@@ -364,7 +364,7 @@ void sofia_event_callback(nua_event_t event,
        }
 
        if (session) {
-               if (channel && switch_channel_get_state(channel) >= CS_HANGUP) {
+               if (channel && switch_channel_down(channel)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n");
                        goto done;
                }
@@ -3325,7 +3325,7 @@ void *SWITCH_THREAD_FUNC nightmare_xfer_thread_run(switch_thread_t *thread, void
 
                        status = switch_ivr_originate(a_session, &tsession, &cause, nhelper->exten, timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE);
                                                        
-                       if ((switch_channel_get_state(channel_a) < CS_HANGUP)) {
+                       if ((switch_channel_up(channel_a))) {
                                
                                if (status != SWITCH_STATUS_SUCCESS || cause != SWITCH_CAUSE_SUCCESS) {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! [%s]\n", nhelper->exten);
index fb8ad359ce0b666e50393960f6727b3d171bac56..5df830820c6182e594eb923373c0f0a9e386d4d2 100644 (file)
@@ -1234,7 +1234,7 @@ SWITCH_STANDARD_APP(erlang_outbound_function)
                        switch_ivr_park(session, NULL);
 
                        /* keep app thread running for lifetime of session */
-                       if (switch_channel_get_state(switch_core_session_get_channel(session)) >= CS_HANGUP) {
+                       if (switch_channel_down(switch_core_session_get_channel(session))) {
                                while (switch_test_flag(session_element, LFLAG_SESSION_ALIVE)) {
                                        switch_yield(100000);
                                }
index 77f65776c6b940741e10565a3bce7192f789637f..aff4288c1c9e3b542054d978f22e64b6318c80e3 100644 (file)
@@ -430,7 +430,7 @@ SWITCH_STANDARD_APP(socket_function)
                listener_run(NULL, (void *) listener);
        }
 
-       if (switch_channel_get_state(channel) >= CS_HANGUP) {
+       if (switch_channel_down(channel)) {
                while (switch_test_flag(listener, LFLAG_SESSION)) {
                        switch_yield(100000);
                }
@@ -1192,7 +1192,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
                        }
                }
 
-               if (channel && switch_channel_get_state(channel) >= CS_HANGUP && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) {
+               if (channel && switch_channel_down(channel) && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) {
                        switch_set_flag_locked(listener, LFLAG_HANDLE_DISCO);
                        if (switch_test_flag(listener, LFLAG_LINGER)) {
                                char message[128] = "";
index d2e9cebc11ca89d2ed22faf630a182d358549cda..36d2c207df69a11d74020fc849bca491c45e1644 100644 (file)
@@ -2152,7 +2152,7 @@ static JSBool session_wait_for_media(JSContext * cx, JSObject * obj, uintN argc,
        saveDepth = JS_SuspendRequest(cx);
        for (;;) {
                if (((elapsed = (unsigned int) ((switch_micro_time_now() - started) / 1000)) > (switch_time_t) timeout)
-                       || switch_channel_get_state(channel) >= CS_HANGUP) {
+                       || switch_channel_down(channel)) {
                        *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
                        break;
                }
@@ -2200,7 +2200,7 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc
        saveDepth = JS_SuspendRequest(cx);
        for (;;) {
                if (((elapsed = (unsigned int) ((switch_micro_time_now() - started) / 1000)) > (switch_time_t) timeout)
-                       || switch_channel_get_state(channel) >= CS_HANGUP) {
+                       || switch_channel_down(channel)) {
                        *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
                        break;
                }
index 4ff1ebb082ebe0dc135b400f6574495df753d5ce..1d278fe087ff1dfc244d1e2444e09c783fd47c19 100644 (file)
@@ -1590,7 +1590,6 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n",
                                                  channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
                
-               switch_core_media_bug_remove_all(channel->session);
                switch_channel_set_variable(channel, "hangup_cause", switch_channel_cause2str(channel->hangup_cause));
                switch_channel_presence(channel, "unavailable", switch_channel_cause2str(channel->hangup_cause), NULL);
 
index eaf851264187d45a997f7715e1b91d3a7fe4c221..50e4627fa5b3b5e04b70d5895953b61a437613eb 100644 (file)
@@ -41,7 +41,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor
        switch_io_event_hook_video_write_frame_t *ptr;
        switch_status_t status = SWITCH_STATUS_FALSE;
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                return SWITCH_STATUS_FALSE;
        }
 
@@ -65,7 +65,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
 
        switch_assert(session != NULL);
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                return SWITCH_STATUS_FALSE;
        }
 
@@ -123,7 +123,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 
   top:
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                *frame = NULL;
                status = SWITCH_STATUS_FALSE; goto even_more_done;
        }
@@ -1066,7 +1066,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_sessio
        switch_status_t status;
        switch_dtmf_t new_dtmf;
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                return SWITCH_STATUS_FALSE;
        }
 
@@ -1096,7 +1096,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
        switch_status_t status = SWITCH_STATUS_FALSE;
        switch_dtmf_t new_dtmf;
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                return SWITCH_STATUS_FALSE;
        }
 
@@ -1144,7 +1144,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
        switch_assert(session != NULL);
 
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                return SWITCH_STATUS_FALSE;
        }
 
index 161f9d3c74ddc2bf499ddd259e1f462ef76fec33..aba781614b475f356e3b9a567f71ee8ba571ad09 100644 (file)
@@ -45,7 +45,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_sessio
        switch_status_t status = SWITCH_STATUS_FALSE;
 
        if (session->rwlock) {
-               if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_HANGUP) {
+               if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_down(session->channel)) {
                        status = SWITCH_STATUS_FALSE;
 #ifdef SWITCH_DEBUG_RWLOCKS
                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n",
index 11a0d31ae7107a2af16aceb31b4c6ae6692e5e05..b95e7740b3cf4d86d26d91c5a6009bb70c89052c 100644 (file)
@@ -91,7 +91,7 @@ SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_nam
                        const char *this_val;
                        session = (switch_core_session_t *) val;
                        if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-                               if (switch_channel_get_state(session->channel) < CS_HANGUP &&
+                               if (switch_channel_up(session->channel) &&
                                        (this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) {
                                        switch_channel_hangup(session->channel, cause);
                                }
@@ -163,7 +163,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(const char *uui
        if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
                /* Acquire a read lock on the session or forget it the channel is dead */
                if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-                       if (switch_channel_get_state(session->channel) < CS_HANGUP) {
+                       if (switch_channel_up(session->channel)) {
                                status = switch_core_session_receive_message(session, message);
                        }
                        switch_core_session_rwunlock(session);
@@ -183,7 +183,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(const char *uuid_
        if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
                /* Acquire a read lock on the session or forget it the channel is dead */
                if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-                       if (switch_channel_get_state(session->channel) < CS_HANGUP) {
+                       if (switch_channel_up(session->channel)) {
                                status = switch_core_session_queue_event(session, event);
                        }
                        switch_core_session_rwunlock(session);
@@ -470,7 +470,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit
 
        switch_assert(session != NULL);
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                return SWITCH_STATUS_FALSE;
        }
 
@@ -626,7 +626,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_event(switch_core_se
 
        /* Acquire a read lock on the session or forget it the channel is dead */
        if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-               if (switch_channel_get_state(session->channel) < CS_HANGUP) {
+               if (switch_channel_up(session->channel)) {
                        if (session->endpoint_interface->io_routines->receive_event) {
                                status = session->endpoint_interface->io_routines->receive_event(session, *event);
                        }
@@ -1247,7 +1247,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_c
 {
        switch_application_interface_t *application_interface;
 
-       if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
+       if (switch_channel_down(session->channel)) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is hungup, aborting execution of application: %s\n", app);
                return SWITCH_STATUS_FALSE;
        }
index 5528b7a43a707bf010bca79f78238fcfc4cdb52a..f675c8313a7106b134d16f51060047843c278b76 100644 (file)
@@ -390,7 +390,6 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                                break;
                        case CS_DONE:
                                goto done;
-                               /* HANGUP INIT ROUTING and RESET are all short term so we signal lock during their callbacks */
                        case CS_HANGUP: /* Deactivate and end the thread */
                                {
                                        const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE);
@@ -410,10 +409,10 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                                                        do_extra_handlers = 0;
                                                }
                                        }
+
+                                       switch_core_media_bug_remove_all(session);
                                        
                                        STATE_MACRO(hangup, "HANGUP");
-                                       
-                                       switch_core_media_bug_remove_all(session);
 
                                        hook_var = switch_channel_get_variable(session->channel, SWITCH_API_HANGUP_HOOK_VARIABLE);
                                        if (switch_true(switch_channel_get_variable(session->channel, SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE))) {
index 69923f83676cdbdaa9c42467c09331f9ae89cccd..f1a661b1d9012580c7d19930cca0d9649f0416f0 100644 (file)
@@ -1774,13 +1774,14 @@ static void *SWITCH_THREAD_FUNC speech_thread(switch_thread_t *thread, void *obj
 
        sth->ready = 1;
 
-       while (switch_channel_ready(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
+       while (switch_channel_up(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
                char *xmlstr = NULL;
 
                switch_thread_cond_wait(sth->cond, sth->mutex);
 
-               if (switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED))
+               if (switch_channel_down(channel) || switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
                        break;
+               }
 
                if (switch_core_asr_check_results(sth->ah, &flags) == SWITCH_STATUS_SUCCESS) {
                        switch_event_t *event;
index 865e0e9446147bb4e588448e3d3d899478b1283a..b883788e4238b4e567027018de8840f26b9441da 100644 (file)
@@ -206,7 +206,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                        goto end_of_bridge_loop;
                }
 
-               if ((b_state = switch_channel_get_state(chan_b)) >= CS_HANGUP) {
+               if ((b_state = switch_channel_down(chan_b))) {
                        goto end_of_bridge_loop;
                }
 
@@ -398,7 +398,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
        }
 
 
-       if (switch_channel_get_state(chan_b) >= CS_HANGUP) {
+       if (switch_channel_down(chan_b)) {
                if (originator && switch_channel_ready(chan_a) && !switch_channel_test_flag(chan_a, CF_ANSWERED)) {
                        switch_channel_hangup(chan_a, switch_channel_get_cause(chan_b));
                }
@@ -409,7 +409,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
        msg.from = __FILE__;
        switch_core_session_receive_message(session_a, &msg);
 
-       if (!inner_bridge && switch_channel_get_state(chan_a) < CS_HANGUP) {
+       if (!inner_bridge && switch_channel_up(chan_a)) {
                if ((app_name = switch_channel_get_variable(chan_a, SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE))) {
                        switch_caller_extension_t *extension = NULL;
                        if ((extension = switch_caller_extension_new(session_a, app_name, app_name)) == 0) {
@@ -693,7 +693,7 @@ static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session)
                        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) {
+                       if (switch_channel_up(other_channel)) {
                                switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
                        }
                }
@@ -723,7 +723,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
        switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
        switch_event_t *event;
 
-       if (switch_channel_get_state(peer_channel) >= CS_HANGUP) {
+       if (switch_channel_down(peer_channel)) {
                switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
                return SWITCH_STATUS_FALSE;
        }
@@ -1013,7 +1013,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
                        originator_channel = switch_core_session_get_channel(originator_session);
                        originatee_channel = switch_core_session_get_channel(originatee_session);
 
-                       if (switch_channel_get_state(originator_channel) >= CS_HANGUP) {
+                       if (switch_channel_down(originator_channel)) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s is hungup refusing to bridge.\n", switch_channel_get_name(originatee_channel));
                                switch_core_session_rwunlock(originator_session);
                                switch_core_session_rwunlock(originatee_session);
index 1e5d31f522da652820979bdfc71f2f8b25a92a39..806fd6d37e70e26fc6890be8e5b2d3a4ed398b8f 100644 (file)
@@ -171,7 +171,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void
 
                switch_core_session_exec(collect->session, application_interface, app_data);
 
-               if (switch_channel_get_state(channel) < CS_HANGUP) {
+               if (switch_channel_up(channel)) {
                        switch_channel_set_flag(channel, CF_WINNER);
                }
                goto wbreak;
@@ -228,7 +228,7 @@ static int check_per_channel_timeouts(originate_global_t *oglobals,
        time_t elapsed = switch_epoch_time_now(NULL) - start;
 
        for (i = 0; i < max; i++) {
-               if (originate_status[i].peer_channel && switch_channel_get_state(originate_status[i].peer_channel) < CS_HANGUP) {
+               if (originate_status[i].peer_channel && switch_channel_up(originate_status[i].peer_channel)) {
                        if (originate_status[i].per_channel_progress_timelimit_sec && elapsed > originate_status[i].per_channel_progress_timelimit_sec &&
                                !(
                                  switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY) ||
@@ -1719,7 +1719,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                                        }
                                                        pchannel = switch_core_session_get_channel(originate_status[i].peer_session);
 
-                                                       if (switch_channel_get_state(pchannel) >= CS_HANGUP) {
+                                                       if (switch_channel_down(pchannel)) {
                                                                cause_str = switch_channel_cause2str(switch_channel_get_cause(pchannel));
                                                                if (switch_stristr(cause_str, fail_on_single_reject_var)) {
                                                                        ok = 0;