From 6f7e34abc3fe37ed51c281d7b6c65284c2635624 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Apr 2009 02:04:48 +0000 Subject: [PATCH] make a little more optimal git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13158 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_loopback/mod_loopback.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index d8a18dd737..1f8a33a9d1 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -36,6 +36,8 @@ #include #include +#define FRAME_QUEUE_LEN 3 + SWITCH_MODULE_LOAD_FUNCTION(mod_loopback_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_loopback_shutdown); SWITCH_MODULE_DEFINITION(mod_loopback, mod_loopback_load, mod_loopback_shutdown, NULL); @@ -187,7 +189,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_core_session_set_private(session, tech_pvt); - switch_queue_create(&tech_pvt->frame_queue, 3, switch_core_session_get_pool(session)); + switch_queue_create(&tech_pvt->frame_queue, FRAME_QUEUE_LEN, switch_core_session_get_pool(session)); tech_pvt->session = session; tech_pvt->channel = switch_core_session_get_channel(session); } @@ -658,18 +660,21 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (switch_test_flag(tech_pvt, TFLAG_LINKED)) { switch_frame_t *clone; + if (frame->codec->implementation != tech_pvt->write_codec.implementation) { /* change codecs to match */ tech_init(tech_pvt, session, frame->codec); tech_init(tech_pvt->other_tech_pvt, tech_pvt->other_session, frame->codec); } - if (switch_frame_dup(frame, &clone) != SWITCH_STATUS_SUCCESS) { - abort(); - } + if (switch_queue_size(tech_pvt->other_tech_pvt->frame_queue) < FRAME_QUEUE_LEN) { + if (switch_frame_dup(frame, &clone) != SWITCH_STATUS_SUCCESS) { + abort(); + } - if (switch_queue_trypush(tech_pvt->other_tech_pvt->frame_queue, clone) != SWITCH_STATUS_SUCCESS) { - switch_frame_free(&clone); + if (switch_queue_trypush(tech_pvt->other_tech_pvt->frame_queue, clone) != SWITCH_STATUS_SUCCESS) { + switch_frame_free(&clone); + } } switch_set_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);