From 8f0580cd73a5523b0f2a773af33bcf35b1159607 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Mar 2007 01:19:41 +0000 Subject: [PATCH] now with rollover git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4455 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_module_interfaces.h | 2 +- .../endpoints/mod_dingaling/mod_dingaling.c | 4 +- src/mod/endpoints/mod_sofia/mod_sofia.c | 4 +- src/mod/timers/mod_softtimer/mod_softtimer.c | 49 ++++++++++++++++--- src/switch_rtp.c | 4 +- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index b0996e64a1..b9576372bf 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -225,7 +225,7 @@ struct switch_timer { /*! sample count to increment by on each cycle */ unsigned int samples; /*! current sample count based on samples parameter */ - switch_size_t samplecount; + uint32_t samplecount; /*! the timer interface provided from a loadable module */ switch_timer_interface_t *timer_interface; /*! the timer's memory pool */ diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index bb45781aa1..4477e7ffaf 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -147,7 +147,7 @@ struct private_object { unsigned int cand_id; unsigned int desc_id; unsigned int dc; - switch_size_t timestamp_send; + uint32_t timestamp_send; int32_t timestamp_recv; uint32_t last_read; char *codec_name; @@ -1357,7 +1357,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; tech_pvt->timestamp_send += samples; - if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, (uint32_t)tech_pvt->timestamp_send) < 0) { + if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send) < 0) { terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING); return SWITCH_STATUS_FALSE; } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index a6588fab0b..6bf99d454a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -276,7 +276,7 @@ struct private_object { switch_codec_t write_codec; uint32_t codec_ms; switch_caller_profile_t *caller_profile; - switch_size_t timestamp_send; + uint32_t timestamp_send; //int32_t timestamp_recv; switch_rtp_t *rtp_session; int ssrc; @@ -1881,7 +1881,7 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_ #endif tech_pvt->timestamp_send += samples; - switch_rtp_write_frame(tech_pvt->rtp_session, frame, (uint32_t)tech_pvt->timestamp_send); + switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send); switch_clear_flag_locked(tech_pvt, TFLAG_WRITING); return status; diff --git a/src/mod/timers/mod_softtimer/mod_softtimer.c b/src/mod/timers/mod_softtimer/mod_softtimer.c index 0505c83656..dbc6e927a1 100644 --- a/src/mod/timers/mod_softtimer/mod_softtimer.c +++ b/src/mod/timers/mod_softtimer/mod_softtimer.c @@ -32,6 +32,13 @@ #include #include +#ifndef UINT32_MAX +#define UINT32_MAX 0xffffffff +#endif + +#define MAX_TICK UINT32_MAX - 1024 + + static switch_memory_pool_t *module_pool = NULL; static struct { @@ -44,12 +51,15 @@ static const char modname[] = "mod_softtimer"; struct timer_private { switch_size_t reference; + switch_size_t start; + uint32_t roll; }; typedef struct timer_private timer_private_t; struct timer_matrix { switch_size_t tick; uint32_t count; + uint32_t roll; }; typedef struct timer_matrix timer_matrix_t; @@ -71,23 +81,41 @@ static inline switch_status_t timer_init(switch_timer_t *timer) TIMER_MATRIX[timer->interval].count++; switch_mutex_unlock(globals.mutex); timer->private_info = private_info; - private_info->reference = TIMER_MATRIX[timer->interval].tick; + private_info->start = private_info->reference = TIMER_MATRIX[timer->interval].tick; + private_info->roll = TIMER_MATRIX[timer->interval].roll; return SWITCH_STATUS_SUCCESS; } return SWITCH_STATUS_MEMERR; } + +#define check_roll() if (private_info->roll < TIMER_MATRIX[timer->interval].roll) {\ + private_info->roll++;\ + private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick;\ + }\ + + + static inline switch_status_t timer_step(switch_timer_t *timer) { timer_private_t *private_info = timer->private_info; + uint64_t samples; if (globals.RUNNING != 1) { return SWITCH_STATUS_FALSE; } - timer->samplecount = timer->samples * private_info->reference; - private_info->reference++;// timer->interval; + check_roll(); + samples = timer->samples * (private_info->reference - private_info->start); + + if (samples > UINT32_MAX) { + private_info->start = private_info->reference; + samples = timer->samples; + } + + timer->samplecount = (uint32_t)samples; + private_info->reference++; return SWITCH_STATUS_SUCCESS; } @@ -96,11 +124,12 @@ static inline switch_status_t timer_step(switch_timer_t *timer) static inline switch_status_t timer_next(switch_timer_t *timer) { timer_private_t *private_info = timer->private_info; - + timer_step(timer); while (globals.RUNNING == 1 && TIMER_MATRIX[timer->interval].tick < private_info->reference) { - switch_yield(1000); + check_roll(); + switch_yield(1000); } if (globals.RUNNING == 1) { @@ -121,6 +150,8 @@ static inline switch_status_t timer_check(switch_timer_t *timer) return SWITCH_STATUS_SUCCESS; } + check_roll(); + if (TIMER_MATRIX[timer->interval].tick < private_info->reference) { diff = private_info->reference - TIMER_MATRIX[timer->interval].tick; } else { @@ -141,6 +172,9 @@ static inline switch_status_t timer_destroy(switch_timer_t *timer) { switch_mutex_lock(globals.mutex); TIMER_MATRIX[timer->interval].count--; + if (TIMER_MATRIX[timer->interval].count == 0) { + TIMER_MATRIX[timer->interval].tick = 0; + } switch_mutex_unlock(globals.mutex); timer->private_info = NULL; return SWITCH_STATUS_SUCCESS; @@ -211,8 +245,11 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) index = (current_ms % i == 0) ? i : 0; if (TIMER_MATRIX[index].count) { - //TIMER_MATRIX[index].tick += index; TIMER_MATRIX[index].tick++; + if (TIMER_MATRIX[index].tick == MAX_TICK) { + TIMER_MATRIX[index].tick = 0; + TIMER_MATRIX[index].roll++; + } } } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 31ab9fc091..8ec9a14b42 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1311,7 +1311,7 @@ SWITCH_DECLARE(int) switch_rtp_write(switch_rtp_t *rtp_session, void *data, uint rtp_session->ts = ts; - if (rtp_session->ts > rtp_session->last_write_ts + rtp_session->packet_size) { + if (rtp_session->ts > rtp_session->last_write_ts + rtp_session->packet_size || rtp_session->ts == rtp_session->packet_size) { mark++; } @@ -1349,7 +1349,7 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra rtp_session->ts = ts; } - if (rtp_session->ts > rtp_session->last_write_ts + rtp_session->packet_size) { + if (rtp_session->ts > rtp_session->last_write_ts + rtp_session->packet_size || rtp_session->ts == rtp_session->packet_size) { mark++; }