fix issue in monitor_early_media_fail issue

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12271 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-02-25 03:41:18 +00:00
parent 4a520847c2
commit 9556be51ef
17 changed files with 43 additions and 43 deletions

View 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,

View 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;
}

View 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;

View 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) {

View 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;
}

View 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);

View 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);
}

View 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] = "";

View 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;
}

View 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);

View 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;
}

View 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",

View 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;
}

View 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))) {

View 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;

View 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);

View 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;