[Asterisk-cvs] asterisk/res res_musiconhold.c,1.49,1.50

markster at lists.digium.com markster at lists.digium.com
Mon Jan 10 16:08:44 CST 2005


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

Modified Files:
	res_musiconhold.c 
Log Message:
Check moh files at runtime (bug #3314)


Index: res_musiconhold.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_musiconhold.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- res_musiconhold.c	9 Jan 2005 09:00:41 -0000	1.49
+++ res_musiconhold.c	10 Jan 2005 22:12:58 -0000	1.50
@@ -140,23 +140,32 @@
 }
 
 
-static int ast_moh_files_next(struct ast_channel *chan) {
+static int ast_moh_files_next(struct ast_channel *chan) 
+{
 	struct moh_files_state *state = chan->music_state;
+	int tries;
 
 	if (state->save_pos) {
 		state->pos = state->save_pos - 1;
 		state->save_pos = 0;
 	} else {
-		state->samples = 0;
-		if (chan->stream) {
-			ast_closestream(chan->stream);
-			chan->stream = NULL;
-			state->pos++;
-		}
+		/* Try 20 times to find something good */
+		for (tries=0;tries < 20;tries++) {
+			state->samples = 0;
+			if (chan->stream) {
+				ast_closestream(chan->stream);
+				chan->stream = NULL;
+				state->pos++;
+			}
+
+			if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
+				srand(time(NULL)+getpid()+strlen(chan->name)-state->class->total_files);
+				state->pos = rand();
+			}
+			/* check to see if this file's format can be opened */
+			if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) != -1)
+				break;
 
-		if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
-			srand(time(NULL)+getpid()+strlen(chan->name)-state->class->total_files);
-			state->pos = rand();
 		}
 	}
 
@@ -712,10 +721,6 @@
 			ext++;
 		}
 
-		/* check to see if this file's format can be opened */
-		if (ast_fileexists(filepath, ext, NULL) == -1)
-			continue;
-
 		/* if the file is present in multiple formats, ensure we only put it into the list once */
 		for (i = 0; i < class->total_files; i++)
 			if (!strcmp(filepath, class->filearray[i]))




More information about the svn-commits mailing list