[Freeswitch-svn] [commit] r7475 - in freeswitch/trunk/src: . mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Fri Feb 1 16:22:28 EST 2008


Author: anthm
Date: Fri Feb  1 16:22:27 2008
New Revision: 7475

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/trunk/src/switch_ivr_async.c
   freeswitch/trunk/src/switch_ivr_bridge.c

Log:
it's suprising what 195 lines of code can do

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Fri Feb  1 16:22:27 2008
@@ -1294,7 +1294,7 @@
 			/* Reactivate the NAT buster flag. */
 			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
 		}
-		return SWITCH_STATUS_SUCCESS;
+        goto video;
 	}
 
 	tech_pvt->rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip,
@@ -1398,6 +1398,7 @@
 			switch_channel_set_variable(tech_pvt->channel, SOFIA_SECURE_MEDIA_CONFIRMED_VARIABLE, "true");
 		}
 
+    video:
 
 		sofia_glue_check_video_codecs(tech_pvt);
 
@@ -1496,7 +1497,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	const char *val;
 	const char *crypto = NULL;
-	int got_crypto = 0;
+	int got_crypto = 0, got_audio = 0;
 
 	switch_assert(tech_pvt != NULL);
 
@@ -1578,7 +1579,7 @@
 
 		ptime = dptime;
 
-		if (m->m_type == sdp_media_audio) {
+		if (m->m_type == sdp_media_audio && !got_audio) {
 			sdp_rtpmap_t *map;
 
 			for (attr = m->m_attributes; attr; attr = attr->a_next) {
@@ -1657,7 +1658,8 @@
 					if (match) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec [%s] is still good, let's keep it\n", 
 										  tech_pvt->rm_encoding);
-						goto end;
+                        got_audio = 1;
+                        break;
 					}
 				}
 			}
@@ -1845,7 +1847,8 @@
 						vmatch = 0;
 					}
 				}
-				
+
+                                        
 				if (mimp) {
 					if ((tech_pvt->video_rm_encoding = switch_core_session_strdup(session, (char *) rm_encoding))) {
 						char tmp[50];
@@ -1859,6 +1862,7 @@
 						switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_video_port);
 						switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_VIDEO_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
 						switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_VIDEO_PORT_VARIABLE, tmp);
+                        break;
 					} else {
 						vmatch = 0;
 					}
@@ -1867,8 +1871,6 @@
 		}
 	}
 
- end:
-
 	switch_set_flag_locked(tech_pvt, TFLAG_SDP);
 
 	return match;

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Fri Feb  1 16:22:27 2008
@@ -47,9 +47,9 @@
 	switch_frame_t *read_frame;
 
 	eh->up = 1;	
-	while(switch_channel_ready(channel) && switch_channel_get_state(channel) == CS_LOOPBACK) {
+	while(switch_channel_ready(channel)) {
 		status = switch_core_session_read_video_frame(session, &read_frame, -1, 0);
-		
+        
 		if (!SWITCH_READ_ACCEPTABLE(status)) {
 			break;
 		}

Modified: freeswitch/trunk/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_bridge.c	(original)
+++ freeswitch/trunk/src/switch_ivr_bridge.c	Fri Feb  1 16:22:27 2008
@@ -35,6 +35,48 @@
 
 /* Bridge Related Stuff*/
 /*********************************************************************************/
+
+struct vid_helper {
+	switch_core_session_t *session_a;
+	switch_core_session_t *session_b;
+	int up;
+};
+
+static void *SWITCH_THREAD_FUNC video_bridge_thread(switch_thread_t *thread, void *obj)
+{
+	struct vid_helper *vh = obj;
+	switch_channel_t *channel = switch_core_session_get_channel(vh->session_a);
+	switch_status_t status;
+	switch_frame_t *read_frame;
+
+	vh->up = 1;	
+	while(switch_channel_ready(channel) && vh->up == 1) {
+		status = switch_core_session_read_video_frame(vh->session_a, &read_frame, -1, 0);
+        
+		if (!SWITCH_READ_ACCEPTABLE(status)) {
+			break;
+		}
+		
+		switch_core_session_write_video_frame(vh->session_b, read_frame, -1, 0);
+		
+	}
+	vh->up = 0;
+	return NULL;
+}
+
+
+static void launch_video(struct vid_helper *vh)
+{
+	switch_thread_t *thread;
+	switch_threadattr_t *thd_attr = NULL;
+
+    switch_threadattr_create(&thd_attr, switch_core_session_get_pool(vh->session_a));
+    switch_threadattr_detach_set(thd_attr, 1);
+    switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+    switch_thread_create(&thread, thd_attr, video_bridge_thread, vh, switch_core_session_get_pool(vh->session_a));
+}
+
+
 struct switch_ivr_bridge_data {
 	switch_core_session_t *session;
 	char b_uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
@@ -54,8 +96,9 @@
 	switch_channel_t *chan_a, *chan_b;
 	switch_frame_t *read_frame;
 	switch_core_session_t *session_a, *session_b;
-	uint32_t loop_count = 0;
+	uint32_t loop_count = 0, vid_launch = 0;
 	const char *app_name = NULL, *app_arg = NULL;
+    struct vid_helper vh = { 0 };
 
 	session_a = data->session;
 	if (!(session_b = switch_core_session_locate(data->b_uuid))) {
@@ -114,6 +157,13 @@
 			continue;
 		}
 
+        if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO) && !vid_launch) {
+            vid_launch++;
+            vh.session_a = session_a;
+            vh.session_b = session_b;
+            launch_video(&vh);
+        }
+
 		/* if 1 channel has DTMF pass it to the other */
 		while (switch_channel_has_dtmf(chan_a)) {
 			switch_dtmf_t dtmf = { 0, 0 };
@@ -165,7 +215,7 @@
 				continue;
 			}
 		}
-		
+
 		/* read audio from 1 channel and write it to the other */
 		status = switch_core_session_read_frame(session_a, &read_frame, -1, stream_id);
 
@@ -187,6 +237,15 @@
 		}
 	}
 
+    if (vh.up) {
+        vh.up = -1;
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ending video thread.\n");
+        while(vh.up) {
+            switch_yield(100000);
+        }
+    }
+
+
 	if (switch_channel_get_state(chan_b) >= CS_HANGUP) {	
 		if (originator && switch_channel_ready(chan_a) && !switch_channel_test_flag(chan_a, CF_ANSWERED)) {
 			switch_channel_hangup(chan_a, switch_channel_get_cause(chan_b));



More information about the Freeswitch-svn mailing list