[Freeswitch-svn] [commit] r4455 - in freeswitch/trunk/src: . include mod/endpoints/mod_dingaling mod/endpoints/mod_sofia mod/timers/mod_softtimer

Freeswitch SVN anthm at freeswitch.org
Mon Mar 5 20:19:41 EST 2007


Author: anthm
Date: Mon Mar  5 20:19:41 2007
New Revision: 4455

Modified:
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
   freeswitch/trunk/src/switch_rtp.c

Log:
now with rollover

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Mon Mar  5 20:19:41 2007
@@ -225,7 +225,7 @@
 	/*! 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 */

Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Mon Mar  5 20:19:41 2007
@@ -147,7 +147,7 @@
 	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 @@
 
 	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;
 	}

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Mon Mar  5 20:19:41 2007
@@ -276,7 +276,7 @@
 	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 @@
 #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;

Modified: freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
==============================================================================
--- freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	(original)
+++ freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	Mon Mar  5 20:19:41 2007
@@ -32,6 +32,13 @@
 #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 @@
 
 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 @@
 		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_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 @@
 		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 @@
 {
 	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 @@
 			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++;
+				}
 			}
 		}
 

Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c	(original)
+++ freeswitch/trunk/src/switch_rtp.c	Mon Mar  5 20:19:41 2007
@@ -1311,7 +1311,7 @@
 
 	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 @@
 			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++;
 		}
 



More information about the Freeswitch-svn mailing list