git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1272 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-04-26 23:09:48 +00:00
parent 842ae3a2f6
commit 152e42aa6c
4 changed files with 68 additions and 27 deletions

View File

@ -1389,6 +1389,7 @@ static void destroy_call_by_event(eXosip_event_t * event)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
switch_call_cause_t cause;
if ((tech_pvt = get_pvt_by_call_id(event->cid)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cannot destroy nonexistant call [%d]!\n", event->cid);
@ -1400,7 +1401,28 @@ static void destroy_call_by_event(eXosip_event_t * event)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "destroy %s\n", switch_channel_get_name(channel));
exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
switch (event->type) {
case EXOSIP_CALL_RELEASED:
case EXOSIP_CALL_CLOSED:
cause = SWITCH_CAUSE_NORMAL_CLEARING;
break;
case EXOSIP_CALL_NOANSWER:
cause = SWITCH_CAUSE_NO_ANSWER;
break;
case EXOSIP_CALL_REQUESTFAILURE:
cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
break;
case EXOSIP_CALL_SERVERFAILURE:
case EXOSIP_CALL_GLOBALFAILURE:
cause = SWITCH_CAUSE_CALL_REJECTED;
break;
default:
cause = SWITCH_CAUSE_SWITCH_CONGESTION;
break;
}
switch_channel_hangup(channel, cause);
}
@ -1825,7 +1847,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
case EXOSIP_CALL_REINVITE:
/* See what the reinvite is about - on hold or whatever */
//handle_reinvite(event);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Got a reinvite.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got a reinvite.\n");
break;
case EXOSIP_CALL_MESSAGE_NEW:
if (event->request != NULL && MSG_IS_REFER(event->request)) {
@ -1836,7 +1858,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
/* If audio is not flowing and this has SDP - fire it up! */
break;
case EXOSIP_CALL_ANSWERED:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "The call was answered.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "The call was answered.\n");
handle_answer(event);
break;
case EXOSIP_CALL_PROCEEDING:
@ -1846,7 +1868,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
//handle_ringing(event);
break;
case EXOSIP_CALL_REDIRECTED:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call was redirect\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call was redirect\n");
break;
case EXOSIP_CALL_CLOSED:
destroy_call_by_event(event);
@ -1855,24 +1877,24 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
destroy_call_by_event(event);
break;
case EXOSIP_CALL_NOANSWER:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "The call was not answered.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "The call was not answered.\n");
destroy_call_by_event(event);
break;
case EXOSIP_CALL_REQUESTFAILURE:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Request failure\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Request failure\n");
destroy_call_by_event(event);
break;
case EXOSIP_CALL_SERVERFAILURE:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Server failure\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Server failure\n");
destroy_call_by_event(event);
break;
case EXOSIP_CALL_GLOBALFAILURE:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Global failure\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Global failure\n");
destroy_call_by_event(event);
break;
/* Registration related stuff */
case EXOSIP_REGISTRATION_NEW:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Received registration attempt\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received registration attempt\n");
break;
default:
/* Unknown event... casually absorb it for now */

View File

@ -297,6 +297,7 @@ SWITCH_DECLARE(switch_status) switch_channel_set_name(switch_channel *channel, c
channel->name = NULL;
if (name) {
channel->name = switch_core_session_strdup(channel->session, name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Channel %s\n", name);
}
return SWITCH_STATUS_SUCCESS;
}
@ -700,7 +701,7 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_hangup(switch_channel *chann
channel->state = CS_HANGUP;
channel->hangup_cause = hangup_cause;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hangup %s [%s] [%s]\n", channel->name,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n", channel->name,
state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);

View File

@ -1847,12 +1847,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
switch (state) {
case CS_NEW: /* Just created, Waiting for first instructions */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State NEW\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State NEW\n", switch_channel_get_name(session->channel));
break;
case CS_DONE:
continue;
case CS_HANGUP: /* Deactivate and end the thread */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State HANGUP\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State HANGUP\n", switch_channel_get_name(session->channel));
if (!driver_state_handler->on_hangup ||
(driver_state_handler->on_hangup &&
driver_state_handler->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
@ -1891,7 +1891,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
midstate = switch_channel_get_state(session->channel);
break;
case CS_INIT: /* Basic setup tasks */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State INIT\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State INIT\n", switch_channel_get_name(session->channel));
if (!driver_state_handler->on_init ||
(driver_state_handler->on_init &&
driver_state_handler->on_init(session) == SWITCH_STATUS_SUCCESS &&
@ -1927,7 +1927,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
break;
case CS_RING: /* Look for a dialplan and find something to do */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State RING\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State RING\n", switch_channel_get_name(session->channel));
if (!driver_state_handler->on_ring ||
(driver_state_handler->on_ring &&
driver_state_handler->on_ring(session) == SWITCH_STATUS_SUCCESS &&
@ -1963,7 +1963,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
break;
case CS_EXECUTE: /* Execute an Operation */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State EXECUTE\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State EXECUTE\n", switch_channel_get_name(session->channel));
if (!driver_state_handler->on_execute ||
(driver_state_handler->on_execute &&
driver_state_handler->on_execute(session) == SWITCH_STATUS_SUCCESS &&
@ -1999,7 +1999,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
break;
case CS_LOOPBACK: /* loop all data back to source */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State LOOPBACK\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State LOOPBACK\n", switch_channel_get_name(session->channel));
if (!driver_state_handler->on_loopback ||
(driver_state_handler->on_loopback &&
driver_state_handler->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
@ -2035,7 +2035,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
break;
case CS_TRANSMIT: /* send/recieve data to/from another channel */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State TRANSMIT\n", switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State TRANSMIT\n", switch_channel_get_name(session->channel));
if (!driver_state_handler->on_transmit ||
(driver_state_handler->on_transmit &&
driver_state_handler->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
@ -2093,6 +2093,8 @@ SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session **session)
switch_memory_pool *pool;
switch_event *event;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Close Channel %s\n", switch_channel_get_name((*session)->channel));
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DESTROY) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data((*session)->channel, event);
switch_event_fire(&event);

View File

@ -802,7 +802,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
return NULL;
}
static switch_status audio_bridge_on_transmit(switch_core_session *session)
static switch_status audio_bridge_on_loopback(switch_core_session *session)
{
switch_channel *channel = NULL;
void *arg;
@ -829,13 +829,21 @@ static switch_status audio_bridge_on_ring(switch_core_session *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
/* put the channel in a passive state so we can loop audio to it */
if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
//switch_channel_set_state(channel, CS_TRANSMIT);
switch_channel_set_state(channel, CS_TRANSMIT);
return SWITCH_STATUS_FALSE;
}
static switch_status audio_bridge_on_transmit(switch_core_session *session)
{
switch_channel *channel = NULL;
return SWITCH_STATUS_SUCCESS;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM TRANSMIT\n");
/* put the channel in a passive state so we can loop audio to it */
return SWITCH_STATUS_FALSE;
}
static const switch_state_handler_table audio_bridge_peer_state_handlers = {
@ -843,8 +851,8 @@ static const switch_state_handler_table audio_bridge_peer_state_handlers = {
/*.on_ring */ audio_bridge_on_ring,
/*.on_execute */ NULL,
/*.on_hangup */ NULL,
/*.on_loopback */ NULL,
/*.on_transmit */ audio_bridge_on_transmit
/*.on_loopback */ audio_bridge_on_loopback,
/*.on_transmit */ audio_bridge_on_transmit,
};
@ -953,6 +961,8 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
switch_event *event;
switch_core_session_message msg = {0};
switch_channel_set_state(peer_channel, CS_TRANSMIT);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(caller_channel, event);
switch_event_fire(&event);
@ -968,7 +978,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
switch_channel_set_flag(peer_channel, CF_LOCK_THREAD);
switch_channel_set_private(peer_channel, &other_audio_thread);
switch_channel_set_state(peer_channel, CS_TRANSMIT);
switch_channel_set_state(peer_channel, CS_LOOPBACK);
audio_bridge_thread(NULL, (void *) &this_audio_thread);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
@ -976,6 +986,12 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
switch_event_fire(&event);
}
switch_channel_clear_flag(peer_channel, CF_LOCK_THREAD);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bridge Failed %s->%s\n",
switch_channel_get_name(caller_channel),
switch_channel_get_name(peer_channel)
);
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}