[svn-commits] russell: branch group/timing r122432 - in /team/group/timing: include/asteris...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 12 18:03:22 CDT 2008


Author: russell
Date: Thu Jun 12 18:03:22 2008
New Revision: 122432

URL: http://svn.digium.com/view/asterisk?view=rev&rev=122432
Log:
convert the core over to the timing API ... ready for testing

Modified:
    team/group/timing/include/asterisk/channel.h
    team/group/timing/main/channel.c
    team/group/timing/main/file.c

Modified: team/group/timing/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/group/timing/include/asterisk/channel.h?view=diff&rev=122432&r1=122431&r2=122432
==============================================================================
--- team/group/timing/include/asterisk/channel.h (original)
+++ team/group/timing/include/asterisk/channel.h Thu Jun 12 18:03:22 2008
@@ -1423,9 +1423,17 @@
  */
 int ast_autoservice_stop(struct ast_channel *chan);
 
-/* If built with dahdi optimizations, force a scheduled expiration on the
-   timer fd, at which point we call the callback function / data */
-int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);
+/*!
+ * \brief Enable or disable timer ticks for a channel
+ *
+ * \arg rate number of timer ticks per second
+ *
+ * If timers are supported, force a scheduled expiration on the
+ * timer fd, at which point we call the callback function / data 
+ *
+ * Call this function with a rate of 0 to turn off the timer ticks
+ */
+int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
 
 /*!	\brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
    and 1 if supported and requested 

Modified: team/group/timing/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/main/channel.c?view=diff&rev=122432&r1=122431&r2=122432
==============================================================================
--- team/group/timing/main/channel.c (original)
+++ team/group/timing/main/channel.c Thu Jun 12 18:03:22 2008
@@ -61,6 +61,7 @@
 #include "asterisk/threadstorage.h"
 #include "asterisk/slinfactory.h"
 #include "asterisk/audiohook.h"
+#include "asterisk/timing.h"
 
 #ifdef HAVE_EPOLL
 #include <sys/epoll.h>
@@ -808,27 +809,19 @@
 #endif
 	}
 
-#ifdef HAVE_DAHDI
-	tmp->timingfd = open("/dev/dahdi/timer", O_RDWR);
+	tmp->timingfd = ast_timer_open();
 	if (tmp->timingfd > -1) {
-		/* Check if timing interface supports new
-		   ping/pong scheme */
-		flags = 1;
-		if (!ioctl(tmp->timingfd, DAHDI_TIMERPONG, &flags))
-			needqueue = 0;
-	}
-#else
-	tmp->timingfd = -1;					
-#endif					
+		needqueue = 0;
+	}
 
 	if (needqueue) {
 		if (pipe(tmp->alertpipe)) {
 			ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
 alertpipe_failed:
-#ifdef HAVE_DAHDI
-			if (tmp->timingfd > -1)
-				close(tmp->timingfd);
-#endif
+			if (tmp->timingfd > -1) {
+				ast_timer_close(tmp->timingfd);
+			}
+
 			sched_context_destroy(tmp->sched);
 			ast_string_field_free_memory(tmp);
 			ast_free(tmp);
@@ -1007,10 +1000,8 @@
 		if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah))
 			ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n",
 				chan->name, f->frametype, f->subclass, qlen, strerror(errno));
-#ifdef HAVE_DAHDI
 	} else if (chan->timingfd > -1) {
-		ioctl(chan->timingfd, DAHDI_TIMERPING, &blah);
-#endif				
+		ast_timer_enable_continuous(chan->timingfd);
 	} else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
 		pthread_kill(chan->blocker, SIGURG);
 	}
@@ -1343,7 +1334,7 @@
 	if ((fd = chan->alertpipe[1]) > -1)
 		close(fd);
 	if ((fd = chan->timingfd) > -1)
-		close(fd);
+		ast_timer_close(fd);
 #ifdef HAVE_EPOLL
 	for (i = 0; i < AST_MAX_FDS; i++) {
 		if (chan->epfd_data[i])
@@ -1795,7 +1786,7 @@
 	}
 	
 	if (!res) {
-		ast_settimeout(chan, 160, generator_force, chan);
+		ast_settimeout(chan, 50, generator_force, chan);
 		chan->generator = gen;
 	}
 
@@ -2181,21 +2172,26 @@
 	return ast_waitfordigit_full(c, ms, -1, -1);
 }
 
-int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data)
-{
-	int res = -1;
-#ifdef HAVE_DAHDI
-	if (c->timingfd > -1) {
-		if (!func) {
-			samples = 0;
-			data = 0;
-		}
-		ast_debug(1, "Scheduling timer at %d sample intervals\n", samples);
-		res = ioctl(c->timingfd, DAHDI_TIMERCONFIG, &samples);
-		c->timingfunc = func;
-		c->timingdata = data;
-	}
-#endif	
+int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data)
+{
+	int res;
+
+	if (c->timingfd == -1) {
+		return -1;
+	}
+
+	if (!func) {
+		rate = 0;
+		data = NULL;
+	}
+
+	ast_debug(1, "Scheduling timer at %u timer ticks per second\n", rate);
+
+	res = ast_timer_set_rate(c->timingfd, rate);
+
+	c->timingfunc = func;
+	c->timingdata = data;
+
 	return res;
 }
 
@@ -2334,7 +2330,7 @@
 	} else if (f->frametype == AST_FRAME_CNG) {
 		if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) {
 			ast_debug(1, "Generator got CNG, switching to timed mode\n");
-			ast_settimeout(chan, 160, generator_force, chan);
+			ast_settimeout(chan, 50, generator_force, chan);
 		}
 	}
 }

Modified: team/group/timing/main/file.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/main/file.c?view=diff&rev=122432&r1=122431&r2=122432
==============================================================================
--- team/group/timing/main/file.c (original)
+++ team/group/timing/main/file.c Thu Jun 12 18:03:22 2008
@@ -29,6 +29,7 @@
 
 #include <dirent.h>
 #include <sys/stat.h>
+#include <math.h>
 
 #include "asterisk/_private.h"	/* declare ast_file_init() */
 #include "asterisk/paths.h"	/* use ast_config_AST_DATA_DIR */
@@ -659,21 +660,17 @@
 		}
 	}
 	if (whennext != s->lasttimeout) {
-#ifdef HAVE_DAHDI
 		if (s->owner->timingfd > -1) {
-			int zap_timer_samples = whennext;
-			int rate;
-			/* whennext is in samples, but DAHDI timers operate in 8 kHz samples. */
-			if ((rate = ast_format_rate(s->fmt->format)) != 8000) {
-				float factor;
-				factor = ((float) rate) / ((float) 8000.0); 
-				zap_timer_samples = (int) ( ((float) zap_timer_samples) / factor );
-			}
-			ast_settimeout(s->owner, zap_timer_samples, ast_fsread_audio, s);
-		} else
-#endif		
+			float samp_rate = (float) ast_format_rate(s->fmt->format);
+			unsigned int rate;
+
+			rate = (unsigned int) roundf(samp_rate / ((float) whennext));
+
+			ast_settimeout(s->owner, rate, ast_fsread_audio, s);
+		} else {
 			s->owner->streamid = ast_sched_add(s->owner->sched, 
 				whennext / (ast_format_rate(s->fmt->format) / 1000), ast_fsread_audio, s);
+		}
 		s->lasttimeout = whennext;
 		return FSREAD_SUCCESS_NOSCHED;
 	}
@@ -681,9 +678,7 @@
 
 return_failure:
 	s->owner->streamid = -1;
-#ifdef HAVE_DAHDI
 	ast_settimeout(s->owner, 0, NULL, NULL);
-#endif			
 	return FSREAD_FAILURE;
 }
 
@@ -792,9 +787,7 @@
 		if (f->fmt->format & AST_FORMAT_AUDIO_MASK) {
 			f->owner->stream = NULL;
 			AST_SCHED_DEL(f->owner->sched, f->owner->streamid);
-#ifdef HAVE_DAHDI
 			ast_settimeout(f->owner, 0, NULL, NULL);
-#endif			
 		} else {
 			f->owner->vstream = NULL;
 			AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid);




More information about the svn-commits mailing list