diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-01-10 22:12:58 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-01-10 22:12:58 +0000 |
commit | 8389b73ec2573aad45258fda070590f4c83fd163 (patch) | |
tree | 87ce1fab0ca37c280df5d1f4a0cdb5a2fa31feb4 /res/res_musiconhold.c | |
parent | 8da3b166d649f55f74a1f218a8d1fb44a8c311fc (diff) |
Check moh files at runtime (bug #3314)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4752 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_musiconhold.c')
-rwxr-xr-x | res/res_musiconhold.c | 33 |
1 files 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])) |