Revision
17431
Author
anthm
Date
2010-04-28 12:59:29 -0500 (Wed, 28 Apr 2010)

Log Message

fix potential excess cpu usage during originate

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (17430 => 17431)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2010-04-28 17:57:05 UTC (rev 17430)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2010-04-28 17:59:29 UTC (rev 17431)
@@ -3874,7 +3874,9 @@
 					}
 
 					free(stream.data);
+
 					switch_core_session_rwunlock(a_session);
+					switch_channel_hangup(channel, SWITCH_CAUSE_REDIRECTION_TO_NEW_DESTINATION);
 				}
 			} else {
 				su_home_t *home = su_home_new(sizeof(*home));

Modified: freeswitch/trunk/src/switch_ivr_originate.c (17430 => 17431)


--- freeswitch/trunk/src/switch_ivr_originate.c	2010-04-28 17:57:05 UTC (rev 17430)
+++ freeswitch/trunk/src/switch_ivr_originate.c	2010-04-28 17:59:29 UTC (rev 17431)
@@ -702,7 +702,8 @@
 
   end:
 
-	if (pindex > -1 && caller_channel && switch_channel_ready(caller_channel) && !switch_channel_media_ready(caller_channel)) {
+	if (pindex > -1 && caller_channel && switch_channel_ready(caller_channel) && !switch_channel_media_ready(caller_channel) && 
+		switch_channel_media_ready(originate_status[pindex].peer_channel)) {
 		inherit_codec(caller_channel, originate_status[pindex].peer_session);
 	}
 
@@ -1750,7 +1751,8 @@
 	const char *soft_holding = NULL;
 	const char *export_vars = NULL;
 	early_state_t early_state = { 0 };
-
+	int read_packet = 0;
+	
 	if (strstr(bridgeto, SWITCH_ENT_ORIGINATE_DELIM)) {
 		return switch_ivr_enterprise_originate(session, bleg, cause, bridgeto, timelimit_sec, table, cid_name_override, cid_num_override,
 											   caller_profile_override, ovars, flags);
@@ -2708,6 +2710,8 @@
 			while ((!caller_channel || switch_channel_ready(caller_channel) || switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) &&
 				   check_channel_status(&oglobals, originate_status, and_argc)) {
 				time_t elapsed = switch_epoch_time_now(NULL) - start;
+				
+				read_packet = 0;
 
 				if (cancel_cause && *cancel_cause > 0) {
 					if (force_reason == SWITCH_CAUSE_NONE) {
@@ -2741,7 +2745,7 @@
 							const char *cause_str;
 
 							if (!originate_status[i].peer_session) {
-								continue;
+								goto do_continue;
 							}
 							pchannel = switch_core_session_get_channel(originate_status[i].peer_session);
 
@@ -2791,10 +2795,12 @@
 							}
 
 							if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
-								continue;
+								goto do_continue;
 							}
 							break;
 						}
+
+						read_packet++;
 					} else {
 						read_frame = NULL;
 					}
@@ -2838,7 +2844,7 @@
 								break;
 							}
 
-							continue;
+							goto do_continue;
 						}
 
 						if (oglobals.bridge_early_media > -1) {							
@@ -2897,7 +2903,7 @@
 
 								if (soft_holding) {
 									switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE);
-									continue;
+									goto do_continue;
 								}
 
 								break;
@@ -2920,16 +2926,19 @@
 								switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE);
 							}
 							if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
-								continue;
+								goto do_continue;
 							}
 							break;
 						}
 					}
 
-				} else {
+				} 
+
+			do_continue:
+
+				if (!read_packet) {
 					switch_cond_next();
 				}
-
 			}
 
 		  notready: