FS-3910 It seems to have a problem keeping up with the realtime audio. Try this patch that introduces some prebuffering

This commit is contained in:
Anthony Minessale 2012-02-17 11:23:59 -06:00
parent 3a0cfa9aaa
commit f6941ca48f
4 changed files with 38 additions and 1 deletions

View 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;
};

View 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

View 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;
@ -189,6 +199,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
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)) {
return SWITCH_STATUS_FALSE;
@ -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);

View 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;