From 614177acd9b5a79cb145c973c36125c5a966106c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 May 2007 23:50:38 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5181 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_ivr.h | 11 ++++- src/mod/endpoints/mod_sofia/mod_sofia.c | 10 ++++ src/switch_core_session.c | 1 + src/switch_ivr.c | 66 ++++++++++++++----------- src/switch_ivr_async.c | 12 ++++- src/switch_ivr_bridge.c | 9 ++-- src/switch_ivr_play_say.c | 17 +++---- 7 files changed, 81 insertions(+), 45 deletions(-) diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index f06b47b0a3..632e450bd7 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -92,12 +92,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_ /*! \brief Parse command from an event - \param session the session to send the message to - \param event the event to send + \param session the session on which to parse the event + \param event the event to parse \return SWITCH_STATUS_SUCCESS if successful */ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event); +/*! + \brief Parse all commands from an event + \param session the session on which to parse the events + \return SWITCH_STATUS_SUCCESS if successful +*/ +SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session); + /*! \brief Wait for time to pass for a specified number of milliseconds \param session the session to wait for. diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 0fa525a3a0..d1cb37d901 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -690,6 +690,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi switch_core_session_t *other_session; switch_channel_t *other_channel; char *ip = NULL, *port = NULL; + + if (switch_channel_get_state(channel) >= CS_HANGUP) { + return SWITCH_STATUS_FALSE; + } + switch_channel_set_flag(channel, CF_BYPASS_MEDIA); tech_pvt->local_sdp_str = NULL; if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) @@ -710,6 +715,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi break; case SWITCH_MESSAGE_INDICATE_MEDIA:{ uint32_t count = 0; + + if (switch_channel_get_state(channel) >= CS_HANGUP) { + return SWITCH_STATUS_FALSE; + } + switch_channel_clear_flag(channel, CF_BYPASS_MEDIA); tech_pvt->local_sdp_str = NULL; if (!switch_rtp_ready(tech_pvt->rtp_session)) { diff --git a/src/switch_core_session.c b/src/switch_core_session.c index fc76d65dc2..8a5078215f 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -581,6 +581,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_private_event(switch return status; } + SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session) { switch_channel_t *channel; diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 9581db6cd8..70e1638205 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -374,6 +374,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se } +SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session) +{ + switch_event_t *event; + switch_channel_t *channel; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + while (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { + switch_ivr_parse_event(session, event); + switch_event_fire(&event); + } + + return SWITCH_STATUS_SUCCESS; +} + + SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_input_args_t *args) { switch_status_t status = SWITCH_STATUS_SUCCESS; @@ -383,6 +400,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_event_t *event; switch_unicast_conninfo_t *conninfo = NULL; switch_codec_t *read_codec = switch_core_session_get_read_codec(session); + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -467,10 +485,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, } } - if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(session, event); - switch_channel_event_set_data(switch_core_session_get_channel(session), event); - switch_event_fire(&event); + if (switch_core_session_private_event_count(session)) { + switch_ivr_parse_all_events(session); } if (switch_channel_has_dtmf(channel)) { @@ -540,10 +556,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s } } - if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(session, event); - switch_event_destroy(&event); - } + if (switch_core_session_private_event_count(session)) { + switch_ivr_parse_all_events(session); + } if (switch_channel_has_dtmf(channel)) { switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf)); @@ -606,8 +621,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess while (switch_channel_ready(channel)) { switch_frame_t *read_frame; - switch_event_t *event; - + if (timeout) { elapsed = (uint32_t) ((switch_time_now() - started) / 1000); if (elapsed >= timeout) { @@ -615,10 +629,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess } } - if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(session, event); - switch_event_destroy(&event); - } + if (switch_core_session_private_event_count(session)) { + switch_ivr_parse_all_events(session); + } if (switch_channel_has_dtmf(channel)) { char dtmf[128]; @@ -776,8 +789,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag switch_core_session_message_t msg = { 0 }; switch_status_t status = SWITCH_STATUS_GENERR; uint8_t swap = 0; - switch_event_t *event; - + msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA; msg.from = __FILE__; @@ -791,27 +803,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag } if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_BYPASS_MEDIA)) { - while (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(session, event); - switch_event_destroy(&event); - } - - switch_channel_set_flag(channel, CF_BYPASS_MEDIA); - switch_core_session_receive_message(session, &msg); + switch_ivr_parse_all_events(session); + if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(other_uuid))) { other_channel = switch_core_session_get_channel(other_session); assert(other_channel != NULL); - - while (switch_core_session_dequeue_private_event(other_session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(other_session, event); - switch_event_destroy(&event); - } + + switch_ivr_parse_all_events(other_session); switch_core_session_receive_message(other_session, &msg); switch_channel_clear_state_handler(other_channel, NULL); - + } + + switch_channel_set_flag(channel, CF_BYPASS_MEDIA); + switch_core_session_receive_message(session, &msg); + if (other_channel) { switch_channel_clear_state_handler(channel, NULL); if (swap) { diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index b787e312bf..5977b2cff2 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -771,7 +771,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(char *uuid, char *path, swi if ((session = switch_core_session_locate(uuid))) { char *cause = NULL; - char *mypath = strdup(path); + char *mypath; char *p; master = session; @@ -779,6 +779,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(char *uuid, char *path, swi channel = switch_core_session_get_channel(session); assert(channel != NULL); + if ((switch_channel_test_flag(channel, CF_EVENT_PARSE))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel [%s] already broadcasting...broadcast aborted\n", + switch_channel_get_name(channel)); + switch_core_session_rwunlock(session); + return SWITCH_STATUS_FALSE; + } + + mypath = strdup(path); + + if ((nomedia = switch_channel_test_flag(channel, CF_BYPASS_MEDIA))) { switch_ivr_media(uuid, SMF_REBRIDGE); } diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 897d4aa575..74900388a2 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -55,6 +55,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) switch_channel_t *chan_a, *chan_b; switch_frame_t *read_frame; switch_core_session_t *session_a, *session_b; + uint32_t loop_count = 0; session_a = data->session; if (!(session_b = switch_core_session_locate(data->b_uuid))) { @@ -80,6 +81,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) switch_channel_state_t b_state; switch_status_t status; switch_event_t *event; + loop_count++; /* if you really want to make sure it's not ready, test it twice because it might be just a break */ if (!switch_channel_ready(chan_a) && !switch_channel_ready(chan_a)) { @@ -96,21 +98,20 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) break; } - if (switch_core_session_dequeue_private_event(session_a, &event) == SWITCH_STATUS_SUCCESS) { + if (loop_count > 10 && switch_core_session_private_event_count(session_a)) { switch_channel_set_flag(chan_b, CF_SUSPEND); msg.string_arg = data->b_uuid; msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; msg.from = __FILE__; switch_core_session_receive_message(session_a, &msg); - switch_ivr_parse_event(session_a, event); + switch_ivr_parse_all_events(session_a); msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; switch_core_session_receive_message(session_a, &msg); switch_channel_clear_flag(chan_b, CF_SUSPEND); - switch_event_destroy(&event); } if (switch_channel_test_flag(chan_a, CF_SUSPEND) || switch_channel_test_flag(chan_b, CF_SUSPEND)) { - switch_yield(100000); + switch_yield(1000); continue; } diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 79b448d7d1..683718bfda 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -394,11 +394,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se while (switch_channel_ready(channel)) { switch_size_t len; - switch_event_t *event; - if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(session, event); - switch_event_destroy(&event); + if (switch_core_session_private_event_count(session)) { + switch_ivr_parse_all_events(session); } if (start && (time(NULL) - start) > limit) { @@ -425,6 +423,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se } if (args->input_callback) { + switch_event_t *event = NULL; + if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) { status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen); switch_event_destroy(&event); @@ -682,12 +682,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess int done = 0; int do_speed = 1; int last_speed = -1; - switch_event_t *event; - - if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) { - switch_ivr_parse_event(session, event); - switch_event_destroy(&event); + if (switch_core_session_private_event_count(session)) { + switch_ivr_parse_all_events(session); } if (args && (args->input_callback || args->buf || args->buflen)) { @@ -711,6 +708,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } if (args->input_callback) { + switch_event_t *event; + if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) { status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen); switch_event_destroy(&event);