[Asterisk-cvs] asterisk/apps app_mp3.c,1.15,1.16 app_nbscat.c,1.4,1.5

markster at lists.digium.com markster at lists.digium.com
Sun Apr 25 22:56:58 CDT 2004


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv25594/apps

Modified Files:
	app_mp3.c app_nbscat.c 
Log Message:
More select/poll updates for various applications


Index: app_mp3.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_mp3.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- app_mp3.c	6 Apr 2004 22:17:31 -0000	1.15
+++ app_mp3.c	26 Apr 2004 03:02:49 -0000	1.16
@@ -84,11 +84,10 @@
 static int timed_read(int fd, void *data, int datalen)
 {
 	int res;
-	fd_set fds;
-	struct timeval tv = { 2, 0 };		/* Wait no more than 2 seconds */
-	FD_ZERO(&fds);
-	FD_SET(fd, &fds);
-	res = ast_select(fd + 1, &fds, NULL, NULL, &tv);
+	struct pollfd fds[1];
+	fds[0].fd = fd;
+	fds[0].events = POLLIN;
+	res = poll(fds, 1, 2000);
 	if (res < 1) {
 		ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
 		return -1;
@@ -146,7 +145,7 @@
 				res = -1;
 				break;
 			}
-			if (ms) {
+			if (ms > 40) {
 				f = ast_read(chan);
 				if (!f) {
 					ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
@@ -161,6 +160,15 @@
 				}
 				ast_frfree(f);
 			} else  {
+#if 0
+				{
+					static struct timeval last;
+					struct timeval tv;
+					gettimeofday(&tv, NULL);
+					printf("Since last: %ld\n", (tv.tv_sec - last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000);
+					last = tv;
+				}
+#endif
 				res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
 				if (res > 0) {
 					myf.f.frametype = AST_FRAME_VOICE;
@@ -182,7 +190,10 @@
 					res = 0;
 					break;
 				}
-				ms = res / 16;
+				ms += res / 16;
+#if 0
+				printf("Next: %d\n", ms);
+#endif				
 			}
 		}
 	}

Index: app_nbscat.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_nbscat.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- app_nbscat.c	6 Apr 2004 22:17:31 -0000	1.4
+++ app_nbscat.c	26 Apr 2004 03:02:49 -0000	1.5
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- A telephony toolkit for Linux.
  *
- * Silly application to play an NBScat file -- uses mpg123
+ * Silly application to play an NBScat file -- uses nbscat8k
  * 
  * Copyright (C) 1999, Mark Spencer
  *
@@ -71,11 +71,10 @@
 static int timed_read(int fd, void *data, int datalen)
 {
 	int res;
-	fd_set fds;
-	struct timeval tv = { 2, 0 };		/* Wait no more than 2 seconds */
-	FD_ZERO(&fds);
-	FD_SET(fd, &fds);
-	res = ast_select(fd + 1, &fds, NULL, NULL, &tv);
+	struct pollfd fds[1];
+	fds[0].fd = fd;
+	fds[0].events = POLLIN;
+	res = poll(fds, 1, 2000);
 	if (res < 1) {
 		ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
 		return -1;
@@ -129,7 +128,7 @@
 				res = -1;
 				break;
 			}
-			if (ms) {
+			if (ms > 40) {
 				f = ast_read(chan);
 				if (!f) {
 					ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
@@ -165,7 +164,7 @@
 					res = 0;
 					break;
 				}
-				ms = res / 16;
+				ms += res / 16;
 			}
 		}
 	}




More information about the svn-commits mailing list