mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
file.c: Add ability to search custom dir for sounds
To better co-exist with sounds files that may be managed by
packages, custom sound files may now be placed in
AST_DATA_DIR/sounds/custom instead of the standard
AST_DATA_DIR/sounds/<lang> directory. If the new
"sounds_search_custom_dir" option in asterisk.conf is set
to "true", asterisk will search the custom directory for sounds
files before searching the standard directory. For performance
reasons, the "sounds_search_custom_dir" defaults to "false".
Resolves: #315
UserNote: A new option "sounds_search_custom_dir" has been added to
asterisk.conf that allows asterisk to search
AST_DATA_DIR/sounds/custom for sounds files before searching the
standard AST_DATA_DIR/sounds/<lang> directory.
(cherry picked from commit 0e0f99db1d
)
This commit is contained in:
committed by
Asterisk Development Team
parent
69338381ea
commit
dadbaed6f5
51
main/file.c
51
main/file.c
@@ -792,7 +792,8 @@ struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *file
|
||||
return ast_openstream_full(chan, filename, preflang, 0);
|
||||
}
|
||||
|
||||
struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis)
|
||||
struct ast_filestream *ast_openstream_full(struct ast_channel *chan,
|
||||
const char *filename, const char *preflang, int asis)
|
||||
{
|
||||
/*
|
||||
* Use fileexists_core() to find a file in a compatible
|
||||
@@ -844,7 +845,8 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang)
|
||||
struct ast_filestream *ast_openvstream(struct ast_channel *chan,
|
||||
const char *filename, const char *preflang)
|
||||
{
|
||||
/* As above, but for video. But here we don't have translators
|
||||
* so we must enforce a format.
|
||||
@@ -1288,22 +1290,41 @@ int ast_file_read_dirs(const char *dir_name, ast_file_on_file on_file, void *obj
|
||||
return res;
|
||||
}
|
||||
|
||||
int ast_streamfile(struct ast_channel *chan, const char *filename, const char *preflang)
|
||||
int ast_streamfile(struct ast_channel *chan, const char *filename,
|
||||
const char *preflang)
|
||||
{
|
||||
struct ast_filestream *fs;
|
||||
struct ast_filestream *vfs=NULL;
|
||||
struct ast_filestream *fs = NULL;
|
||||
struct ast_filestream *vfs = NULL;
|
||||
off_t pos;
|
||||
int seekattempt;
|
||||
int res;
|
||||
char custom_filename[256];
|
||||
char *tmp_filename;
|
||||
|
||||
/* If file with the same name exists in /var/lib/asterisk/sounds/custom directory, use that file.
|
||||
* Otherwise, use the original file*/
|
||||
|
||||
if (ast_opt_sounds_search_custom && !is_absolute_path(filename)) {
|
||||
memset(custom_filename, 0, sizeof(custom_filename));
|
||||
snprintf(custom_filename, sizeof(custom_filename), "custom/%s", filename);
|
||||
fs = ast_openstream(chan, custom_filename, preflang);
|
||||
if (fs) {
|
||||
tmp_filename = custom_filename;
|
||||
ast_debug(3, "Found file %s in custom directory\n", filename);
|
||||
}
|
||||
}
|
||||
|
||||
fs = ast_openstream(chan, filename, preflang);
|
||||
if (!fs) {
|
||||
struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
|
||||
ast_channel_lock(chan);
|
||||
ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n",
|
||||
filename, ast_format_cap_get_names(ast_channel_nativeformats(chan), &codec_buf), strerror(errno));
|
||||
ast_channel_unlock(chan);
|
||||
return -1;
|
||||
fs = ast_openstream(chan, filename, preflang);
|
||||
if (!fs) {
|
||||
struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
|
||||
ast_channel_lock(chan);
|
||||
ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n",
|
||||
filename, ast_format_cap_get_names(ast_channel_nativeformats(chan), &codec_buf), strerror(errno));
|
||||
ast_channel_unlock(chan);
|
||||
return -1;
|
||||
}
|
||||
tmp_filename = (char *)filename;
|
||||
}
|
||||
|
||||
/* check to see if there is any data present (not a zero length file),
|
||||
@@ -1322,7 +1343,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p
|
||||
fseeko(fs->f, pos, SEEK_SET);
|
||||
}
|
||||
|
||||
vfs = ast_openvstream(chan, filename, preflang);
|
||||
vfs = ast_openvstream(chan, tmp_filename, preflang);
|
||||
if (vfs) {
|
||||
ast_debug(1, "Ooh, found a video stream, too, format %s\n", ast_format_get_name(vfs->fmt->format));
|
||||
}
|
||||
@@ -1333,14 +1354,14 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p
|
||||
return -1;
|
||||
if (vfs && ast_applystream(chan, vfs))
|
||||
return -1;
|
||||
ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", filename, ast_channel_name(chan));
|
||||
ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", tmp_filename, ast_channel_name(chan));
|
||||
res = ast_playstream(fs);
|
||||
if (!res && vfs)
|
||||
res = ast_playstream(vfs);
|
||||
|
||||
if (VERBOSITY_ATLEAST(3)) {
|
||||
ast_channel_lock(chan);
|
||||
ast_verb(3, "<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), filename, ast_format_get_name(ast_channel_writeformat(chan)), preflang ? preflang : "default");
|
||||
ast_verb(3, "<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), tmp_filename, ast_format_get_name(ast_channel_writeformat(chan)), preflang ? preflang : "default");
|
||||
ast_channel_unlock(chan);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user