mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-13 18:47:44 +00:00
redecorating
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2301 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
a29d426c8c
commit
5782555e70
@ -40,42 +40,17 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
|
|||||||
{
|
{
|
||||||
switch_channel_t *caller_channel;
|
switch_channel_t *caller_channel;
|
||||||
switch_core_session_t *peer_session;
|
switch_core_session_t *peer_session;
|
||||||
switch_caller_profile_t *caller_profile, *caller_caller_profile;
|
unsigned int timelimit = 60; /* probably a useful option to pass in when there's time */
|
||||||
char chan_type[128] = { '\0' }, *chan_data;
|
|
||||||
unsigned int timelimit = 60; /* probably a useful option to pass in when there's time */
|
|
||||||
caller_channel = switch_core_session_get_channel(session);
|
caller_channel = switch_core_session_get_channel(session);
|
||||||
assert(caller_channel != NULL);
|
assert(caller_channel != NULL);
|
||||||
|
|
||||||
|
if (switch_ivr_outcall(session, &peer_session, data) != SWITCH_STATUS_SUCCESS) {
|
||||||
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) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
|
||||||
switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
|
switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
|
||||||
return;
|
return;
|
||||||
} else {
|
} 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);
|
switch_ivr_multi_threaded_bridge(session, peer_session, timelimit, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "End existing sessions\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "End existing sessions\n");
|
||||||
switch_core_session_hupall();
|
switch_core_session_hupall();
|
||||||
switch_yield(10000);
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clean up modules.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clean up modules.\n");
|
||||||
switch_loadable_module_shutdown();
|
switch_loadable_module_shutdown();
|
||||||
switch_core_destroy();
|
switch_core_destroy();
|
||||||
|
@ -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,
|
SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel,
|
||||||
const switch_state_handler_table_t *state_handler)
|
const switch_state_handler_table_t *state_handler)
|
||||||
{
|
{
|
||||||
int index;
|
int x, index;
|
||||||
|
|
||||||
assert(channel != NULL);
|
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++;
|
index = channel->state_handler_index++;
|
||||||
|
|
||||||
if (channel->state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
|
if (channel->state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
|
||||||
|
@ -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)
|
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)
|
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_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);
|
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);
|
switch_mutex_unlock(runtime.session_table_mutex);
|
||||||
|
|
||||||
while(runtime.session_count) {
|
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_DECLARE(switch_status_t) switch_core_destroy(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Closing Event Engine.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Closing Event Engine.\n");
|
||||||
switch_event_shutdown();
|
switch_event_shutdown();
|
||||||
|
|
||||||
switch_queue_push(runtime.sql_queue, NULL);
|
switch_queue_push(runtime.sql_queue, NULL);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
|
||||||
while (switch_queue_size(runtime.sql_queue) > 0) {
|
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.db);
|
||||||
switch_core_db_close(runtime.event_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_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Finalizing Shutdown.\n");
|
||||||
switch_log_shutdown();
|
switch_log_shutdown();
|
||||||
|
|
||||||
if (runtime.memory_pool) {
|
|
||||||
apr_pool_destroy(runtime.memory_pool);
|
|
||||||
apr_terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(runtime.console != stdout && runtime.console != stderr) {
|
if(runtime.console != stdout && runtime.console != stderr) {
|
||||||
fclose(runtime.console);
|
fclose(runtime.console);
|
||||||
runtime.console = NULL;
|
runtime.console = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (runtime.memory_pool) {
|
||||||
|
apr_pool_destroy(runtime.memory_pool);
|
||||||
|
apr_terminate();
|
||||||
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -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_name,
|
||||||
caller_caller_profile->caller_id_number,
|
caller_caller_profile->caller_id_number,
|
||||||
caller_caller_profile->network_addr,
|
caller_caller_profile->network_addr,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
caller_caller_profile->rdnis,
|
caller_caller_profile->rdnis,
|
||||||
caller_caller_profile->source,
|
caller_caller_profile->source,
|
||||||
@ -1207,6 +1207,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_core_session_read_lock(peer_session);
|
||||||
|
|
||||||
peer_channel = switch_core_session_get_channel(peer_session);
|
peer_channel = switch_core_session_get_channel(peer_session);
|
||||||
assert(peer_channel != NULL);
|
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_core_thread_session_t *this_audio_thread, *other_audio_thread;
|
||||||
switch_channel_t *caller_channel, *peer_channel;
|
switch_channel_t *caller_channel, *peer_channel;
|
||||||
time_t start;
|
|
||||||
int stream_id = 0;
|
int stream_id = 0;
|
||||||
switch_frame_t *read_frame = NULL;
|
|
||||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
|
|
||||||
caller_channel = switch_core_session_get_channel(session);
|
caller_channel = switch_core_session_get_channel(session);
|
||||||
assert(caller_channel != NULL);
|
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);
|
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)) {
|
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
|
||||||
switch_channel_answer(caller_channel);
|
switch_channel_answer(caller_channel);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user