}
-static void destroy_call_by_event(eXosip_event_t * event)
+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);
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);
}
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)) {
/* 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:
//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);
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 */
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;
}
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);
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 &&
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 &&
}
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 &&
}
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 &&
}
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 &&
}
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 &&
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);
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;
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);
- return SWITCH_STATUS_FALSE;
- }
+ 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 = {
/*.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,
};
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);
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) {
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;
}