[svn-commits] file: branch 1.2 r53084 - /branches/1.2/res/res_musiconhold.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Feb 1 14:03:11 MST 2007


Author: file
Date: Thu Feb  1 15:03:10 2007
New Revision: 53084

URL: http://svn.digium.com/view/asterisk?view=rev&rev=53084
Log:
Return previous behavior of having MOH pick up where it was left off. (issue #8672 reported by sinistermidget)

Modified:
    branches/1.2/res/res_musiconhold.c

Modified: branches/1.2/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/res/res_musiconhold.c?view=diff&rev=53084&r1=53083&r2=53084
==============================================================================
--- branches/1.2/res/res_musiconhold.c (original)
+++ branches/1.2/res/res_musiconhold.c Thu Feb  1 15:03:10 2007
@@ -203,28 +203,29 @@
 	struct moh_files_state *state = chan->music_state;
 	int tries;
 
+	/* Discontinue a stream if it is running already */
+	if (chan->stream) {
+		ast_closestream(chan->stream);
+		chan->stream = NULL;
+	}
+
+	/* If a specific file has been saved, use it */
 	if (state->save_pos) {
 		state->pos = state->save_pos;
 		state->save_pos = 0;
-	}
-
-	state->samples = 0;
-	if (chan->stream) {
-		ast_closestream(chan->stream);
-		chan->stream = NULL;
+	} else if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
+		/* Get a random file and ensure we can open it */
+		for (tries = 0; tries < 20; tries++) {
+			state->pos = rand() % state->class->total_files;
+			if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) > 0)
+				break;
+		}
+		state->samples = 0;
+	} else {
+		/* This is easy, just increment our position and make sure we don't exceed the total file count */
 		state->pos++;
 		state->pos %= state->class->total_files;
-	}
-
-	if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
-		/* Try 20 times to find something good */
-		for (tries = 0; tries < 20; tries++) {
-			state->pos = rand() % state->class->total_files;
-
-			/* check to see if this file's format can be opened */
-			if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) > 0)
-				break;
-		}
+		state->samples = 0;
 	}
 
 	if (!ast_openstream_full(chan, state->class->filearray[state->pos], chan->language, 1)) {



More information about the svn-commits mailing list