[Freeswitch-svn] [commit] r3300 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/applications/mod_playback mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Fri Nov 10 03:13:03 EST 2006


Author: anthm
Date: Fri Nov 10 03:13:01 2006
New Revision: 3300

Modified:
   freeswitch/trunk/src/include/switch_am_config.h.in
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/applications/mod_playback/mod_playback.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/switch_ivr.c

Log:
fix gremlins in code that worked before then changed it's mind

Modified: freeswitch/trunk/src/include/switch_am_config.h.in
==============================================================================
--- freeswitch/trunk/src/include/switch_am_config.h.in	(original)
+++ freeswitch/trunk/src/include/switch_am_config.h.in	Fri Nov 10 03:13:01 2006
@@ -124,5 +124,5 @@
 /* Define to rpl_malloc if the replacement function should be used. */
 #undef malloc
 
-/* Define to `unsigned' if <sys/types.h> does not define. */
+/* Define to `unsigned int' if <sys/types.h> does not define. */
 #undef size_t

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Fri Nov 10 03:13:01 2006
@@ -87,15 +87,16 @@
 #define SWITCH_REMOTE_MEDIA_IP_VARIABLE "_remote_media_ip_"
 #define SWITCH_REMOTE_MEDIA_PORT_VARIABLE "_remote_media_port_"
 #define SWITCH_SPEECH_KEY "_speech_"
-
+#define SWITCH_UUID_BRIDGE "_uuid_bridge_"
 #define SWITCH_BITS_PER_BYTE 8
 typedef uint8_t switch_byte_t;
 
 typedef enum {
 	SMF_NONE = 0,
 	SMF_REBRIDGE = (1 << 0),
-	SMF_ECHO_BRIDGED = (1 << 1),
-	SMF_FORCE = (1 << 2)
+	SMF_ECHO_ALEG = (1 << 1),
+	SMF_ECHO_BLEG = (1 << 2),
+	SMF_FORCE = (1 << 3),
 } switch_media_flag_t;
 
 typedef enum {

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Fri Nov 10 03:13:01 2006
@@ -287,8 +287,16 @@
 	} else {
 		switch_media_flag_t flags = SMF_NONE;
 
-		if (argv[2] && !strcmp(argv[2], "both")) {
-			flags |= SMF_ECHO_BRIDGED;
+		if (argv[2]) {
+			if (!strcmp(argv[2], "both")) {
+				flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG);
+			} else if (!strcmp(argv[2], "aleg")) {
+				flags |= SMF_ECHO_ALEG;
+			} else if (!strcmp(argv[2], "bleg")) {
+				flags |= SMF_ECHO_BLEG;
+			}
+		} else {
+			flags |= SMF_ECHO_ALEG;
 		}
 		
 		status = switch_ivr_broadcast(argv[0], argv[1], flags);

Modified: freeswitch/trunk/src/mod/applications/mod_playback/mod_playback.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_playback/mod_playback.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_playback/mod_playback.c	Fri Nov 10 03:13:01 2006
@@ -111,7 +111,6 @@
 	switch_channel_t *channel;
 	char *timer_name = NULL;
 	char *file_name = NULL;
-	switch_status_t status;
 
 	file_name = switch_core_session_strdup(session, data);
 
@@ -124,12 +123,8 @@
 
 	switch_channel_pre_answer(channel);
 
-	status = switch_ivr_play_file(session, NULL, file_name, timer_name, on_dtmf, NULL, 0);
+	switch_ivr_play_file(session, NULL, file_name, timer_name, on_dtmf, NULL, 0);
 
-	if (!switch_channel_ready(channel) || (status != SWITCH_STATUS_SUCCESS && !SWITCH_STATUS_IS_BREAK(status))) {
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-	}
-	
 }
 
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Nov 10 03:13:01 2006
@@ -146,7 +146,7 @@
 
 typedef enum {
 	TFLAG_IO = (1 << 0),
-	TFLAG_USEME = (1 << 1),
+	TFLAG_CHANGE_MEDIA = (1 << 1),
 	TFLAG_OUTBOUND = (1 << 2),
 	TFLAG_READING = (1 << 3),
 	TFLAG_WRITING = (1 << 4),
@@ -1773,7 +1773,6 @@
 		if (!tech_pvt->local_sdp_str) {
 			tech_absorb_sdp(tech_pvt);
 		}
-
 		do_invite(session);
 	}
 		break;
@@ -2403,24 +2402,29 @@
 	}
 }
 
-static void pass_sdp(switch_channel_t *channel, char *sdp) 
+static void pass_sdp(private_object_t *tech_pvt, char *sdp) 
 {
 	char *val;
+	switch_channel_t *channel;
 	switch_core_session_t *other_session;
 	switch_channel_t *other_channel;
 	
+	channel = switch_core_session_get_channel(tech_pvt->session);
+	assert(channel != NULL);
+	
 	if ((val = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE)) && (other_session = switch_core_session_locate(val))) {
 		other_channel = switch_core_session_get_channel(other_session);
 		assert(other_channel != NULL);
 		if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
 			switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp);
 		}
-		if (
+		if (!switch_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && (
 			switch_channel_test_flag(other_channel, CF_OUTBOUND) && 
 			switch_channel_test_flag(other_channel, CF_NOMEDIA) && 
 			switch_channel_test_flag(channel, CF_OUTBOUND) && 
-			switch_channel_test_flag(channel, CF_NOMEDIA)) {
+			switch_channel_test_flag(channel, CF_NOMEDIA))) {
 			switch_ivr_nomedia(val, SMF_FORCE);
+			switch_set_flag_locked(tech_pvt, TFLAG_CHANGE_MEDIA);
 		}
 		
 		switch_core_session_rwunlock(other_session);
@@ -2481,7 +2485,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote SDP:\n%s\n", r_sdp);			
 			tech_pvt->remote_sdp_str = switch_core_session_strdup(session, (char *)r_sdp);
 			switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, (char *) r_sdp);
-			pass_sdp(channel, (char *) r_sdp);
+			pass_sdp(tech_pvt, (char *) r_sdp);
 
 		}
 	}
@@ -2639,7 +2643,6 @@
 		if (tech_pvt && r_sdp) {
 			if (r_sdp) {
 				if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "What should i do?\n%s\n", r_sdp);
 					return;
 				} else {
 					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Fri Nov 10 03:13:01 2006
@@ -288,7 +288,7 @@
 			switch_ivr_parse_event(session, event);
 			switch_event_destroy(&event);
 		}
-
+		
 		if (switch_channel_has_dtmf(channel)) {
 			char dtmf[128];
 			switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
@@ -1949,11 +1949,10 @@
 
 
 	if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) {
-		switch_channel_set_flag(channel, CF_TAGGED);
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if ((other_session = switch_channel_get_private(channel, "_uuid_bridge_"))) {
+	if ((other_session = switch_channel_get_private(channel, SWITCH_UUID_BRIDGE))) {
 		switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
 		switch_channel_state_t state = switch_channel_get_state(other_channel);
 		switch_channel_state_t mystate = switch_channel_get_state(channel);
@@ -1963,7 +1962,7 @@
 
 
 		switch_channel_clear_flag(channel, CF_TRANSFER);
-		switch_channel_set_private(channel, "_uuid_bridge_", NULL);
+		switch_channel_set_private(channel, SWITCH_UUID_BRIDGE, NULL);
 
 		while (mystate <= CS_HANGUP && state <= CS_HANGUP && !switch_channel_test_flag(other_channel, CF_TAGGED)) {
 			switch_yield(1000);
@@ -2682,14 +2681,15 @@
 {
     switch_channel_t *channel;
 	int nomedia;
-	switch_core_session_t *session;
+	switch_core_session_t *session, *master;
 	switch_event_t *event;
-	switch_core_session_t *other_session;
+	switch_core_session_t *other_session = NULL;
 	char *other_uuid = NULL;
 
 	if ((session = switch_core_session_locate(uuid))) {
 		char *app;
-		
+		master = session;
+
 		channel = switch_core_session_get_channel(session);
 		assert(channel != NULL);
 
@@ -2704,7 +2704,7 @@
 			app = "playback";
 		}
 		
-		if ((flags & SMF_ECHO_BRIDGED) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE))
+		if ((flags & SMF_ECHO_BLEG) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE))
 			&& (other_session = switch_core_session_locate(other_uuid))) {
 			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
@@ -2713,21 +2713,25 @@
 				switch_core_session_queue_private_event(other_session, &event);
 			}
 			switch_core_session_rwunlock(other_session);
+			master = other_session;
 			other_session = NULL;
 		}
-
-		if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
-			switch_core_session_queue_private_event(session, &event);
+		
+		if ((flags & SMF_ECHO_ALEG)) {
+			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
+				switch_core_session_queue_private_event(session, &event);
+			}
+			master = session;
 		}
 
 		if (nomedia) {
 			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "nomedia");
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "nomedia-uuid", "%s", uuid);
-				switch_core_session_queue_private_event(session, &event);
+				switch_core_session_queue_private_event(master, &event);
 			}
 		}
 		
@@ -2744,19 +2748,24 @@
     switch_core_session_t *session, *other_session;
 	switch_core_session_message_t msg = {0};
 	switch_status_t status = SWITCH_STATUS_GENERR;
-	
+	uint8_t swap = 0;
+
 	msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA;
 	msg.from = __FILE__;
 
 	if ((session = switch_core_session_locate(uuid))) {
 		channel = switch_core_session_get_channel(session);
 		assert(channel != NULL);
+		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+			swap = 1;
+		}
 		
 		if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
 			status = SWITCH_STATUS_SUCCESS;
 			switch_channel_clear_flag(channel, CF_NOMEDIA);
 			switch_core_session_receive_message(session, &msg);
-			if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) 
+
+			if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE)) 
 				&& (other_session = switch_core_session_locate(other_uuid))) {
 				other_channel = switch_core_session_get_channel(other_session);
 				assert(other_channel != NULL);
@@ -2772,7 +2781,11 @@
 		switch_core_session_rwunlock(session);
 
 		if (other_channel) {
-			switch_ivr_uuid_bridge(uuid, other_uuid);
+			if (swap) {
+				switch_ivr_uuid_bridge(other_uuid, uuid);
+			} else {
+				switch_ivr_uuid_bridge(uuid, other_uuid);
+			}
 		}
 	}
 
@@ -2787,6 +2800,7 @@
     switch_core_session_t *session, *other_session = NULL;
 	switch_core_session_message_t msg = {0};
 	switch_status_t status = SWITCH_STATUS_GENERR;
+	uint8_t swap = 0;
 
 	msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA;
 	msg.from = __FILE__;
@@ -2796,6 +2810,10 @@
 		channel = switch_core_session_get_channel(session);
 		assert(channel != NULL);
 
+		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+			swap = 1;
+		}
+
 		if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_NOMEDIA)) {
 			switch_channel_set_flag(channel, CF_NOMEDIA);
 			switch_core_session_receive_message(session, &msg);
@@ -2809,7 +2827,11 @@
 			}
 			if (other_channel) {
 				switch_channel_clear_state_handler(channel, NULL);
-				switch_ivr_signal_bridge(session, other_session);
+				if (swap) {
+					switch_ivr_signal_bridge(other_session, session);
+				} else {
+					switch_ivr_signal_bridge(session, other_session);
+				}
 				switch_core_session_rwunlock(other_session);
 			}
 		}
@@ -2826,7 +2848,7 @@
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 	switch_channel_clear_flag(channel, CF_TRANSFER);
-	
+
 	switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE));
 
 	return SWITCH_STATUS_SUCCESS;
@@ -2886,11 +2908,11 @@
 	caller_channel = switch_core_session_get_channel(session);
 	assert(caller_channel != NULL);
 
-	switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
-
 	peer_channel = switch_core_session_get_channel(peer_session);
 	assert(peer_channel != NULL);
 
+	switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
+
 	switch_channel_clear_state_handler(caller_channel, NULL);
 	switch_channel_clear_state_handler(peer_channel, NULL);
 
@@ -3095,7 +3117,8 @@
 			switch_channel_set_flag(originator_channel, CF_ORIGINATOR);
 			switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers);
 			switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers);
-			switch_channel_set_private(originator_channel, "_uuid_bridge_", originatee_session);
+			switch_channel_set_flag(originatee_channel, CF_TAGGED);
+			switch_channel_set_private(originator_channel, SWITCH_UUID_BRIDGE, originatee_session);
 
 			/* switch_channel_set_state_flag sets flags you want to be set when the next state change happens */
 			switch_channel_set_state_flag(originator_channel, CF_TRANSFER);
@@ -3108,8 +3131,12 @@
 			/* change the states and let the chips fall where they may */
 			switch_channel_set_state(originator_channel, CS_TRANSMIT);
 			switch_channel_set_state(originatee_channel, CS_TRANSMIT);
-			
+
 			status = SWITCH_STATUS_SUCCESS;
+			
+			while(switch_channel_get_state(originatee_channel) < CS_HANGUP && switch_channel_test_flag(originatee_channel, CF_TAGGED)) {
+				switch_yield(20000);
+			}
 		} else {
 			switch_core_session_rwunlock(originator_session);
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no channel for originatee uuid %s\n", originatee_uuid);



More information about the Freeswitch-svn mailing list