fs_encode: encode by [ptime] ms so we don't end up with partial frames, destroy codec when done
This commit is contained in:
parent
69555111d7
commit
3c4d7f1d48
|
@ -64,10 +64,11 @@ int main(int argc, char *argv[])
|
||||||
int rate = 8000;
|
int rate = 8000;
|
||||||
switch_file_handle_t fh_input = { 0 }, fh_output = { 0 };
|
switch_file_handle_t fh_input = { 0 }, fh_output = { 0 };
|
||||||
switch_codec_t codec = { 0 };
|
switch_codec_t codec = { 0 };
|
||||||
char buf[1024];
|
char buf[2048];
|
||||||
switch_size_t len = sizeof(buf)/2;
|
switch_size_t len = sizeof(buf)/2;
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
int bitrate = 0;
|
int bitrate = 0;
|
||||||
|
int blocksize;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
|
@ -170,8 +171,15 @@ int main(int argc, char *argv[])
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blocksize = len = (rate*ptime)/1000;
|
||||||
|
switch_assert(sizeof(buf) >= len * 2);
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
printf("Frame size is %d\n", blocksize);
|
||||||
|
}
|
||||||
|
|
||||||
while (switch_core_file_read(&fh_input, buf, &len) == SWITCH_STATUS_SUCCESS) {
|
while (switch_core_file_read(&fh_input, buf, &len) == SWITCH_STATUS_SUCCESS) {
|
||||||
char encode_buf[1024];
|
char encode_buf[2048];
|
||||||
uint32_t encoded_len = sizeof(buf);
|
uint32_t encoded_len = sizeof(buf);
|
||||||
uint32_t encoded_rate = rate;
|
uint32_t encoded_rate = rate;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
@ -182,18 +190,25 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
len = encoded_len;
|
len = encoded_len;
|
||||||
|
|
||||||
if (switch_core_file_write(&fh_output, encode_buf, &len) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_file_write(&fh_output, encode_buf, &len) != SWITCH_STATUS_SUCCESS) {
|
||||||
fprintf(stderr, "Write error\n");
|
fprintf(stderr, "Write error\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = sizeof(buf)/2;
|
if (len != encoded_len) {
|
||||||
|
printf("Short write: wrote %"SWITCH_SIZE_T_FMT"/%d bytes\n", len, encoded_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = blocksize;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
|
switch_core_codec_destroy(&codec);
|
||||||
|
|
||||||
if (fh_input.file_interface) {
|
if (fh_input.file_interface) {
|
||||||
switch_core_file_close(&fh_input);
|
switch_core_file_close(&fh_input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,10 @@ SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t
|
||||||
switch_cache_db_connection_options_t options = { {0} };
|
switch_cache_db_connection_options_t options = { {0} };
|
||||||
switch_status_t r;
|
switch_status_t r;
|
||||||
|
|
||||||
|
if (!sql_manager.manage) {
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!zstr(runtime.odbc_dsn)) {
|
if (!zstr(runtime.odbc_dsn)) {
|
||||||
options.odbc_options.dsn = runtime.odbc_dsn;
|
options.odbc_options.dsn = runtime.odbc_dsn;
|
||||||
options.odbc_options.user = runtime.odbc_user;
|
options.odbc_options.user = runtime.odbc_user;
|
||||||
|
|
Loading…
Reference in New Issue