redecorating

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2301 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-08-15 21:38:24 +00:00
parent a29d426c8c
commit 5782555e70
5 changed files with 30 additions and 98 deletions

View File

@ -40,42 +40,17 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
{
switch_channel_t *caller_channel;
switch_core_session_t *peer_session;
switch_caller_profile_t *caller_profile, *caller_caller_profile;
char chan_type[128] = { '\0' }, *chan_data;
unsigned int timelimit = 60; /* probably a useful option to pass in when there's time */
unsigned int timelimit = 60; /* probably a useful option to pass in when there's time */
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
strncpy(chan_type, data, sizeof(chan_type));
if ((chan_data = strchr(chan_type, '/')) != 0) {
*chan_data = '\0';
chan_data++;
}
caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
caller_caller_profile->username,
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr,
NULL,
NULL,
caller_caller_profile->rdnis,
caller_caller_profile->source,
caller_caller_profile->context,
chan_data);
if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session, NULL) !=
SWITCH_STATUS_SUCCESS) {
if (switch_ivr_outcall(session, &peer_session, data) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
return;
} else {
/* peer channel is read locked now the bridge func will unlock it for us */
switch_ivr_multi_threaded_bridge(session, peer_session, timelimit, NULL, NULL, NULL);
}
}

View File

@ -220,7 +220,6 @@ int main(int argc, char *argv[])
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "End existing sessions\n");
switch_core_session_hupall();
switch_yield(10000);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clean up modules.\n");
switch_loadable_module_shutdown();
switch_core_destroy();

View File

@ -762,9 +762,14 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originatee_caller_p
SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel,
const switch_state_handler_table_t *state_handler)
{
int index;
int x, index;
assert(channel != NULL);
for (x = 0; x < SWITCH_MAX_STATE_HANDLERS; x++) {
if (channel->state_handlers[x] == state_handler) {
return x;
}
}
index = channel->state_handler_index++;
if (channel->state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {

View File

@ -233,7 +233,15 @@ SWITCH_DECLARE(const switch_state_handler_table_t *) switch_core_get_state_handl
SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_session_t *session)
{
return (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (!switch_channel_test_flag(session->channel, CF_LOCK_THREAD)) {
if ((status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock)) == SWITCH_STATUS_SUCCESS) {
switch_channel_set_flag(session->channel, CF_LOCK_THREAD);
}
}
return status;
}
SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *session)
@ -243,6 +251,7 @@ SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *sessi
SWITCH_DECLARE(void) switch_core_session_rwunlock(switch_core_session_t *session)
{
switch_channel_clear_flag(session->channel, CF_LOCK_THREAD);
switch_thread_rwlock_unlock(session->rwlock);
}
@ -283,7 +292,7 @@ SWITCH_DECLARE(void) switch_core_session_hupall(void)
switch_mutex_unlock(runtime.session_table_mutex);
while(runtime.session_count) {
switch_yield(1000);
switch_yield(10000);
}
}
@ -3116,15 +3125,13 @@ SWITCH_DECLARE(switch_time_t) switch_core_uptime(void)
SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Closing Event Engine.\n");
switch_event_shutdown();
switch_queue_push(runtime.sql_queue, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
while (switch_queue_size(runtime.sql_queue) > 0) {
switch_yield(1000);
switch_yield(10000);
}
switch_core_db_close(runtime.db);
switch_core_db_close(runtime.event_db);
@ -3132,16 +3139,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Finalizing Shutdown.\n");
switch_log_shutdown();
if (runtime.memory_pool) {
apr_pool_destroy(runtime.memory_pool);
apr_terminate();
}
if(runtime.console != stdout && runtime.console != stderr) {
fclose(runtime.console);
runtime.console = NULL;
}
if (runtime.memory_pool) {
apr_pool_destroy(runtime.memory_pool);
apr_terminate();
}
return SWITCH_STATUS_SUCCESS;
}

View File

@ -1177,7 +1177,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr,
NULL,
NULL,
NULL,
caller_caller_profile->rdnis,
caller_caller_profile->source,
@ -1207,6 +1207,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
goto done;
}
switch_core_session_read_lock(peer_session);
peer_channel = switch_core_session_get_channel(peer_session);
assert(peer_channel != NULL);
@ -1294,12 +1296,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
{
switch_core_thread_session_t *this_audio_thread, *other_audio_thread;
switch_channel_t *caller_channel, *peer_channel;
time_t start;
int stream_id = 0;
switch_frame_t *read_frame = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
@ -1329,59 +1328,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
if (switch_core_session_runing(peer_session)) {
switch_channel_set_state(peer_channel, CS_RING);
} else {
switch_core_session_thread_launch(peer_session);
}
time(&start);
for (;;) {
int state = switch_channel_get_state(peer_channel);
if (state >= CS_RING) {
break;
}
if (!switch_channel_ready(caller_channel)) {
break;
}
if ((time(NULL) - start) > (time_t)timelimit) {
break;
}
switch_yield(1000);
}
switch_channel_pre_answer(caller_channel);
while (switch_channel_ready(caller_channel) &&
switch_channel_ready(peer_channel) &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
!switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
((time(NULL) - start) < (time_t)timelimit)) {
/* read from the channel while we wait if the audio is up on it */
if (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
if (read_frame) {
//memset(read_frame->data, 0, read_frame->datalen);
if (switch_core_session_write_frame(session, read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
break;
}
}
} else {
switch_yield(1000);
}
}
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
switch_channel_answer(caller_channel);
}