33 #define _XOPEN_SOURCE 600
38 #include <sys/resource.h>
46 #pragma warning (disable:167)
56 int main(
int argc,
char *argv[])
60 const char *err = NULL;
62 char *extra_modules[100] = { 0 };
63 int extra_modules_count = 0;
65 const char *fmtp =
"";
67 const char *input, *output, *format = NULL;
82 for (i = 1; i < argc; i++) {
83 if (argv[i][0] ==
'-') {
109 if (strchr(argv[i],
',')) {
110 extra_modules_count =
switch_split(argv[i],
',', extra_modules);
112 extra_modules_count = 1;
113 extra_modules[0] = argv[i];
120 ptime = atoi(argv[++i]);
123 rate = atoi(argv[++i]);
126 bitrate = atoi(argv[++i]);
132 printf(
"Command line option not recognized: %s\n", argv[i]);
140 if (argc - i < 2 || cmd_fail) {
146 if (
zstr(input) ||
zstr(output) || !(format = strchr(output,
'.'))) {
153 fprintf(stderr,
"Cannot init core [%s]\n", err);
162 for (i = 0; i < extra_modules_count; i++) {
164 fprintf(stderr,
"Cannot init %s [%s]\n", extra_modules[i], err);
170 fprintf(stderr,
"Cannot init mod_spandsp [%s]\n", err);
175 fprintf(stderr,
"Cannot init mod_sndfile [%s]\n", err);
180 fprintf(stderr,
"Cannot init mod_native_file [%s]\n", err);
186 fprintf(stderr,
"Opening file %s\n", input);
189 fprintf(stderr,
"Couldn't open %s\n", input);
195 fprintf(stderr,
"Opening file %s\n", output);
208 if (
switch_core_codec_init_with_bitrate(&codec, format, NULL, fmtp, rate, ptime, channels, bitrate,
SWITCH_CODEC_FLAG_ENCODE, NULL, pool) !=
SWITCH_STATUS_SUCCESS) {
209 fprintf(stderr,
"Couldn't initialize codec for %s@%dh@%di\n", format, rate, ptime);
215 if ((p = strchr(input,
'.'))) {
218 if (!p ||
switch_core_codec_init_with_bitrate(&codec, p, NULL, fmtp, rate, ptime, channels, bitrate,
SWITCH_CODEC_FLAG_ENCODE|
SWITCH_CODEC_FLAG_DECODE, NULL, pool) !=
SWITCH_STATUS_SUCCESS) {
219 fprintf(stderr,
"Couldn't initialize codec for %s@%dh@%di\n", p, rate, ptime);
223 if (
switch_core_codec_init_with_bitrate(&raw_codec,
"L16", NULL, fmtp, rate, ptime, channels, bitrate,
SWITCH_CODEC_FLAG_ENCODE|
SWITCH_CODEC_FLAG_DECODE, NULL, pool) !=
SWITCH_STATUS_SUCCESS) {
224 fprintf(stderr,
"Couldn't initialize codec for %s@%dh@%di\n",
"L16", rate, ptime);
233 fprintf(stderr,
"Couldn't open %s\n", output);
246 blocksize = len = (rate*ptime)/1000;
252 fprintf(stderr,
"Frame size is %d\n", blocksize);
256 char encode_buf[2048];
257 uint32_t encoded_len =
sizeof(
buf);
258 uint32_t encoded_rate = rate;
259 unsigned int flags = 0;
263 fprintf(stderr,
"Codec encoder error\n");
271 }
else if (in_asis) {
289 fprintf(stderr,
"Write error\n");
293 if (len != encoded_len) {
313 if (fh_output.file_interface) {
327 printf(
"Usage: %s [options] input output\n\n", argv[0]);
328 printf(
"The output must end in the format, e.g., myfile.SPEEX\n");
329 printf(
"\t\t -c path\t\t Path to the FS configurations.\n");
330 printf(
"\t\t -k path\t\t Path to the FS log directory\n");
331 printf(
"\t\t -l module[,module]\t Load additional modules (comma-separated)\n");
332 printf(
"\t\t -m path\t\t Path to the modules.\n");
333 printf(
"\t\t -f format\t\t fmtp to pass to the codec\n");
334 printf(
"\t\t -p ptime\t\t ptime to use while encoding\n");
335 printf(
"\t\t -r rate\t\t sampling rate\n");
336 printf(
"\t\t -b bitrate\t\t codec bitrate (if supported)\n");
337 printf(
"\t\t -v\t\t\t verbose\n");
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_loadable_module_load_module(char *dir, char *fname, switch_bool_t runtime, const char **err)
Load a module.
switch_file_interface_t * file_interface
switch_status_t switch_core_init(_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err)
Initilize the core.
switch_status_t switch_core_codec_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
Encode data using a codec handle.
#define switch_split(_data, _delim, _array)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
switch_status_t switch_core_codec_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
Decode data using a codec handle.
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
int main(int argc, char *argv[])
static const char usage[]
const switch_codec_implementation_t * implementation
switch_byte_t switch_byte_t * buf
uint32_t actual_samples_per_second
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_directories SWITCH_GLOBAL_dirs
switch_status_t switch_core_codec_init_with_bitrate(switch_codec_t *codec, const char *codec_name, const char *fmtp, const char *modname, uint32_t rate, int ms, int channels, uint32_t bitrate, uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
uint32_t encoded_bytes_per_packet
static void fs_encode_cleanup()
switch_status_t switch_loadable_module_init(switch_bool_t autoload)
Initilize the module backend and load all the modules.
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
const char * switch_stristr(const char *instr, const char *str)
#define SWITCH_SIZE_T_FMT