Convert a file from one format to another.
65{
69 struct timeval start;
70 int cost;
71 char *file_in =
NULL, *file_out =
NULL;
72 char *name_in, *ext_in, *name_out, *ext_out;
73
74 switch (cmd) {
78 "Usage: file convert <file_in> <file_out>\n"
79 " Convert from file_in to file_out. If an absolute path\n"
80 " is not given, the default Asterisk sounds directory\n"
81 " will be used.\n\n"
82 " Example:\n"
83 " file convert tt-weasels.gsm tt-weasels.ulaw\n";
87 }
88
91 goto fail_out;
92 }
93
96
97 if (
split_ext(file_in, &name_in, &ext_in)) {
98 ast_cli(
a->fd,
"'%s' is an invalid filename!\n",
a->argv[2]);
99 goto fail_out;
100 }
102 ast_cli(
a->fd,
"Unable to open input file: %s\n",
a->argv[2]);
103 goto fail_out;
104 }
105
106 if (
split_ext(file_out, &name_out, &ext_out)) {
107 ast_cli(
a->fd,
"'%s' is an invalid filename!\n",
a->argv[3]);
108 goto fail_out;
109 }
111 ast_cli(
a->fd,
"Unable to open output file: %s\n",
a->argv[3]);
112 goto fail_out;
113 }
114
116
120 ast_cli(
a->fd,
"Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out);
121 goto fail_out;
122 }
124 }
125
127 ast_cli(
a->fd,
"Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost);
129
130fail_out:
131 if (fs_out) {
135 }
136
137 if (fs_in)
139
140 return ret;
141}
#define ast_strdupa(s)
duplicate a string in memory from the stack
void ast_cli(int fd, const char *fmt,...)
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
struct ast_filestream * ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts reading from a file.
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
int ast_closestream(struct ast_filestream *f)
Closes a stream.
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
static int split_ext(char *filename, char **name, char **ext)
Split the filename to basename and extension.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Data structure associated with a single frame of data.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().