From 303271f92a54d0409a4c05d615124b55522c804f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 May 2009 16:34:39 +0000 Subject: [PATCH] allow socket app to operate without pre_answer (please test) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13294 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 2 +- .../mod_event_socket/mod_event_socket.c | 4 -- src/switch_ivr.c | 53 +++++++++---------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 9f02e5cdca..861cc2e3ae 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1401,7 +1401,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (!sofia_test_flag(tech_pvt, TFLAG_ANS) && !sofia_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) { sofia_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->_file, msg->_func, msg->_line, NULL, SWITCH_LOG_INFO, "Sending early media\n"); /* Transmit 183 Progress with SDP */ if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) { diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 84fb2999c9..2353faee27 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -432,10 +432,6 @@ SWITCH_STANDARD_APP(socket_function) launch_listener_thread(listener); - if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { - return; - } - while(switch_channel_ready(channel) && !switch_test_flag(listener, LFLAG_CONNECTED)) { switch_cond_next(); } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 23dfc2469a..cab280b7f9 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -642,40 +642,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, int stream_id = 0; switch_event_t *event; switch_unicast_conninfo_t *conninfo = NULL; - uint32_t rate; - uint32_t bpf; + uint32_t rate = 0; + uint32_t bpf = 0; const char *to; int timeout = 0; time_t expires = 0; - switch_codec_implementation_t read_impl = {0}; - switch_core_session_get_read_impl(session, &read_impl); + if (switch_channel_test_flag(channel, CF_CONTROLLED)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that are under control already.\n"); return SWITCH_STATUS_FALSE; } - if (!switch_channel_test_flag(channel, CF_ANSWERED)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Careful, Channel is unanswered. Pre-answering...\n"); - if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n"); - return SWITCH_STATUS_FALSE; - } - } - if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_get_state(channel) == CS_RESET) { return SWITCH_STATUS_FALSE; } - if (!switch_channel_media_ready(channel)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that have no read codec.\n"); - return SWITCH_STATUS_FALSE; - } - - rate = read_impl.actual_samples_per_second; - bpf = read_impl.decoded_bytes_per_packet; - if ((to = switch_channel_get_variable(channel, "park_timeout"))) { if ((timeout = atoi(to)) < 0) { timeout = 0; @@ -693,20 +676,36 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_event_fire(&event); } - while (switch_channel_media_ready(channel) && switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED) - && switch_channel_test_flag(channel, CF_PARK)) { - - if ((status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id)) == SWITCH_STATUS_SUCCESS) { - if (!SWITCH_READ_ACCEPTABLE(status)) { - break; - } + while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED) && switch_channel_test_flag(channel, CF_PARK)) { + + if (!rate && switch_channel_media_ready(channel)) { + switch_core_session_get_read_impl(session, &read_impl); + rate = read_impl.actual_samples_per_second; + bpf = read_impl.decoded_bytes_per_packet; + } + + if (rate) { + status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id); + } else { + switch_yield(20000); + status = SWITCH_STATUS_SUCCESS; + } + if (!SWITCH_READ_ACCEPTABLE(status)) { + break; + } else { if (expires && switch_epoch_time_now(NULL) >= expires) { switch_channel_hangup(channel, SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE); break; } if (switch_channel_test_flag(channel, CF_UNICAST)) { + if (!switch_channel_media_ready(channel)) { + if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { + return SWITCH_STATUS_FALSE; + } + } + if (!conninfo) { if (!(conninfo = switch_channel_get_private(channel, "unicast"))) { switch_channel_clear_flag(channel, CF_UNICAST);