aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-09-04 05:41:01 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-09-04 05:41:01 +0000
commitea0e9e5f6f2b335855d31ad2e71136a4afacb62c (patch)
tree78f2651a4a75c23dcab600f3f46598088eabfb3b /res/res_musiconhold.c
parent58be7a874b541e4dfbe87ed1f8eeb68c129ee09c (diff)
Add stream support and permit minimum respawn time (bug #2254)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3723 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_musiconhold.c')
-rwxr-xr-xres/res_musiconhold.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index f31b977cf..2cbb59c05 100755
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -71,6 +71,8 @@ static char *descrip2 = "SetMusicOnHold(class): "
"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 @@ struct mohclass {
int quiet;
int single;
int custom;
+ time_t start;
pthread_t thread;
struct mohdata *members;
/* Source of audio */
@@ -98,6 +101,7 @@ struct mohdata {
static struct mohclass *mohclasses;
+
AST_MUTEX_DEFINE_STATIC(moh_lock);
#define LOCAL_MPG_123 "/usr/local/bin/mpg123"
@@ -116,7 +120,7 @@ static int spawn_mp3(struct mohclass *class)
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 @@ static int spawn_mp3(struct mohclass *class)
}
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 @@ static int spawn_mp3(struct mohclass *class)
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 @@ static int moh_register(char *classname, char *mode, char *param, char *miscargs
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);