Check moh files at runtime (bug #3314)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4752 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-01-10 22:12:58 +00:00
parent dcd583bbde
commit 2c1f9b84ff

View File

@@ -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]))