mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-22 11:53:16 +00:00
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:
parent
3a0cfa9aaa
commit
f6941ca48f
@ -196,6 +196,8 @@ struct switch_media_bug {
|
|||||||
switch_codec_implementation_t read_impl;
|
switch_codec_implementation_t read_impl;
|
||||||
switch_codec_implementation_t write_impl;
|
switch_codec_implementation_t write_impl;
|
||||||
uint32_t record_frame_size;
|
uint32_t record_frame_size;
|
||||||
|
uint32_t record_pre_buffer_count;
|
||||||
|
uint32_t record_pre_buffer_max;
|
||||||
switch_frame_t *ping_frame;
|
switch_frame_t *ping_frame;
|
||||||
struct switch_media_bug *next;
|
struct switch_media_bug *next;
|
||||||
};
|
};
|
||||||
|
@ -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_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
|
///\defgroup pa1 Port Allocation
|
||||||
|
@ -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)
|
SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
bug->record_pre_buffer_count = 0;
|
||||||
|
|
||||||
if (bug->raw_read_buffer) {
|
if (bug->raw_read_buffer) {
|
||||||
switch_mutex_lock(bug->read_mutex);
|
switch_mutex_lock(bug->read_mutex);
|
||||||
switch_buffer_zero(bug->raw_read_buffer);
|
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_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;
|
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);
|
do_write = switch_buffer_inuse(bug->raw_write_buffer);
|
||||||
switch_mutex_unlock(bug->write_mutex);
|
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 (bug->record_frame_size) {
|
||||||
if ((do_read && do_read < bug->record_frame_size) || (do_write && do_write < 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;
|
bug->record_frame_size = do_read;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fill_read = !do_read;
|
fill_read = !do_read;
|
||||||
fill_write = !do_write;
|
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;
|
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) {
|
if (do_read) {
|
||||||
switch_mutex_lock(bug->read_mutex);
|
switch_mutex_lock(bug->read_mutex);
|
||||||
frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, do_read);
|
frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, do_read);
|
||||||
|
@ -1765,6 +1765,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
|
|||||||
return status;
|
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);
|
switch_channel_set_private(channel, file, bug);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user