[Freeswitch-svn] [commit] r13158 - freeswitch/trunk/src/mod/endpoints/mod_loopback

FreeSWITCH SVN anthm at freeswitch.org
Sun Apr 26 19:04:48 PDT 2009


Author: anthm
Date: Sun Apr 26 21:04:48 2009
New Revision: 13158

Log:
make a little more optimal

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c

Modified: freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c	Sun Apr 26 21:04:48 2009
@@ -36,6 +36,8 @@
 #include <math.h>
 #include <string.h>
 
+#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 @@
 		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 @@
 
 	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);



More information about the Freeswitch-svn mailing list