#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 = "f450f61f60e761b3aa089ebed76ca8a5" , .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 224 of file res_convert.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 224 of file res_convert.c.
static int cli_audio_convert | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 127 of file res_convert.c.
References ast_cli(), ast_closestream(), ast_filedelete(), 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().
00128 { 00129 int ret = RESULT_FAILURE; 00130 struct ast_filestream *fs_in = NULL, *fs_out = NULL; 00131 struct ast_frame *f; 00132 struct timeval start; 00133 int cost; 00134 char *file_in = NULL, *file_out = NULL; 00135 char *name_in, *ext_in, *name_out, *ext_out; 00136 00137 /* ugly, can be removed when CLI entries have ast_module pointers */ 00138 ast_module_ref(ast_module_info->self); 00139 00140 if (argc != 4 || ast_strlen_zero(argv[2]) || ast_strlen_zero(argv[3])) { 00141 ret = RESULT_SHOWUSAGE; 00142 goto fail_out; 00143 } 00144 00145 file_in = ast_strdupa(argv[2]); 00146 file_out = ast_strdupa(argv[3]); 00147 00148 if (split_ext(file_in, &name_in, &ext_in)) { 00149 ast_cli(fd, "'%s' is an invalid filename!\n", argv[2]); 00150 goto fail_out; 00151 } 00152 if (!(fs_in = ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) { 00153 ast_cli(fd, "Unable to open input file: %s\n", argv[2]); 00154 goto fail_out; 00155 } 00156 00157 if (split_ext(file_out, &name_out, &ext_out)) { 00158 ast_cli(fd, "'%s' is an invalid filename!\n", argv[3]); 00159 goto fail_out; 00160 } 00161 if (!(fs_out = ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, 0644))) { 00162 ast_cli(fd, "Unable to open output file: %s\n", argv[3]); 00163 goto fail_out; 00164 } 00165 00166 start = ast_tvnow(); 00167 00168 while ((f = ast_readframe(fs_in))) { 00169 if (ast_writestream(fs_out, f)) { 00170 ast_cli(fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out); 00171 goto fail_out; 00172 } 00173 } 00174 00175 cost = ast_tvdiff_ms(ast_tvnow(), start); 00176 ast_cli(fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost); 00177 ret = RESULT_SUCCESS; 00178 00179 fail_out: 00180 if (fs_out) { 00181 ast_closestream(fs_out); 00182 if (ret != RESULT_SUCCESS) 00183 ast_filedelete(name_out, ext_out); 00184 } 00185 00186 if (fs_in) 00187 ast_closestream(fs_in); 00188 00189 ast_module_unref(ast_module_info->self); 00190 00191 return ret; 00192 }
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_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_cli(fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out); 00104 goto fail_out; 00105 } 00106 } 00107 00108 cost = ast_tvdiff_ms(ast_tvnow(), start); 00109 ast_cli(fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost); 00110 ret = RESULT_SUCCESS; 00111 00112 fail_out: 00113 if (fs_out) { 00114 ast_closestream(fs_out); 00115 if (ret != RESULT_SUCCESS) 00116 ast_filedelete(name_out, ext_out); 00117 } 00118 00119 if (fs_in) 00120 ast_closestream(fs_in); 00121 00122 ast_module_unref(ast_module_info->self); 00123 00124 return ret; 00125 }
static int load_module | ( | void | ) | [static] |
Definition at line 218 of file res_convert.c.
References ast_cli_register_multiple(), and cli_convert.
00219 { 00220 ast_cli_register_multiple(cli_convert, sizeof(cli_convert) / sizeof(struct ast_cli_entry)); 00221 return 0; 00222 }
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 212 of file res_convert.c.
References ast_cli_unregister_multiple(), and cli_convert.
00213 { 00214 ast_cli_unregister_multiple(cli_convert, sizeof(cli_convert) / sizeof(struct ast_cli_entry)); 00215 return 0; 00216 }
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 = "f450f61f60e761b3aa089ebed76ca8a5" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 224 of file res_convert.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 224 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 206 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 201 of file res_convert.c.
char usage_audio_convert[] [static] |
Definition at line 194 of file res_convert.c.