diff --git a/src/switch_channel.c b/src/switch_channel.c index 43e7b1b8b1..5c0e78fe61 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1641,6 +1641,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel return SWITCH_STATUS_FALSE; } + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CRIT, "INVALID! Channel [%s] is an outbound leg\n", channel->name); + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + return SWITCH_STATUS_FALSE; + } + if (switch_channel_test_flag(channel, CF_ANSWERED)) { return SWITCH_STATUS_SUCCESS; } @@ -1673,6 +1679,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready(switch_channel return SWITCH_STATUS_FALSE; } + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CRIT, "INVALID! Channel [%s] is an outbound leg\n", channel->name); + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + return SWITCH_STATUS_FALSE; + } + if (switch_channel_test_flag(channel, CF_ANSWERED)) { return SWITCH_STATUS_SUCCESS; } @@ -1782,6 +1794,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t * return SWITCH_STATUS_FALSE; } + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CRIT, "INVALID! Channel [%s] is an outbound leg\n", channel->name); + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + return SWITCH_STATUS_FALSE; + } + if (switch_channel_test_flag(channel, CF_ANSWERED)) { return SWITCH_STATUS_SUCCESS; } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 34bd416ff4..175d5be8dc 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -41,7 +41,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args) { switch_channel_t *channel = switch_core_session_get_channel(session); - int media_ready = 0; switch_status_t status = SWITCH_STATUS_SUCCESS; switch_time_t start = switch_timestamp_now(), now, done = switch_timestamp_now() + (ms * 1000); switch_frame_t *read_frame, cng_frame = { 0 }; @@ -55,16 +54,20 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, int sval = 0; const char *var; - if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && !switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) { + if (!switch_channel_test_flag(channel, CF_OUTBOUND) && !switch_channel_test_flag(channel, CF_PROXY_MODE) && + !switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) { 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; } } - media_ready = (switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)); - - if (ms > 100 && media_ready && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) { + if (!switch_channel_media_ready(channel)) { + switch_yield(ms * 1000); + return SWITCH_STATUS_SUCCESS; + } + + if (ms > 100 && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) { switch_core_session_get_read_impl(session, &imp); if (switch_core_codec_init(&codec, @@ -102,7 +105,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, cng_frame.buflen = 2; switch_set_flag((&cng_frame), SFF_CNG); - if (sync && media_ready) { + if (sync) { switch_channel_audio_sync(channel); } @@ -169,11 +172,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, } } - if (!media_ready) { - switch_cond_next(); - continue; - } - status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); if (!SWITCH_READ_ACCEPTABLE(status)) {