提交 cb587626 authored 作者: Anthony Minessale's avatar Anthony Minessale

timer mojo (cont)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4151 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 e216bbe0
...@@ -905,10 +905,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer); ...@@ -905,10 +905,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_step(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 diff the remaining number of ms
\return the newest sample count \return the newest sample count
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer, uint32_t *diff); SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer);
/*! /*!
\brief Destroy an allocated timer \brief Destroy an allocated timer
......
...@@ -245,7 +245,7 @@ struct switch_timer_interface { ...@@ -245,7 +245,7 @@ struct switch_timer_interface {
/*! 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 check if the current step has expired */ /*! function to check if the current step has expired */
switch_status_t (*timer_check)(switch_timer_t *, uint32_t *); switch_status_t (*timer_check)(switch_timer_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 *);
const struct switch_timer_interface *next; const struct switch_timer_interface *next;
......
...@@ -78,10 +78,7 @@ static inline switch_status_t timer_step(switch_timer_t *timer) ...@@ -78,10 +78,7 @@ static inline 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;
while(private_info->reference <= TIMER_MATRIX[timer->interval].tick) {
private_info->reference += timer->interval; private_info->reference += timer->interval;
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -93,41 +90,31 @@ static inline switch_status_t timer_next(switch_timer_t *timer) ...@@ -93,41 +90,31 @@ static inline switch_status_t timer_next(switch_timer_t *timer)
timer_step(timer); timer_step(timer);
while (TIMER_MATRIX[timer->interval].tick < private_info->reference) { while (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
uint64_t diff; uint64_t diff;
switch_yield(timer->interval * 500);
if ((diff = (private_info->reference - TIMER_MATRIX[timer->interval].tick))) {
if (diff == timer->interval) {
switch_yield(diff * 500);
} else {
switch_yield(1000);
}
} else {
break;
}
} }
timer->samplecount += timer->samples; timer->samplecount += timer->samples;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static inline switch_status_t timer_check(switch_timer_t *timer, uint32_t *diff) static inline switch_status_t timer_check(switch_timer_t *timer)
{ {
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;
uint64_t diff;
if (TIMER_MATRIX[timer->interval].tick < private_info->reference) { if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
uint64_t _diff = private_info->reference - TIMER_MATRIX[timer->interval].tick; diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
*diff = (uint32_t) _diff;
} else { } else {
*diff = 0; diff = 0;
} }
if (*diff) { if (diff) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else { } else {
timer_step(timer); timer_step(timer);
} }
return status; return status;
} }
......
...@@ -1321,14 +1321,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer) ...@@ -1321,14 +1321,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer)
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, uint32_t *diff) SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer)
{ {
if (!timer->timer_interface) { if (!timer->timer_interface) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
return timer->timer_interface->timer_check(timer, diff); return timer->timer_interface->timer_check(timer);
} }
......
...@@ -711,7 +711,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ ...@@ -711,7 +711,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
switch_size_t bytes = 0; switch_size_t bytes = 0;
switch_status_t status; switch_status_t status;
uint8_t check = 1; uint8_t check = 1;
uint32_t diff = 0;
if (!rtp_session->timer.interval) { if (!rtp_session->timer.interval) {
rtp_session->last_time = switch_time_now(); rtp_session->last_time = switch_time_now();
...@@ -758,7 +757,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ ...@@ -758,7 +757,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
} }
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
check = (uint8_t)(switch_core_timer_check(&rtp_session->timer, &diff) == SWITCH_STATUS_SUCCESS); check = (uint8_t)(switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS);
} }
if (check) { if (check) {
...@@ -781,7 +780,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ ...@@ -781,7 +780,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (status == SWITCH_STATUS_BREAK || bytes == 0) { if (status == SWITCH_STATUS_BREAK || bytes == 0) {
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DATAWAIT)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DATAWAIT)) {
switch_yield(diff * 500); switch_yield((rtp_session->ms_per_packet / 1000) * 750);
continue; continue;
} }
return 0; return 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论