aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-20 20:18:25 +0000
committerqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-20 20:18:25 +0000
commit2846dafde0b1af86474aff29a2ebbc4376e183a3 (patch)
tree96b45efb676fd29cf60f6d1dcd919b4fdfc8e296 /res
parentcd937b3b07bf42588c703c1d779c1ecb51b774c4 (diff)
Fix a bug in the CLI reverbification, as pointed out by ZX81 in #asterisk-dev
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@43361 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_convert.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/res/res_convert.c b/res/res_convert.c
index ed2c6465a..38d3e5399 100644
--- a/res/res_convert.c
+++ b/res/res_convert.c
@@ -54,7 +54,7 @@ static int split_ext(char *filename, char **name, char **ext)
}
/*! \brief Convert a file from one format to another */
-static int cli_audio_convert(int fd, int argc, char *argv[])
+static int cli_audio_convert_deprecated(int fd, int argc, char *argv[])
{
int ret = RESULT_FAILURE;
struct ast_filestream *fs_in = NULL, *fs_out = NULL;
@@ -121,6 +121,73 @@ fail_out:
return ret;
}
+static int cli_audio_convert(int fd, int argc, char *argv[])
+{
+ int ret = RESULT_FAILURE;
+ struct ast_filestream *fs_in = NULL, *fs_out = NULL;
+ struct ast_frame *f;
+ struct timeval start;
+ int cost;
+ char *file_in = NULL, *file_out = NULL;
+ char *name_in, *ext_in, *name_out, *ext_out;
+
+ /* ugly, can be removed when CLI entries have ast_module pointers */
+ ast_module_ref(ast_module_info->self);
+
+ if (argc != 4 || ast_strlen_zero(argv[2]) || ast_strlen_zero(argv[3])) {
+ ret = RESULT_SHOWUSAGE;
+ goto fail_out;
+ }
+
+ file_in = ast_strdupa(argv[2]);
+ file_out = ast_strdupa(argv[3]);
+
+ if (split_ext(file_in, &name_in, &ext_in)) {
+ ast_cli(fd, "'%s' is an invalid filename!\n", argv[2]);
+ goto fail_out;
+ }
+ if (!(fs_in = ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) {
+ ast_cli(fd, "Unable to open input file: %s\n", argv[2]);
+ goto fail_out;
+ }
+
+ if (split_ext(file_out, &name_out, &ext_out)) {
+ ast_cli(fd, "'%s' is an invalid filename!\n", argv[3]);
+ goto fail_out;
+ }
+ if (!(fs_out = ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) {
+ ast_cli(fd, "Unable to open output file: %s\n", argv[3]);
+ goto fail_out;
+ }
+
+ start = ast_tvnow();
+
+ while ((f = ast_readframe(fs_in))) {
+ if (ast_writestream(fs_out, f)) {
+ ast_cli(fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out);
+ goto fail_out;
+ }
+ }
+
+ cost = ast_tvdiff_ms(ast_tvnow(), start);
+ ast_cli(fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost);
+ ret = RESULT_SUCCESS;
+
+fail_out:
+ if (fs_out) {
+ ast_closestream(fs_out);
+ if (ret != RESULT_SUCCESS)
+ ast_filedelete(name_out, ext_out);
+ }
+
+ if (fs_in)
+ ast_closestream(fs_in);
+
+ ast_module_unref(ast_module_info->self);
+
+ return ret;
+}
+
static char usage_audio_convert[] =
"Usage: file convert <file_in> <file_out>\n"
" Convert from file_in to file_out. If an absolute path is not given, the\n"
@@ -130,7 +197,7 @@ static char usage_audio_convert[] =
static struct ast_cli_entry cli_convert_deprecated = {
{ "convert" , NULL },
- cli_audio_convert, NULL,
+ cli_audio_convert_deprecated, NULL,
NULL };
static struct ast_cli_entry cli_convert[] = {