From 74a3d8ab95ea6fc6f2b821b3ee28d068db2d65a4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 11 Mar 2008 03:45:16 +0000 Subject: [PATCH] fix a bunch of stuff git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7854 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_ivr.h | 6 ++- src/include/switch_platform.h | 1 + src/include/switch_types.h | 3 +- .../applications/mod_commands/mod_commands.c | 47 ++++++++++++++++++- .../applications/mod_dptools/mod_dptools.c | 12 +++++ src/mod/applications/mod_enum/mod_enum.c | 4 -- .../mod_dialplan_asterisk.c | 4 -- .../mod_dialplan_directory.c | 5 -- .../mod_dialplan_xml/mod_dialplan_xml.c | 4 -- src/mod/endpoints/mod_sofia/mod_sofia.c | 20 +++++++- src/switch_channel.c | 22 ++++----- src/switch_core_state_machine.c | 19 ++++++-- src/switch_ivr.c | 8 ++-- src/switch_ivr_originate.c | 8 ++-- src/switch_ivr_play_say.c | 3 +- src/switch_rtp.c | 10 ++-- src/switch_time.c | 28 ++++++----- 17 files changed, 139 insertions(+), 65 deletions(-) diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 99bac572eb..a8e8f284ca 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -459,9 +459,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi /*! \brief Signal the session with a protocol specific hold message. \param uuid the uuid of the session to hold + \param message optional message \return SWITCH_STATUS_SUCCESS if all is well */ -SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid); +SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid, const char *message); /*! \brief Signal the session with a protocol specific unhold message. @@ -473,9 +474,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_unhold_uuid(const char *uuid); /*! \brief Signal the session with a protocol specific hold message. \param session the session to hold + \param message optional message \return SWITCH_STATUS_SUCCESS if all is well */ -SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session); +SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session, const char *message); /*! \brief Signal the session with a protocol specific unhold message. diff --git a/src/include/switch_platform.h b/src/include/switch_platform.h index 143857f5d8..38f6c2877f 100644 --- a/src/include/switch_platform.h +++ b/src/include/switch_platform.h @@ -35,6 +35,7 @@ #define SWITCH_PLATFORM_H SWITCH_BEGIN_EXTERN_C +#define SWITCH_USE_CLOCK_FUNCS #ifdef __ICC #pragma warning (disable:810 869 981 279 1469 188) #endif diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 59dadead2c..19e9461ebb 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -504,7 +504,8 @@ typedef enum { SWITCH_MESSAGE_INDICATE_BROADCAST, SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT, SWITCH_MESSAGE_INDICATE_DEFLECT, - SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ + SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, + SWITCH_MESSAGE_INDICATE_DISPLAY } switch_core_session_message_types_t; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 7075d0629d..4b5a5517b8 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1081,7 +1081,7 @@ SWITCH_STANDARD_API(sched_broadcast_function) return SWITCH_STATUS_SUCCESS; } -#define HOLD_SYNTAX "" +#define HOLD_SYNTAX " []" SWITCH_STANDARD_API(uuid_hold_function) { char *mycmd = NULL, *argv[4] = { 0 }; @@ -1102,7 +1102,49 @@ SWITCH_STANDARD_API(uuid_hold_function) if (!strcasecmp(argv[0], "off")) { status = switch_ivr_unhold_uuid(argv[1]); } else { - status = switch_ivr_hold_uuid(argv[0]); + status = switch_ivr_hold_uuid(argv[0], argv[1]); + } + } + + if (status == SWITCH_STATUS_SUCCESS) { + stream->write_function(stream, "+OK Success\n"); + } else { + stream->write_function(stream, "-ERR Operation Failed\n"); + } + + switch_safe_free(mycmd); + return SWITCH_STATUS_SUCCESS; +} + + +#define DISPLAY_SYNTAX " " +SWITCH_STANDARD_API(uuid_display_function) +{ + char *mycmd = NULL, *argv[2] = { 0 }; + int argc = 0; + switch_status_t status = SWITCH_STATUS_FALSE; + + if (session) { + return status; + } + + if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) { + argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } + + if (switch_strlen_zero(cmd) || argc < 2 || switch_strlen_zero(argv[0]) || switch_strlen_zero(argv[1])) { + stream->write_function(stream, "-USAGE: %s\n", HOLD_SYNTAX); + } else { + switch_core_session_message_t msg = { 0 }; + switch_core_session_t *lsession = NULL; + + msg.message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; + msg.string_arg = argv[1]; + msg.from = __FILE__; + + if ((lsession = switch_core_session_locate(argv[0]))) { + status = switch_core_session_receive_message(lsession, &msg); + switch_core_session_rwunlock(lsession); } } @@ -2152,6 +2194,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "uuid_broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX); SWITCH_ADD_API(commands_api_interface, "hold", "hold (depricated)", uuid_hold_function, HOLD_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_hold", "hold", uuid_hold_function, HOLD_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_display", "change display", uuid_display_function, DISPLAY_SYNTAX); SWITCH_ADD_API(commands_api_interface, "media", "media (depricated)", uuid_media_function, MEDIA_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_media", "media", uuid_media_function, MEDIA_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fsctl", "control messages", ctl_function, CTL_SYNTAX); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 2611ff79de..31ab5a2101 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -374,6 +374,17 @@ SWITCH_STANDARD_APP(redirect_function) switch_core_session_receive_message(session, &msg); } +SWITCH_STANDARD_APP(display_function) +{ + switch_core_session_message_t msg = { 0 }; + + /* Tell the channel to redirect */ + msg.from = __FILE__; + msg.string_arg = data; + msg.message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; + switch_core_session_receive_message(session, &msg); +} + SWITCH_STANDARD_APP(respond_function) { switch_core_session_message_t msg = { 0 }; @@ -1588,6 +1599,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) SWITCH_ADD_APP(app_interface, "detect_speech", "Detect speech", "Detect speech on a channel.", detect_speech_function, DETECT_SPEECH_SYNTAX, SAF_NONE); SWITCH_ADD_APP(app_interface, "ivr", "Run an ivr menu", "Run an ivr menu.", ivr_application_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "", SAF_SUPPORT_NOMEDIA); + SWITCH_ADD_APP(app_interface, "send_display", "Send session a new display", "Send session a new display.", display_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "deflect", "Send call deflect", "Send a call deflect.", deflect_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "reject", "Send session reject (depricated)", "Send a respond message to a session.", respond_function, "", SAF_SUPPORT_NOMEDIA); diff --git a/src/mod/applications/mod_enum/mod_enum.c b/src/mod/applications/mod_enum/mod_enum.c index 6eb60c2118..86ab09d5c9 100644 --- a/src/mod/applications/mod_enum/mod_enum.c +++ b/src/mod/applications/mod_enum/mod_enum.c @@ -572,10 +572,6 @@ SWITCH_STANDARD_DIALPLAN(enum_dialplan_hunt) free_results(&results); } - if (extension) { - switch_channel_set_state(channel, CS_EXECUTE); - } - return extension; } diff --git a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c index 805880c06f..48fef5fe69 100644 --- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c +++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c @@ -284,10 +284,6 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) switch_config_close_file(&cfg); - if (extension) { - switch_channel_set_state(channel, CS_EXECUTE); - } - return extension; } diff --git a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c index 626a912440..3f1f14288e 100644 --- a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c +++ b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c @@ -138,11 +138,6 @@ SWITCH_STANDARD_DIALPLAN(directory_dialplan_hunt) switch_core_directory_close(&dh); - - if (extension) { - switch_channel_set_state(channel, CS_EXECUTE); - } - return extension; } diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index 8b0d25ff2f..792cc7fd48 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -274,10 +274,6 @@ SWITCH_STANDARD_DIALPLAN(dialplan_hunt) switch_xml_free(xml); xml = NULL; - if (extension) { - switch_channel_set_state(channel, CS_EXECUTE); - } - done: switch_xml_free(xml); return extension; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 505c63a08e..a4dab15f8e 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -100,12 +100,14 @@ static switch_status_t sofia_on_init(switch_core_session_t *session) if (sofia_glue_do_invite(session) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + assert( switch_channel_get_state(channel) != CS_INIT); return SWITCH_STATUS_FALSE; } } /* Move Channel's State Machine to RING */ switch_channel_set_state(channel, CS_RING); + assert( switch_channel_get_state(channel) != CS_INIT); return SWITCH_STATUS_SUCCESS; } @@ -538,6 +540,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f tech_pvt->read_frame.flags = SFF_NONE; status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame); + if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { if (status == SWITCH_STATUS_TIMEOUT) { switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_MEDIA_TIMEOUT); @@ -552,7 +555,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf); switch_channel_queue_dtmf(channel, &dtmf); } - + if (tech_pvt->read_frame.datalen > 0) { size_t bytes = 0; int frames = 1; @@ -844,10 +847,25 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } break; + case SWITCH_MESSAGE_INDICATE_DISPLAY: + { + if (!switch_strlen_zero(msg->string_arg)) { + char message[256] = ""; + snprintf(message, sizeof(message), "From:\r\nTo: \"%s\"\r\n", msg->string_arg); + nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), SIPTAG_PAYLOAD_STR(message), TAG_END()); + } + } + break; + case SWITCH_MESSAGE_INDICATE_HOLD: { switch_set_flag_locked(tech_pvt, TFLAG_SIP_HOLD); sofia_glue_do_invite(session); + if (!switch_strlen_zero(msg->string_arg)) { + char message[256] = ""; + snprintf(message, sizeof(message), "From:\r\nTo: \"%s\"\r\n", msg->string_arg); + nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), SIPTAG_PAYLOAD_STR(message), TAG_END()); + } } break; diff --git a/src/switch_channel.c b/src/switch_channel.c index 82d581ff2a..defba01060 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1083,20 +1083,20 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw } x = 0; /* Index Variables */ - for (hi = channel->variables->headers; hi; hi = hi->next) { - char buf[1024]; - char *vvar = NULL, *vval = NULL; + if (channel->variables) { + for (hi = channel->variables->headers; hi; hi = hi->next) { + char buf[1024]; + char *vvar = NULL, *vval = NULL; - vvar = (char *) hi->name; - vval = (char *) hi->value; - x++; - - switch_assert(vvar && vval); - switch_snprintf(buf, sizeof(buf), "variable_%s", vvar); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, "%s", vval); + vvar = (char *) hi->name; + vval = (char *) hi->value; + x++; + switch_assert(vvar && vval); + switch_snprintf(buf, sizeof(buf), "variable_%s", vvar); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, "%s", vval); + } } - switch_mutex_unlock(channel->profile_mutex); } diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index f7b82e8fcd..143b0e5802 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -93,6 +93,7 @@ static void switch_core_standard_on_ring(switch_core_session_t *session) if ((extension = dialplan_interface->hunt_function(session, dparg, NULL)) != 0) { switch_channel_set_caller_extension(session->channel, extension); + switch_channel_set_state(session->channel, CS_EXECUTE); goto end; } } @@ -112,12 +113,14 @@ static void switch_core_standard_on_ring(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No Route, Aborting\n"); switch_channel_hangup(session->channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION); } + end: if (expanded && dpstr && expanded != dpstr) { free(expanded); } + } static void switch_core_standard_on_execute(switch_core_session_t *session) @@ -294,7 +297,7 @@ void switch_core_state_machine_init(switch_memory_pool_t *pool) #define STATE_MACRO(__STATE, __STATE_STR) do { \ midstate = state; \ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State %s\n", switch_channel_get_name(session->channel), __STATE_STR); \ - if (!driver_state_handler->on_##__STATE || (driver_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS \ + if (!driver_state_handler->on_##__STATE || ( driver_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS \ && midstate == switch_channel_get_state(session->channel))) { \ while (do_extra_handlers && (application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) { \ if (!application_state_handler || !application_state_handler->on_##__STATE \ @@ -325,6 +328,7 @@ void switch_core_state_machine_init(switch_memory_pool_t *pool) switch_core_standard_on_##__STATE(session); \ } \ } \ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State end %s %s %s\n", switch_channel_get_name(session->channel), __STATE_STR, switch_channel_state_name(midstate), switch_channel_state_name(switch_channel_get_state(session->channel))); \ } while (silly) SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) @@ -430,9 +434,14 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) } goto done; case CS_INIT: /* Basic setup tasks */ - switch_core_session_signal_lock(session); - STATE_MACRO(init, "INIT"); - switch_core_session_signal_unlock(session); + assert(driver_state_handler->on_init); + //switch_core_session_signal_lock(session); + if (0) STATE_MACRO(init, "INIT"); + //switch_core_session_signal_unlock(session); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State INIT\n", switch_channel_get_name(session->channel)); + driver_state_handler->on_init(session); + assert( switch_channel_get_state(session->channel) != CS_INIT); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State INIT-END\n", switch_channel_get_name(session->channel)); break; case CS_RING: /* Look for a dialplan and find something to do */ switch_core_session_signal_lock(session); @@ -480,6 +489,8 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) if (endstate == CS_NEW) { switch_yield(1000); } else { + assert( switch_channel_get_state(session->channel) != CS_INIT); + assert( switch_channel_get_running_state(session->channel) != CS_INIT); switch_thread_cond_wait(session->cond, session->mutex); } } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index c2218b7cee..658b544726 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -678,7 +678,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess return status; } -SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session) +SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session, const char *message) { switch_core_session_message_t msg = { 0 }; switch_channel_t *channel = switch_core_session_get_channel(session); @@ -686,6 +686,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session) const char *other_uuid; msg.message_id = SWITCH_MESSAGE_INDICATE_HOLD; + msg.string_arg = message; msg.from = __FILE__; switch_channel_set_flag(channel, CF_HOLD); @@ -693,7 +694,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session) switch_core_session_receive_message(session, &msg); - if ((stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { if ((other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) { switch_ivr_broadcast(other_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP); @@ -704,12 +704,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid) +SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid, const char *message) { switch_core_session_t *session; if ((session = switch_core_session_locate(uuid))) { - switch_ivr_hold(session); + switch_ivr_hold(session, message); switch_core_session_rwunlock(session); } diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index a5fc1678f3..1a017b47ea 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -34,7 +34,7 @@ static const switch_state_handler_table_t originate_state_handlers; -static switch_status_t originate_on_hold(switch_core_session_t *session) +static switch_status_t originate_on_hold_transmit(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); @@ -42,7 +42,6 @@ static switch_status_t originate_on_hold(switch_core_session_t *session) switch_ivr_sleep(session, 10); } - /* clear this handler so it only works once (next time (a.k.a. Transfer) we will do the real ring and hold states) */ switch_channel_clear_state_handler(channel, &originate_state_handlers); return SWITCH_STATUS_FALSE; @@ -64,8 +63,8 @@ static const switch_state_handler_table_t originate_state_handlers = { /*.on_execute */ NULL, /*.on_hangup */ NULL, /*.on_loopback */ NULL, - /*.on_transmit */ NULL, - /*.on_hold */ originate_on_hold + /*.on_transmit */ originate_on_hold_transmit, + /*.on_hold */ originate_on_hold_transmit }; typedef enum { @@ -113,6 +112,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t * thread, voi goto wbreak; } + switch_channel_set_state(channel, CS_TRANSMIT); switch_core_session_exec(collect->session, application_interface, app_data); if (switch_channel_get_state(channel) < CS_HANGUP) { diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 5ccb898681..5e213e9298 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -1057,8 +1057,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) { switch_yield(10000); } + tstatus = switch_core_session_read_frame(session, &read_frame, -1, 0); - + if (!SWITCH_READ_ACCEPTABLE(tstatus)) { break; } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index c0145fbbb5..902600e6d6 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -879,14 +879,12 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session) void *pop; switch_socket_t *sock; - - switch_mutex_lock((*rtp_session)->flag_mutex); - if (!rtp_session || !*rtp_session || !(*rtp_session)->ready) { - switch_mutex_unlock((*rtp_session)->flag_mutex); return; } + switch_mutex_lock((*rtp_session)->flag_mutex); + READ_INC((*rtp_session)); WRITE_INC((*rtp_session)); @@ -1122,7 +1120,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes); - + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) { switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); bytes = 0; @@ -1293,7 +1291,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (rtp_session->timer.interval) { check = (uint8_t) (switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS); - + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTO_CNG) && rtp_session->timer.samplecount >= (rtp_session->last_write_samplecount + (rtp_session->samples_per_interval * 50))) { uint8_t data[10] = { 0 }; diff --git a/src/switch_time.c b/src/switch_time.c index 2774f7d0a7..de4c8a1154 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -58,7 +58,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown); SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime); SWITCH_MODULE_DEFINITION(CORE_SOFTTIMER_MODULE, softtimer_load, softtimer_shutdown, softtimer_runtime); -#define MAX_ELEMENTS 360 +#define MAX_ELEMENTS 3600 #define IDLE_SPEED 100 #define STEP_MS 1 #define STEP_MIC 1000 @@ -202,7 +202,7 @@ static switch_status_t timer_step(switch_timer_t *timer) } timer->samplecount = (uint32_t) samples; - private_info->reference++; + private_info->reference = TIMER_MATRIX[timer->interval].tick + 1; return SWITCH_STATUS_SUCCESS; } @@ -217,7 +217,7 @@ static switch_status_t timer_next(switch_timer_t *timer) check_roll(); switch_yield(1000); } - + if (globals.RUNNING == 1) { return SWITCH_STATUS_SUCCESS; } @@ -230,7 +230,6 @@ static switch_status_t timer_check(switch_timer_t *timer) timer_private_t *private_info = timer->private_info; switch_status_t status = SWITCH_STATUS_SUCCESS; - if (globals.RUNNING != 1 || !private_info->ready) { return SWITCH_STATUS_SUCCESS; } @@ -340,20 +339,25 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime) tick = 0; } - - for (x = 1; x <= MAX_ELEMENTS; x++) { - int i = x * 10; - int index = (current_ms % i == 0) ? i : 0; + + for (x = 0; x <= MAX_ELEMENTS; x++) { + int i = x, index; + + if (i == 0) { + i = 1; + } + index = (current_ms % i == 0) ? i : 0; + if (TIMER_MATRIX[index].count) { TIMER_MATRIX[index].tick++; - if (TIMER_MATRIX[index].tick == MAX_TICK) { - TIMER_MATRIX[index].tick = 0; - TIMER_MATRIX[index].roll++; + if (TIMER_MATRIX[x].tick == MAX_TICK) { + TIMER_MATRIX[x].tick = 0; + TIMER_MATRIX[x].roll++; } } } - + if (current_ms == MAX_ELEMENTS) { current_ms = 0; }