]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3910 It seems to have a problem keeping up with the realtime audio. Try this...
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 17 Feb 2012 17:23:59 +0000 (11:23 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 17 Feb 2012 17:23:59 +0000 (11:23 -0600)
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/switch_core_media_bug.c
src/switch_ivr_async.c

index 7e3659b09d4957c1fe2065169f7bda1f152347fa..ff0a6189b907c90eaa68ed52cc07c102276358e2 100644 (file)
@@ -196,6 +196,8 @@ struct switch_media_bug {
        switch_codec_implementation_t read_impl;
        switch_codec_implementation_t write_impl;
        uint32_t record_frame_size;
+       uint32_t record_pre_buffer_count;
+       uint32_t record_pre_buffer_max;
        switch_frame_t *ping_frame;
        struct switch_media_bug *next;
 };
index 2558e1bb19bacafd9ed7418cf185b058823dca52..517e13ed94343497592e74d5cd3ad4e4f1106956 100644 (file)
@@ -270,6 +270,8 @@ SWITCH_DECLARE(void) switch_core_media_bug_flush(_In_ switch_media_bug_t *bug);
 */
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(_In_ switch_core_session_t *session);
 
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_set_pre_buffer_framecount(switch_media_bug_t *bug, uint32_t framecount);
+
 ///\}
 
 ///\defgroup pa1 Port Allocation
index c01d823963af985b7f8b46055107d18745b6ff9d..0397aa666b713a56d78f7792f406da96dd0c2160 100644 (file)
@@ -112,6 +112,9 @@ SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *b
 
 SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
 {
+
+       bug->record_pre_buffer_count = 0;
+
        if (bug->raw_read_buffer) {
                switch_mutex_lock(bug->read_mutex);
                switch_buffer_zero(bug->raw_read_buffer);
@@ -144,6 +147,13 @@ SWITCH_DECLARE(void) switch_core_media_bug_inuse(switch_media_bug_t *bug, switch
        }
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_set_pre_buffer_framecount(switch_media_bug_t *bug, uint32_t framecount)
+{
+       bug->record_pre_buffer_max = framecount;
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame, switch_bool_t fill)
 {
        switch_size_t bytes = 0, datalen = 0;
@@ -188,6 +198,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
                do_write = switch_buffer_inuse(bug->raw_write_buffer);
                switch_mutex_unlock(bug->write_mutex);
        }
+
+       if (bug->record_frame_size && bug->record_pre_buffer_max && (do_read || do_write) && bug->record_pre_buffer_count < bug->record_pre_buffer_max) {
+               bug->record_pre_buffer_count++;
+               return SWITCH_STATUS_FALSE;
+       }
        
        if (bug->record_frame_size) {
                if ((do_read && do_read < bug->record_frame_size) || (do_write && do_write < bug->record_frame_size)) {
@@ -212,7 +227,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
                        bug->record_frame_size = do_read;
                }
        }
-       
+
        fill_read = !do_read;
        fill_write = !do_write;
 
@@ -220,6 +235,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
                return SWITCH_STATUS_FALSE;
        }
 
+       if (do_read && do_read > SWITCH_RECOMMENDED_BUFFER_SIZE) {
+               do_read = 1280;
+       }
+
+       if (do_write && do_write > SWITCH_RECOMMENDED_BUFFER_SIZE) {
+               do_write = 1280;
+       }
+       
        if (do_read) {
                switch_mutex_lock(bug->read_mutex);
                frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, do_read);
index 7b6cd1271c20bb4c024516d35fd2605e66b4c479..9971ab68e00ef63a98fab67b7edd6cc93cef184c 100644 (file)
@@ -1765,6 +1765,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
                return status;
        }
 
+       if ((p = switch_channel_get_variable(channel, "RECORD_PRE_BUFFER_FRAMES"))) {
+               int tmp = atoi(p);
+               
+               if (tmp > 0) {
+                       switch_core_media_bug_set_pre_buffer_framecount(bug, tmp);
+               }
+       } else {
+               switch_core_media_bug_set_pre_buffer_framecount(bug, 25);
+       }
+
        switch_channel_set_private(channel, file, bug);
 
        return SWITCH_STATUS_SUCCESS;