#include "asterisk.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/file.h"
Go to the source code of this file.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | cli_audio_convert (int fd, int argc, char *argv[]) |
static int | cli_audio_convert_deprecated (int fd, int argc, char *argv[]) |
Convert a file from one format to another. | |
static int | load_module (void) |
static int | split_ext (char *filename, char **name, char **ext) |
Split the filename to basename and extension. | |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "File format conversion CLI command" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_convert [] |
static struct ast_cli_entry | cli_convert_deprecated |
static char | usage_audio_convert [] |
Russell Bryant <russell@digium.com>
Definition in file res_convert.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 228 of file res_convert.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 228 of file res_convert.c.
static int cli_audio_convert | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 129 of file res_convert.c.
References ast_cli(), ast_closestream(), ast_filedelete(), ast_frfree, ast_module_ref(), ast_module_unref(), ast_readfile(), ast_readframe(), ast_strdupa, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_writefile(), ast_writestream(), f, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and split_ext().
00130 { 00131 int ret = RESULT_FAILURE; 00132 struct ast_filestream *fs_in = NULL, *fs_out = NULL; 00133 struct ast_frame *f; 00134 struct timeval start; 00135 int cost; 00136 char *file_in = NULL, *file_out = NULL; 00137 char *name_in, *ext_in, *name_out, *ext_out; 00138 00139 /* ugly, can be removed when CLI entries have ast_module pointers */ 00140 ast_module_ref(ast_module_info->self); 00141 00142 if (argc != 4 || ast_strlen_zero(argv[2]) || ast_strlen_zero(argv[3])) { 00143 ret = RESULT_SHOWUSAGE; 00144 goto fail_out; 00145 } 00146 00147 file_in = ast_strdupa(argv[2]); 00148 file_out = ast_strdupa(argv[3]); 00149 00150 if (split_ext(file_in, &name_in, &ext_in)) { 00151 ast_cli(fd, "'%s' is an invalid filename!\n", argv[2]); 00152 goto fail_out; 00153 } 00154 if (!(fs_in = ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) { 00155 ast_cli(fd, "Unable to open input file: %s\n", argv[2]); 00156 goto fail_out; 00157 } 00158 00159 if (split_ext(file_out, &name_out, &ext_out)) { 00160 ast_cli(fd, "'%s' is an invalid filename!\n", argv[3]); 00161 goto fail_out; 00162 } 00163 if (!(fs_out = ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) { 00164 ast_cli(fd, "Unable to open output file: %s\n", argv[3]); 00165 goto fail_out; 00166 } 00167 00168 start = ast_tvnow(); 00169 00170 while ((f = ast_readframe(fs_in))) { 00171 if (ast_writestream(fs_out, f)) { 00172 ast_frfree(f); 00173 ast_cli(fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out); 00174 goto fail_out; 00175 } 00176 ast_frfree(f); 00177 } 00178 00179 cost = ast_tvdiff_ms(ast_tvnow(), start); 00180 ast_cli(fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost); 00181 ret = RESULT_SUCCESS; 00182 00183 fail_out: 00184 if (fs_out) { 00185 ast_closestream(fs_out); 00186 if (ret != RESULT_SUCCESS) 00187 ast_filedelete(name_out, ext_out); 00188 } 00189 00190 if (fs_in) 00191 ast_closestream(fs_in); 00192 00193 ast_module_unref(ast_module_info->self); 00194 00195 return ret; 00196 }
static int cli_audio_convert_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Convert a file from one format to another.
Definition at line 60 of file res_convert.c.
References ast_cli(), ast_closestream(), ast_filedelete(), ast_frfree, ast_module_ref(), ast_module_unref(), ast_readfile(), ast_readframe(), ast_strdupa, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_writefile(), ast_writestream(), f, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and split_ext().
00061 { 00062 int ret = RESULT_FAILURE; 00063 struct ast_filestream *fs_in = NULL, *fs_out = NULL; 00064 struct ast_frame *f; 00065 struct timeval start; 00066 int cost; 00067 char *file_in = NULL, *file_out = NULL; 00068 char *name_in, *ext_in, *name_out, *ext_out; 00069 00070 /* ugly, can be removed when CLI entries have ast_module pointers */ 00071 ast_module_ref(ast_module_info->self); 00072 00073 if (argc != 3 || ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2])) { 00074 ret = RESULT_SHOWUSAGE; 00075 goto fail_out; 00076 } 00077 00078 file_in = ast_strdupa(argv[1]); 00079 file_out = ast_strdupa(argv[2]); 00080 00081 if (split_ext(file_in, &name_in, &ext_in)) { 00082 ast_cli(fd, "'%s' is an invalid filename!\n", argv[1]); 00083 goto fail_out; 00084 } 00085 if (!(fs_in = ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) { 00086 ast_cli(fd, "Unable to open input file: %s\n", argv[1]); 00087 goto fail_out; 00088 } 00089 00090 if (split_ext(file_out, &name_out, &ext_out)) { 00091 ast_cli(fd, "'%s' is an invalid filename!\n", argv[2]); 00092 goto fail_out; 00093 } 00094 if (!(fs_out = ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) { 00095 ast_cli(fd, "Unable to open output file: %s\n", argv[2]); 00096 goto fail_out; 00097 } 00098 00099 start = ast_tvnow(); 00100 00101 while ((f = ast_readframe(fs_in))) { 00102 if (ast_writestream(fs_out, f)) { 00103 ast_frfree(f); 00104 ast_cli(fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out); 00105 goto fail_out; 00106 } 00107 ast_frfree(f); 00108 } 00109 00110 cost = ast_tvdiff_ms(ast_tvnow(), start); 00111 ast_cli(fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost); 00112 ret = RESULT_SUCCESS; 00113 00114 fail_out: 00115 if (fs_out) { 00116 ast_closestream(fs_out); 00117 if (ret != RESULT_SUCCESS) 00118 ast_filedelete(name_out, ext_out); 00119 } 00120 00121 if (fs_in) 00122 ast_closestream(fs_in); 00123 00124 ast_module_unref(ast_module_info->self); 00125 00126 return ret; 00127 }
static int load_module | ( | void | ) | [static] |
Definition at line 222 of file res_convert.c.
References ast_cli_register_multiple(), and cli_convert.
00223 { 00224 ast_cli_register_multiple(cli_convert, sizeof(cli_convert) / sizeof(struct ast_cli_entry)); 00225 return 0; 00226 }
static int split_ext | ( | char * | filename, | |
char ** | name, | |||
char ** | ext | |||
) | [static] |
Split the filename to basename and extension.
Definition at line 44 of file res_convert.c.
References ast_strlen_zero().
Referenced by cli_audio_convert(), and cli_audio_convert_deprecated().
00045 { 00046 *name = *ext = filename; 00047 00048 if ((*ext = strrchr(filename, '.'))) { 00049 **ext = '\0'; 00050 (*ext)++; 00051 } 00052 00053 if (ast_strlen_zero(*name) || ast_strlen_zero(*ext)) 00054 return -1; 00055 00056 return 0; 00057 }
static int unload_module | ( | void | ) | [static] |
Definition at line 216 of file res_convert.c.
References ast_cli_unregister_multiple(), and cli_convert.
00217 { 00218 ast_cli_unregister_multiple(cli_convert, sizeof(cli_convert) / sizeof(struct ast_cli_entry)); 00219 return 0; 00220 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "File format conversion CLI command" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 228 of file res_convert.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 228 of file res_convert.c.
struct ast_cli_entry cli_convert[] [static] |
Initial value:
{ { { "file", "convert" , NULL }, cli_audio_convert, "Convert audio file", usage_audio_convert, NULL, &cli_convert_deprecated }, }
Definition at line 210 of file res_convert.c.
Referenced by load_module(), and unload_module().
struct ast_cli_entry cli_convert_deprecated [static] |
Initial value:
{ { "convert" , NULL }, cli_audio_convert_deprecated, NULL, NULL }
Definition at line 205 of file res_convert.c.
char usage_audio_convert[] [static] |
Definition at line 198 of file res_convert.c.