From 8389b73ec2573aad45258fda070590f4c83fd163 Mon Sep 17 00:00:00 2001 From: markster Date: Mon, 10 Jan 2005 22:12:58 +0000 Subject: Check moh files at runtime (bug #3314) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4752 f38db490-d61c-443f-a65b-d21fe96a405b --- res/res_musiconhold.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 2070cdd50..335a2b101 100755 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -140,23 +140,32 @@ static void moh_files_release(struct ast_channel *chan, void *data) } -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 @@ static int moh_scan_files(struct mohclass *class) { 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])) -- cgit v1.2.3