]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
now with rollover
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 6 Mar 2007 01:19:41 +0000 (01:19 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 6 Mar 2007 01:19:41 +0000 (01:19 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4455 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_module_interfaces.h
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/timers/mod_softtimer/mod_softtimer.c
src/switch_rtp.c

index b0996e64a1606c04c6771d0f6edb29854c124163..b9576372bf725ba5b3b9edb8adf00c4bf7db1297 100644 (file)
@@ -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 */
index bb45781aa1a849d9fab99ce553f54b5b0c0f265a..4477e7ffaf3d8fc9f499e7fe0429cb5e3f2fd6a1 100644 (file)
@@ -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;
        }
index a6588fab0b18980775ce43a9db85d0308cc74bd2..6bf99d454a08a4c39ca92724ca27f56797398bcd 100644 (file)
@@ -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;
index 0505c8365613b1959dee7cf747add68bf98bb481..dbc6e927a1bedcc4194d93ce12b6f086d6d14d57 100644 (file)
 #include <switch.h>
 #include <stdio.h>
 
+#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++;
+                               }
                        }
                }
 
index 31ab9fc091a1904fc38bac8a53f550e938cdc17d..8ec9a14b42f85a6dd098a901ba47e52e8aa322c9 100644 (file)
@@ -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++;
                }