]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fs_encode: encode by [ptime] ms so we don't end up with partial frames, destroy codec...
authorMathieu Rene <mrene@avgs.ca>
Tue, 12 Oct 2010 19:48:24 +0000 (15:48 -0400)
committerMathieu Rene <mrene@avgs.ca>
Tue, 12 Oct 2010 19:48:33 +0000 (15:48 -0400)
src/fs_encode.c
src/switch_core_sqldb.c

index abfd23f22a5658e4aa5a64ef4ebd3ce3f5af8a17..6704077dfa31c2189238adf79025cadb0c187a1f 100644 (file)
@@ -64,10 +64,11 @@ int main(int argc, char *argv[])
        int rate = 8000;
        switch_file_handle_t fh_input = { 0 }, fh_output = { 0 };
        switch_codec_t codec = { 0 };
-       char buf[1024];
+       char buf[2048];
        switch_size_t len = sizeof(buf)/2;
        switch_memory_pool_t *pool;
        int bitrate = 0;
+       int blocksize;
        
        for (i = 1; i < argc; i++) {
                if (argv[i][0] == '-') {
@@ -169,9 +170,16 @@ int main(int argc, char *argv[])
                fprintf(stderr, "Couldn't initialize codec for %s@%dh@%di\n", format, rate, ptime);
                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) {
-               char encode_buf[1024];
+               char encode_buf[2048];
                uint32_t encoded_len = sizeof(buf);
                uint32_t encoded_rate = rate;
                unsigned int flags = 0;
@@ -182,18 +190,25 @@ int main(int argc, char *argv[])
                }
                
                len = encoded_len;
+
                if (switch_core_file_write(&fh_output, encode_buf, &len) != SWITCH_STATUS_SUCCESS) {
                        fprintf(stderr, "Write error\n");
                        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;
 
 end:
        
+       switch_core_codec_destroy(&codec);
+       
        if (fh_input.file_interface) {
                switch_core_file_close(&fh_input);              
        }
index c467a23a625e1ea5ed9cae7fa3fb327beff1ec2d..7f995040e97b2fcbee079d4edd4d51bb50c7fa3d 100644 (file)
@@ -62,6 +62,10 @@ SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t
 {
        switch_cache_db_connection_options_t options = { {0} };
        switch_status_t r;
+       
+       if (!sql_manager.manage) {
+               return SWITCH_STATUS_FALSE;
+       }
 
        if (!zstr(runtime.odbc_dsn)) {
                options.odbc_options.dsn = runtime.odbc_dsn;