From: Tilghman Lesher Date: Mon, 27 Nov 2006 17:15:54 +0000 (+0000) Subject: Random MOH wasn't really random (bug 8381) X-Git-Tag: 1.2.14~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bb51868ca084838b7f88d408754a44dc7bddac9;p=thirdparty%2Fasterisk.git Random MOH wasn't really random (bug 8381) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@48045 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index b9b7b8f173..ccc6182578 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -190,7 +190,7 @@ static void moh_files_release(struct ast_channel *chan, void *data) if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) { ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, state->origwfmt); } - state->save_pos = state->pos + 1; + state->save_pos = state->pos; } } @@ -201,32 +201,29 @@ static int ast_moh_files_next(struct ast_channel *chan) int tries; if (state->save_pos) { - state->pos = state->save_pos - 1; + state->pos = state->save_pos; state->save_pos = 0; - } else { - /* 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)) - state->pos = rand(); + state->samples = 0; + if (chan->stream) { + ast_closestream(chan->stream); + chan->stream = NULL; + state->pos++; + state->pos %= state->class->total_files; + } - 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->pos = state->pos % state->class->total_files; - if (!ast_openstream_full(chan, state->class->filearray[state->pos], chan->language, 1)) { ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", state->class->filearray[state->pos], strerror(errno)); state->pos++;