]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
timer mojo
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 7 Feb 2007 18:44:00 +0000 (18:44 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 7 Feb 2007 18:44:00 +0000 (18:44 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4149 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/include/switch_module_interfaces.h
src/mod/timers/mod_softtimer/mod_softtimer.c
src/switch_core.c
src/switch_rtp.c

index 826b88ebd1174208ff8aed5ca9a043775671818c..da673465ac9a8705213b072975513c4bb7ec34b0 100644 (file)
@@ -905,9 +905,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer);
 /*! 
   \brief Check if the current step has been exceeded
   \param timer the timer to wait on
+  \param diff the remaining number of ms
   \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, uint32_t *diff);
 
 /*! 
   \brief Destroy an allocated timer
index e8abf5efcf2dd63e5f35706f9ee7f0082fca4c12..37bc6497eb2b893d5fc12505f85e6022f96adae5 100644 (file)
@@ -245,7 +245,7 @@ struct switch_timer_interface {
        /*! function to step the timer one step */
        switch_status_t (*timer_step)(switch_timer_t *);
        /*! 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 *, uint32_t *);
        /*! function to deallocate the timer */
        switch_status_t (*timer_destroy)(switch_timer_t *);
        const struct switch_timer_interface *next;
index 0572d549495835fb1a190cd191fb430fd16c0fd0..e24e5e01e1834a111218d6baf1d61fa3fa747e2c 100644 (file)
@@ -78,8 +78,10 @@ static inline switch_status_t timer_step(switch_timer_t *timer)
 {
        timer_private_t *private_info = timer->private_info;
 
-       private_info->reference += timer->interval;
-
+    while(private_info->reference <= TIMER_MATRIX[timer->interval].tick) {
+        private_info->reference += timer->interval;
+    }
+    
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -87,28 +89,39 @@ 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 (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
-               switch_yield(1000);
+        uint64_t diff;
+
+        if ((diff = (private_info->reference - TIMER_MATRIX[timer->interval].tick))) {
+            switch_yield(diff * 1000);
+        }
        }
        timer->samplecount += timer->samples;
        return SWITCH_STATUS_SUCCESS;
 }
 
-static inline switch_status_t timer_check(switch_timer_t *timer)
+static inline switch_status_t timer_check(switch_timer_t *timer, uint32_t *diff)
 
 {
        timer_private_t *private_info = timer->private_info;
-       switch_status_t status;
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
 
        if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
-               status = SWITCH_STATUS_FALSE;
+        uint64_t _diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
+        *diff = (uint32_t) _diff;
        } else {
-               private_info->reference += timer->interval;
-               status = SWITCH_STATUS_SUCCESS;
+        *diff = 0;
        }
 
+    if (*diff) {
+        status = SWITCH_STATUS_FALSE;
+    } else {
+        timer_step(timer);
+    }
+
+
        return status;
 }
 
@@ -159,8 +172,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
    twice the granularity we need, we'll change it if we need anything smaller
 */
 
-#define STEP_MS 10
-#define STEP_MIC 10000
+#define STEP_MS 1
+#define STEP_MIC 1000
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
        switch_time_t reference = switch_time_now();
index 19e8b6debdfc028b7438110fb464a01c559030a0..96661f977cc4c515683699ff015927336aa3213b 100644 (file)
@@ -1321,14 +1321,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *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_check(switch_timer_t *timer, uint32_t *diff)
 {
        if (!timer->timer_interface) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n");
                return SWITCH_STATUS_GENERR;
        }
 
-       return timer->timer_interface->timer_check(timer);
+       return timer->timer_interface->timer_check(timer, diff);
 }
 
 
index b571cbc811fe3c4b4f08deed68a622ec9d1200c8..334b8814c777b488c84e95b4cdd65df38072b874 100644 (file)
@@ -711,6 +711,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
        switch_size_t bytes = 0;
        switch_status_t status;
        uint8_t check = 1;
+    uint32_t diff = 0;
 
        if (!rtp_session->timer.interval) {
                rtp_session->last_time = switch_time_now();
@@ -757,7 +758,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);
+                       check = (uint8_t)(switch_core_timer_check(&rtp_session->timer, &diff) == SWITCH_STATUS_SUCCESS);
                }
 
                if (check) {
@@ -780,7 +781,8 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
                
                if (status == SWITCH_STATUS_BREAK || bytes == 0) {
                        if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DATAWAIT)) {
-                               switch_yield(rtp_session->ms_per_packet/2);
+
+                               switch_yield(diff  * 1000);
                                continue;
                        }
                        return 0;