From d29cd78976c20db8022da3ea59b55e1c765e5616 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthony.minessale@gmail.com>
Date: Fri, 3 Mar 2006 17:49:22 +0000
Subject: [PATCH] slowly unbreak things broken since the 'break everything'
 commit

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@742 d0543943-73ff-0310-b7d9-9358b9ac24b2
---
 src/switch_channel.c |  6 +++++-
 src/switch_core.c    |  4 +---
 src/switch_ivr.c     | 16 ++++++++++++----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/switch_channel.c b/src/switch_channel.c
index cc60d33f06..cdeb37be4b 100644
--- a/src/switch_channel.c
+++ b/src/switch_channel.c
@@ -575,7 +575,11 @@ SWITCH_DECLARE(switch_status) switch_channel_pre_answer(switch_channel *channel)
 	msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
 	msg.from = channel->name;
 	status = switch_core_session_message_send(uuid, &msg);
-	switch_channel_set_flag(channel, CF_EARLY_MEDIA);
+
+	if (status == SWITCH_STATUS_SUCCESS) {
+		switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Pre-Answer %s!\n", channel->name);
+		switch_channel_set_flag(channel, CF_EARLY_MEDIA);
+	}
 
 	return status;
 }
diff --git a/src/switch_core.c b/src/switch_core.c
index 9ccb824e5d..d4cc51c56f 100644
--- a/src/switch_core.c
+++ b/src/switch_core.c
@@ -857,9 +857,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_se
 				}
 			}
 		}
-	} else {
-		status = SWITCH_STATUS_SUCCESS;
-	}
+	} 
 
 	return status;
 }
diff --git a/src/switch_ivr.c b/src/switch_ivr.c
index 763b74bd1c..f4a6334879 100644
--- a/src/switch_ivr.c
+++ b/src/switch_ivr.c
@@ -862,7 +862,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
 	int stream_id = 0;
 	switch_frame *read_frame;
 
-
+	
 
 	caller_channel = switch_core_session_get_channel(session);
 	assert(caller_channel != NULL);
@@ -896,6 +896,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
 	switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
 	switch_core_session_thread_launch(peer_session);
 
+
 	for (;;) {
 		int state = switch_channel_get_state(peer_channel);
 		if (state > CS_RING) {
@@ -904,16 +905,23 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
 		switch_yield(1000);
 	}
 
+	switch_channel_pre_answer(caller_channel);
+	
 	time(&start);
 	while (switch_channel_ready(caller_channel) &&
 		   switch_channel_ready(peer_channel) &&
 		   !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
 		   !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
 		   ((time(NULL) - start) < timelimit)) {
-		if (switch_core_session_read_frame(session, &read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
-			break;
+
+		/* read from the channel while we wait if the audio is up on it */
+		if (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
+			if (switch_core_session_read_frame(session, &read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
+				break;
+			}
+		} else {
+			switch_yield(1000);
 		}
-		switch_yield(1000);
 	}
 
 	if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {