AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17),
/*! Suppress some warnings */
AST_OPT_FLAG_DONT_WARN = (1 << 18),
+ /*! Search custom directory for sounds first */
+ AST_OPT_FLAG_SOUNDS_SEARCH_CUSTOM = (1 << 19),
/*! Reference Debugging */
AST_OPT_FLAG_REF_DEBUG = (1 << 20),
/*! Always fork, even if verbose or debug settings are non-zero */
#define ast_opt_ref_debug ast_test_flag(&ast_options, AST_OPT_FLAG_REF_DEBUG)
#define ast_opt_generic_plc_on_equal_codecs ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS)
#define ast_opt_hide_messaging_ami_events ast_test_flag(&ast_options, AST_OPT_FLAG_HIDE_MESSAGING_AMI_EVENTS)
+#define ast_opt_sounds_search_custom ast_test_flag(&ast_options, AST_OPT_FLAG_SOUNDS_SEARCH_CUSTOM)
/*! Maximum log level defined by PJPROJECT. */
#define MAX_PJ_LOG_MAX_LEVEL 6
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
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.
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),
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));
}
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);
}