diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/app.c | 12 | ||||
-rw-r--r-- | main/file.c | 60 |
2 files changed, 66 insertions, 6 deletions
diff --git a/main/app.c b/main/app.c index 2c448d549..2beee00a3 100644 --- a/main/app.c +++ b/main/app.c @@ -51,7 +51,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/indications.h" #include "asterisk/linkedlists.h" -#define MAX_OTHER_FORMATS 10 +#define AST_MAX_FORMATS 10 static AST_LIST_HEAD_STATIC(groups, ast_group_info); @@ -507,8 +507,8 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, char *fmts; char comment[256]; int x, fmtcnt = 1, res = -1, outmsg = 0; - struct ast_filestream *others[MAX_OTHER_FORMATS]; - char *sfmt[MAX_OTHER_FORMATS]; + struct ast_filestream *others[AST_MAX_FORMATS]; + char *sfmt[AST_MAX_FORMATS]; char *stringp = NULL; time_t start, end; struct ast_dsp *sildet = NULL; /* silence detector dsp */ @@ -556,8 +556,8 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, sfmt[0] = ast_strdupa(fmts); while ((fmt = strsep(&stringp, "|"))) { - if (fmtcnt > MAX_OTHER_FORMATS - 1) { - ast_log(LOG_WARNING, "Please increase MAX_OTHER_FORMATS in app.c\n"); + if (fmtcnt > AST_MAX_FORMATS - 1) { + ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n"); break; } sfmt[fmtcnt++] = ast_strdupa(fmt); @@ -747,7 +747,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, } if (prepend && outmsg) { - struct ast_filestream *realfiles[MAX_OTHER_FORMATS]; + struct ast_filestream *realfiles[AST_MAX_FORMATS]; struct ast_frame *fr; for (x = 0; x < fmtcnt; x++) { diff --git a/main/file.c b/main/file.c index 57282c316..6631112c4 100644 --- a/main/file.c +++ b/main/file.c @@ -1358,6 +1358,66 @@ int ast_stream_and_wait(struct ast_channel *chan, const char *file, return res; } +char *ast_format_str_reduce(char *fmts) +{ + struct ast_format *f; + struct ast_format *fmts_ptr[AST_MAX_FORMATS]; + char *fmts_str[AST_MAX_FORMATS]; + char *stringp, *type; + char *orig = fmts; + int i, j, x, found; + int len = strlen(fmts) + 1; + + if (AST_LIST_LOCK(&formats)) { + ast_log(LOG_WARNING, "Unable to lock format list\n"); + return NULL; + } + + stringp = ast_strdupa(fmts); + + for (x = 0; (type = strsep(&stringp, "|")) && x < AST_MAX_FORMATS; x++) { + AST_LIST_TRAVERSE(&formats, f, list) { + if (exts_compare(f->exts, type)) { + found = 1; + break; + } + } + + fmts_str[x] = type; + if (found) { + fmts_ptr[x] = f; + } else { + fmts_ptr[x] = NULL; + } + } + AST_LIST_UNLOCK(&formats); + + for (i = 0; i < x; i++) { + /* special handling for the first entry */ + if (i == 0) { + fmts += snprintf(fmts, len, "%s", fmts_str[i]); + len -= (fmts - orig); + continue; + } + + found = 0; + for (j = 0; j < i; j++) { + /* this is a duplicate */ + if (fmts_ptr[j] == fmts_ptr[i]) { + found = 1; + break; + } + } + + if (!found) { + fmts += snprintf(fmts, len, "|%s", fmts_str[i]); + len -= (fmts - orig); + } + } + + return orig; +} + static int show_file_formats(int fd, int argc, char *argv[]) { #define FORMAT "%-10s %-10s %-20s\n" |