[Asterisk-cvs] asterisk/res res_musiconhold.c,1.37,1.38

markster at lists.digium.com markster at lists.digium.com
Sat Sep 4 01:37:59 CDT 2004


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

Modified Files:
	res_musiconhold.c 
Log Message:
Add stream support and permit minimum respawn time (bug #2254)


Index: res_musiconhold.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_musiconhold.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- res_musiconhold.c	8 Aug 2004 17:15:02 -0000	1.37
+++ res_musiconhold.c	4 Sep 2004 05:41:01 -0000	1.38
@@ -71,6 +71,8 @@
 "music on hold is activated, this class will be used to select which\n"
 "music is played.\n";
 
+static int respawn_time = 20;
+
 struct mohclass {
 	char class[80];
 	char dir[256];
@@ -80,6 +82,7 @@
 	int quiet;
 	int single;
 	int custom;
+	time_t start;
 	pthread_t thread;
 	struct mohdata *members;
 	/* Source of audio */
@@ -98,6 +101,7 @@
 
 static struct mohclass *mohclasses;
 
+
 AST_MUTEX_DEFINE_STATIC(moh_lock);
 
 #define LOCAL_MPG_123 "/usr/local/bin/mpg123"
@@ -116,7 +120,7 @@
 	DIR *dir;
 	struct dirent *de;
 	dir = opendir(class->dir);
-	if (!dir) {
+	if (!dir && !strstr(class->dir,"http://") && !strstr(class->dir,"HTTP://")) {
 		ast_log(LOG_WARNING, "%s is not a valid directory\n", class->dir);
 		return -1;
  	}
@@ -167,11 +171,20 @@
 	}
 
 	files = 0;
-	while((de = readdir(dir)) && (files < MAX_MP3S)) {
-		if ((strlen(de->d_name) > 3) && !strcasecmp(de->d_name + strlen(de->d_name) - 4, ".mp3")) {
-			strncpy(fns[files], de->d_name, sizeof(fns[files]) - 1);
-			argv[argc++] = fns[files];
-			files++;
+	if (strstr(class->dir,"http://") || strstr(class->dir,"HTTP://"))
+	{
+		strncpy(fns[files], class->dir, sizeof(fns[files]) - 1);
+		argv[argc++] = fns[files];
+		files++;
+	}
+	else
+	{
+		while((de = readdir(dir)) && (files < MAX_MP3S)) {
+			if ((strlen(de->d_name) > 3) && !strcasecmp(de->d_name + strlen(de->d_name) - 4, ".mp3")) {
+				strncpy(fns[files], de->d_name, sizeof(fns[files]) - 1);
+				argv[argc++] = fns[files];
+				files++;
+			}
 		}
 	}
 	argv[argc] = NULL;
@@ -194,6 +207,10 @@
 		close(fds[1]);
 		return -1;
 	}
+	if (time(NULL) - class->start < respawn_time) {
+		sleep(respawn_time - (time(NULL) - class->start));
+	}
+	time(&class->start);
 	class->pid = fork();
 	if (class->pid < 0) {
 		close(fds[0]);
@@ -522,7 +539,8 @@
 	if (!moh)
 		return -1;
 	memset(moh, 0, sizeof(struct mohclass));
-
+	time(&moh->start);
+	moh->start -= respawn_time;
 	strncpy(moh->class, classname, sizeof(moh->class) - 1);
 	if (miscargs)
 		strncpy(moh->miscargs, miscargs, sizeof(moh->miscargs) - 1);




More information about the svn-commits mailing list