]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Return previous behavior of having MOH pick up where it was left off. (issue #8672...
authorJoshua Colp <jcolp@digium.com>
Thu, 1 Feb 2007 21:03:10 +0000 (21:03 +0000)
committerJoshua Colp <jcolp@digium.com>
Thu, 1 Feb 2007 21:03:10 +0000 (21:03 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@53084 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_musiconhold.c

index 04e4a39eebc10643a6ebd84bc6405df75e88aece..7649d6f5b537ce5e18a98c265dec45a65cde122b 100644 (file)
@@ -203,28 +203,29 @@ 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;
-               state->save_pos = 0;
-       }
-
-       state->samples = 0;
+       /* Discontinue a stream if it is running already */
        if (chan->stream) {
                ast_closestream(chan->stream);
                chan->stream = NULL;
-               state->pos++;
-               state->pos %= state->class->total_files;
        }
 
-       if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
-               /* Try 20 times to find something good */
+       /* If a specific file has been saved, use it */
+       if (state->save_pos) {
+               state->pos = state->save_pos;
+               state->save_pos = 0;
+       } 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;
-
-                       /* 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;
+       } 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;
+               state->samples = 0;
        }
 
        if (!ast_openstream_full(chan, state->class->filearray[state->pos], chan->language, 1)) {