[Freeswitch-svn] [commit] r7857 - in freeswitch/trunk/src: . include

Freeswitch SVN anthm at freeswitch.org
Tue Mar 11 12:55:58 EDT 2008


Author: anthm
Date: Tue Mar 11 12:55:58 2008
New Revision: 7857

Modified:
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/switch_core_timer.c
   freeswitch/trunk/src/switch_ivr_play_say.c
   freeswitch/trunk/src/switch_rtp.c
   freeswitch/trunk/src/switch_time.c

Log:
fix a bunch more stuff that broke from fixing it yesterday!

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Tue Mar 11 12:55:58 2008
@@ -977,12 +977,15 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer);
 
+SWITCH_DECLARE(switch_status_t) switch_core_timer_sync(switch_timer_t *timer);
+
 /*! 
   \brief Check if the current step has been exceeded
   \param timer the timer to wait on
+  \param step increment timer if a tick was detected
   \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, switch_bool_t step);
 
 /*! 
   \brief Destroy an allocated timer

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	Tue Mar 11 12:55:58 2008
@@ -202,12 +202,14 @@
 	void *private_info;
 	/*! remaining time from last call to _check()*/
 	switch_size_t diff;
+	switch_size_t tick;
 };
 
 typedef enum {
 	SWITCH_TIMER_FUNC_TIMER_INIT,
 	SWITCH_TIMER_FUNC_TIMER_NEXT,
 	SWITCH_TIMER_FUNC_TIMER_STEP,
+	SWITCH_TIMER_FUNC_TIMER_SYNC,
 	SWITCH_TIMER_FUNC_TIMER_CHECK,
 	SWITCH_TIMER_FUNC_TIMER_DESTROY
 } switch_timer_func_name_t;
@@ -222,8 +224,10 @@
 	switch_status_t (*timer_next) (switch_timer_t *);
 	/*! function to step the timer one step */
 	switch_status_t (*timer_step) (switch_timer_t *);
+	/*! function to reset the timer  */
+	switch_status_t (*timer_sync) (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 *, switch_bool_t);
 	/*! function to deallocate the timer */
 	switch_status_t (*timer_destroy) (switch_timer_t *);
 	struct switch_timer_interface *next;

Modified: freeswitch/trunk/src/switch_core_timer.c
==============================================================================
--- freeswitch/trunk/src/switch_core_timer.c	(original)
+++ freeswitch/trunk/src/switch_core_timer.c	Tue Mar 11 12:55:58 2008
@@ -40,7 +40,7 @@
 	switch_timer_interface_t *timer_interface;
 	switch_status_t status;
 	memset(timer, 0, sizeof(*timer));
-	if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0) {
+	if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0 || !timer_interface->timer_init) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid timer %s!\n", timer_name);
 		return SWITCH_STATUS_GENERR;
 	}
@@ -66,8 +66,8 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer)
 {
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
+	if (!timer->timer_interface || !timer->timer_interface->timer_next) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -81,29 +81,40 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer)
 {
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
+	if (!timer->timer_interface || !timer->timer_interface->timer_step) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
 		return SWITCH_STATUS_GENERR;
 	}
 
 	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_sync(switch_timer_t *timer)
+{
+	if (!timer->timer_interface || !timer->timer_interface->timer_sync) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
+		return SWITCH_STATUS_GENERR;
+	}
+
+	return timer->timer_interface->timer_sync(timer);
+}
+
+SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer, switch_bool_t step)
 {
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
+	if (!timer->timer_interface || !timer->timer_interface->timer_check) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
 		return SWITCH_STATUS_GENERR;
 	}
 
-	return timer->timer_interface->timer_check(timer);
+	return timer->timer_interface->timer_check(timer, step);
 }
 
 
 SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer)
 {
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initialized!\n");
+	if (!timer->timer_interface || !timer->timer_interface->timer_destroy) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not properly configured.\n");
 		return SWITCH_STATUS_GENERR;
 	}
 

Modified: freeswitch/trunk/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_play_say.c	(original)
+++ freeswitch/trunk/src/switch_ivr_play_say.c	Tue Mar 11 12:55:58 2008
@@ -1057,7 +1057,7 @@
 			while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) {
 				switch_yield(10000);
 			}
-			
+
 			tstatus = switch_core_session_read_frame(session, &read_frame, -1, 0);
 			
 			if (!SWITCH_READ_ACCEPTABLE(tstatus)) {

Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c	(original)
+++ freeswitch/trunk/src/switch_rtp.c	Tue Mar 11 12:55:58 2008
@@ -1032,7 +1032,6 @@
 			rtp_session->last_write_ts = rtp_session->dtmf_data.timestamp_dtmf + rtp_session->dtmf_data.out_digit_sub_sofar;
 			rtp_session->sending_dtmf = 0;
 			if (rtp_session->timer.interval) {
-				switch_core_timer_check(&rtp_session->timer);
 				rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
 				rtp_session->next_write_samplecount = rtp_session->timer.samplecount + samples * 5;
 			}
@@ -1044,7 +1043,6 @@
 		void *pop;
 
 		if (rtp_session->timer.interval) {
-			switch_core_timer_check(&rtp_session->timer);
 			if (rtp_session->timer.samplecount < rtp_session->next_write_samplecount) {
 				return;
 			}
@@ -1069,7 +1067,6 @@
 			
 			rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples;
 			if (rtp_session->timer.interval) {
- 				switch_core_timer_check(&rtp_session->timer);
 				offset = rtp_session->timer.samplecount - rtp_session->last_write_samplecount;
 				if (offset > 0) {
 					rtp_session->dtmf_data.timestamp_dtmf = (uint32_t)(rtp_session->dtmf_data.timestamp_dtmf + offset);
@@ -1121,6 +1118,11 @@
 		bytes = sizeof(rtp_msg_t);
 		status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes);
 		
+		if (bytes < 0) {
+			ret = (int) bytes;
+			goto end;
+		}
+		
 		if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
 			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
 			bytes = 0;
@@ -1134,9 +1136,13 @@
 			ret = (int) bytes;
 			goto end;
 		}
-		
-		if (!SWITCH_STATUS_IS_BREAK(status) && rtp_session->timer.interval) {
-			switch_core_timer_step(&rtp_session->timer);
+
+		if (rtp_session->timer.interval) {
+			if (bytes) {
+				check++;
+				switch_core_timer_sync(&rtp_session->timer);
+			}
+			check = (uint8_t) (switch_core_timer_check(&rtp_session->timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS);
 		}
 
 		if (bytes && rtp_session->recv_msg.header.version != 2) {
@@ -1284,14 +1290,7 @@
 			goto end;
 		}
 
-		if (bytes < 0) {
-			ret = (int) bytes;
-			goto end;
-		}
-
 		if (rtp_session->timer.interval) {
-			check = (uint8_t) (switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS);
-			
 			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTO_CNG) &&
 				rtp_session->timer.samplecount >= (rtp_session->last_write_samplecount + (rtp_session->samples_per_interval * 50))) {
 				uint8_t data[10] = { 0 };
@@ -1804,7 +1803,6 @@
 		}
 		
 		if (rtp_session->timer.interval) {
-			switch_core_timer_check(&rtp_session->timer);
 			rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
 		}
 		rtp_session->last_write_ts = this_ts;

Modified: freeswitch/trunk/src/switch_time.c
==============================================================================
--- freeswitch/trunk/src/switch_time.c	(original)
+++ freeswitch/trunk/src/switch_time.c	Tue Mar 11 12:55:58 2008
@@ -184,6 +184,7 @@
 		private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick;\
 	}\
 
+
 static switch_status_t timer_step(switch_timer_t *timer)
 {
 	timer_private_t *private_info = timer->private_info;
@@ -202,11 +203,32 @@
 	}
 
 	timer->samplecount = (uint32_t) samples;
-	private_info->reference = TIMER_MATRIX[timer->interval].tick + 1;
+	private_info->reference++;
+	
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t timer_sync(switch_timer_t *timer)
+{
+	timer_private_t *private_info = timer->private_info;
+
+	if (globals.RUNNING != 1 || private_info->ready == 0) {
+		return SWITCH_STATUS_FALSE;
+	}
 
+	/* sync the clock */
+	private_info->reference = timer->tick = TIMER_MATRIX[timer->interval].tick;
+
+	/* apply timestamp */
+	if (timer_step(timer) == SWITCH_STATUS_SUCCESS) {
+		/* push the reference into the future 2 more intervals to prevent collision */
+		private_info->reference += 2;
+	}
+	
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
 static switch_status_t timer_next(switch_timer_t *timer)
 {
 	timer_private_t *private_info = timer->private_info;
@@ -225,7 +247,7 @@
 	return SWITCH_STATUS_FALSE;
 }
 
-static switch_status_t timer_check(switch_timer_t *timer)
+static switch_status_t timer_check(switch_timer_t *timer, switch_bool_t step)
 {
 	timer_private_t *private_info = timer->private_info;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -236,18 +258,21 @@
 
 	check_roll();
 
-	if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
-		timer->diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
+	timer->tick = TIMER_MATRIX[timer->interval].tick;
+
+	if (timer->tick < private_info->reference) {
+		timer->diff = private_info->reference - timer->tick;
 	} else {
 		timer->diff = 0;
 	}
-
-	if (timer->diff) {
+	
+	if (timer->diff) {		
 		status = SWITCH_STATUS_FALSE;
-	} else {
+	} else if (step) {
 		timer_step(timer);
 	}
 
+
 	return status;
 }
 
@@ -348,7 +373,7 @@
 			}
 			
 			index = (current_ms % i == 0) ? i : 0; 
-
+			
 			if (TIMER_MATRIX[index].count) {
 				TIMER_MATRIX[index].tick++;
 				if (TIMER_MATRIX[x].tick == MAX_TICK) {
@@ -382,6 +407,7 @@
 	timer_interface->timer_init = timer_init;
 	timer_interface->timer_next = timer_next;
 	timer_interface->timer_step = timer_step;
+	timer_interface->timer_sync = timer_sync;
 	timer_interface->timer_check = timer_check;
 	timer_interface->timer_destroy = timer_destroy;
 



More information about the Freeswitch-svn mailing list