fix a bunch more stuff that broke from fixing it yesterday!

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7857 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-03-11 16:55:58 +00:00
parent da754b5098
commit 2294d90653
6 changed files with 79 additions and 37 deletions

View File

@ -977,12 +977,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer);
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer); SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer);
SWITCH_DECLARE(switch_status_t) switch_core_timer_sync(switch_timer_t *timer);
/*! /*!
\brief Check if the current step has been exceeded \brief Check if the current step has been exceeded
\param timer the timer to wait on \param timer the timer to wait on
\param step increment timer if a tick was detected
\return the newest sample count \return the newest sample count
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer); SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer, switch_bool_t step);
/*! /*!
\brief Destroy an allocated timer \brief Destroy an allocated timer

View File

@ -202,12 +202,14 @@ struct switch_timer {
void *private_info; void *private_info;
/*! remaining time from last call to _check()*/ /*! remaining time from last call to _check()*/
switch_size_t diff; switch_size_t diff;
switch_size_t tick;
}; };
typedef enum { typedef enum {
SWITCH_TIMER_FUNC_TIMER_INIT, SWITCH_TIMER_FUNC_TIMER_INIT,
SWITCH_TIMER_FUNC_TIMER_NEXT, SWITCH_TIMER_FUNC_TIMER_NEXT,
SWITCH_TIMER_FUNC_TIMER_STEP, SWITCH_TIMER_FUNC_TIMER_STEP,
SWITCH_TIMER_FUNC_TIMER_SYNC,
SWITCH_TIMER_FUNC_TIMER_CHECK, SWITCH_TIMER_FUNC_TIMER_CHECK,
SWITCH_TIMER_FUNC_TIMER_DESTROY SWITCH_TIMER_FUNC_TIMER_DESTROY
} switch_timer_func_name_t; } switch_timer_func_name_t;
@ -222,8 +224,10 @@ struct switch_timer_interface {
switch_status_t (*timer_next) (switch_timer_t *); switch_status_t (*timer_next) (switch_timer_t *);
/*! function to step the timer one step */ /*! function to step the timer one step */
switch_status_t (*timer_step) (switch_timer_t *); switch_status_t (*timer_step) (switch_timer_t *);
/*! function to reset the timer */
switch_status_t (*timer_sync) (switch_timer_t *);
/*! function to check if the current step has expired */ /*! function to check if the current step has expired */
switch_status_t (*timer_check) (switch_timer_t *); switch_status_t (*timer_check) (switch_timer_t *, switch_bool_t);
/*! function to deallocate the timer */ /*! function to deallocate the timer */
switch_status_t (*timer_destroy) (switch_timer_t *); switch_status_t (*timer_destroy) (switch_timer_t *);
struct switch_timer_interface *next; struct switch_timer_interface *next;

View File

@ -40,7 +40,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, co
switch_timer_interface_t *timer_interface; switch_timer_interface_t *timer_interface;
switch_status_t status; switch_status_t status;
memset(timer, 0, sizeof(*timer)); memset(timer, 0, sizeof(*timer));
if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0) { if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0 || !timer_interface->timer_init) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid timer %s!\n", timer_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid timer %s!\n", timer_name);
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -66,8 +66,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, co
SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer) SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer)
{ {
if (!timer->timer_interface) { if (!timer->timer_interface || !timer->timer_interface->timer_next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -81,29 +81,40 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer)
SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer) SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer)
{ {
if (!timer->timer_interface) { if (!timer->timer_interface || !timer->timer_interface->timer_step) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
return timer->timer_interface->timer_step(timer); return timer->timer_interface->timer_step(timer);
} }
SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer)
SWITCH_DECLARE(switch_status_t) switch_core_timer_sync(switch_timer_t *timer)
{ {
if (!timer->timer_interface) { if (!timer->timer_interface || !timer->timer_interface->timer_sync) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
return timer->timer_interface->timer_check(timer); return timer->timer_interface->timer_sync(timer);
}
SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer, switch_bool_t step)
{
if (!timer->timer_interface || !timer->timer_interface->timer_check) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
return SWITCH_STATUS_GENERR;
}
return timer->timer_interface->timer_check(timer, step);
} }
SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer) SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer)
{ {
if (!timer->timer_interface) { if (!timer->timer_interface || !timer->timer_interface->timer_destroy) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }

View File

@ -1057,7 +1057,7 @@ 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)) { while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) {
switch_yield(10000); switch_yield(10000);
} }
tstatus = switch_core_session_read_frame(session, &read_frame, -1, 0); tstatus = switch_core_session_read_frame(session, &read_frame, -1, 0);
if (!SWITCH_READ_ACCEPTABLE(tstatus)) { if (!SWITCH_READ_ACCEPTABLE(tstatus)) {

View File

@ -1032,7 +1032,6 @@ static void do_2833(switch_rtp_t *rtp_session)
rtp_session->last_write_ts = rtp_session->dtmf_data.timestamp_dtmf + rtp_session->dtmf_data.out_digit_sub_sofar; rtp_session->last_write_ts = rtp_session->dtmf_data.timestamp_dtmf + rtp_session->dtmf_data.out_digit_sub_sofar;
rtp_session->sending_dtmf = 0; rtp_session->sending_dtmf = 0;
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
switch_core_timer_check(&rtp_session->timer);
rtp_session->last_write_samplecount = rtp_session->timer.samplecount; rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
rtp_session->next_write_samplecount = rtp_session->timer.samplecount + samples * 5; rtp_session->next_write_samplecount = rtp_session->timer.samplecount + samples * 5;
} }
@ -1044,7 +1043,6 @@ static void do_2833(switch_rtp_t *rtp_session)
void *pop; void *pop;
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
switch_core_timer_check(&rtp_session->timer);
if (rtp_session->timer.samplecount < rtp_session->next_write_samplecount) { if (rtp_session->timer.samplecount < rtp_session->next_write_samplecount) {
return; return;
} }
@ -1069,7 +1067,6 @@ static void do_2833(switch_rtp_t *rtp_session)
rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples; rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples;
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
switch_core_timer_check(&rtp_session->timer);
offset = rtp_session->timer.samplecount - rtp_session->last_write_samplecount; offset = rtp_session->timer.samplecount - rtp_session->last_write_samplecount;
if (offset > 0) { if (offset > 0) {
rtp_session->dtmf_data.timestamp_dtmf = (uint32_t)(rtp_session->dtmf_data.timestamp_dtmf + offset); rtp_session->dtmf_data.timestamp_dtmf = (uint32_t)(rtp_session->dtmf_data.timestamp_dtmf + offset);
@ -1121,6 +1118,11 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
bytes = sizeof(rtp_msg_t); bytes = sizeof(rtp_msg_t);
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes);
if (bytes < 0) {
ret = (int) bytes;
goto end;
}
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
bytes = 0; bytes = 0;
@ -1134,9 +1136,13 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
ret = (int) bytes; ret = (int) bytes;
goto end; goto end;
} }
if (!SWITCH_STATUS_IS_BREAK(status) && rtp_session->timer.interval) { if (rtp_session->timer.interval) {
switch_core_timer_step(&rtp_session->timer); if (bytes) {
check++;
switch_core_timer_sync(&rtp_session->timer);
}
check = (uint8_t) (switch_core_timer_check(&rtp_session->timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS);
} }
if (bytes && rtp_session->recv_msg.header.version != 2) { if (bytes && rtp_session->recv_msg.header.version != 2) {
@ -1284,14 +1290,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
goto end; goto end;
} }
if (bytes < 0) {
ret = (int) bytes;
goto end;
}
if (rtp_session->timer.interval) { 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) && 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))) { rtp_session->timer.samplecount >= (rtp_session->last_write_samplecount + (rtp_session->samples_per_interval * 50))) {
uint8_t data[10] = { 0 }; uint8_t data[10] = { 0 };
@ -1804,7 +1803,6 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
} }
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
switch_core_timer_check(&rtp_session->timer);
rtp_session->last_write_samplecount = rtp_session->timer.samplecount; rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
} }
rtp_session->last_write_ts = this_ts; rtp_session->last_write_ts = this_ts;

View File

@ -184,6 +184,7 @@ static switch_status_t timer_init(switch_timer_t *timer)
private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick;\ private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick;\
}\ }\
static switch_status_t timer_step(switch_timer_t *timer) static switch_status_t timer_step(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
@ -202,11 +203,32 @@ static switch_status_t timer_step(switch_timer_t *timer)
} }
timer->samplecount = (uint32_t) samples; timer->samplecount = (uint32_t) samples;
private_info->reference = TIMER_MATRIX[timer->interval].tick + 1; private_info->reference++;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t timer_sync(switch_timer_t *timer)
{
timer_private_t *private_info = timer->private_info;
if (globals.RUNNING != 1 || private_info->ready == 0) {
return SWITCH_STATUS_FALSE;
}
/* sync the clock */
private_info->reference = timer->tick = TIMER_MATRIX[timer->interval].tick;
/* apply timestamp */
if (timer_step(timer) == SWITCH_STATUS_SUCCESS) {
/* push the reference into the future 2 more intervals to prevent collision */
private_info->reference += 2;
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t timer_next(switch_timer_t *timer) static switch_status_t timer_next(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
@ -225,7 +247,7 @@ static switch_status_t timer_next(switch_timer_t *timer)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
static switch_status_t timer_check(switch_timer_t *timer) static switch_status_t timer_check(switch_timer_t *timer, switch_bool_t step)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
@ -236,18 +258,21 @@ static switch_status_t timer_check(switch_timer_t *timer)
check_roll(); check_roll();
if (TIMER_MATRIX[timer->interval].tick < private_info->reference) { timer->tick = TIMER_MATRIX[timer->interval].tick;
timer->diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
if (timer->tick < private_info->reference) {
timer->diff = private_info->reference - timer->tick;
} else { } else {
timer->diff = 0; timer->diff = 0;
} }
if (timer->diff) { if (timer->diff) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else { } else if (step) {
timer_step(timer); timer_step(timer);
} }
return status; return status;
} }
@ -348,7 +373,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
} }
index = (current_ms % i == 0) ? i : 0; index = (current_ms % i == 0) ? i : 0;
if (TIMER_MATRIX[index].count) { if (TIMER_MATRIX[index].count) {
TIMER_MATRIX[index].tick++; TIMER_MATRIX[index].tick++;
if (TIMER_MATRIX[x].tick == MAX_TICK) { if (TIMER_MATRIX[x].tick == MAX_TICK) {
@ -382,6 +407,7 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load)
timer_interface->timer_init = timer_init; timer_interface->timer_init = timer_init;
timer_interface->timer_next = timer_next; timer_interface->timer_next = timer_next;
timer_interface->timer_step = timer_step; timer_interface->timer_step = timer_step;
timer_interface->timer_sync = timer_sync;
timer_interface->timer_check = timer_check; timer_interface->timer_check = timer_check;
timer_interface->timer_destroy = timer_destroy; timer_interface->timer_destroy = timer_destroy;