diff --git a/src/mod/applications/mod_bridgecall/mod_bridgecall.c b/src/mod/applications/mod_bridgecall/mod_bridgecall.c index ac8c85bd58..be0482f930 100644 --- a/src/mod/applications/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/applications/mod_bridgecall/mod_bridgecall.c @@ -83,7 +83,6 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) if (no_media_bridge) { switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); switch_frame_t *read_frame; - /* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */ while(switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel) && !switch_channel_test_flag(peer_channel, CF_ANSWERED)) { switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0); @@ -92,7 +91,6 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) if (SWITCH_READ_ACCEPTABLE(status) && switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) { bad = 0; } - if (bad) { switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 05a90d1c14..64fd08349e 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -162,6 +162,15 @@ static void answer_function(switch_core_session_t *session, char *data) switch_channel_answer(channel); } +static void pre_answer_function(switch_core_session_t *session, char *data) +{ + switch_channel_t *channel; + channel = switch_core_session_get_channel(session); + + assert(channel != NULL); + switch_channel_pre_answer(channel); +} + static void redirect_function(switch_core_session_t *session, char *data) { switch_core_session_message_t msg = {0}; @@ -595,13 +604,23 @@ static const switch_application_interface_t answer_application_interface = { }; +static const switch_application_interface_t pre_answer_application_interface = { + /*.interface_name */ "pre_answer", + /*.application_function */ pre_answer_function, + /* long_desc */ "Pre-Answer the call for a channel.", + /* short_desc */ "Pre-Answer the call", + /* syntax */ "", + /*.next */ &hangup_application_interface + +}; + static const switch_application_interface_t eval_application_interface = { /*.interface_name */ "eval", /*.application_function */ eval_function, /* long_desc */ "Do Nothing", /* short_desc */ "Do Nothing", /* syntax */ "", - /*.next */ &answer_application_interface + /*.next */ &pre_answer_application_interface }; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 11539ac4c8..a9a31f6a98 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1604,47 +1604,47 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) tech_pvt = (private_object_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - - if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) { - char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE); - if (tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { - switch_channel_set_variable(channel, "endpoint_disposition", "CODEC NEGOTIATION ERROR"); - nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); - return SWITCH_STATUS_FALSE; - } - switch_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION); - } - - if (switch_channel_test_flag(channel, CF_NOMEDIA)) { - switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA); - tech_absorb_sdp(tech_pvt); - } - if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_channel_test_flag(channel, CF_OUTBOUND)) { switch_set_flag_locked(tech_pvt, TFLAG_ANS); - - if ((status = tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) { - return status; - } - - set_local_sdp(tech_pvt, NULL, 0, NULL, 0); - activate_rtp(tech_pvt); - - if (tech_pvt->nh) { - if (tech_pvt->local_sdp_str) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", - switch_channel_get_name(channel), - tech_pvt->local_sdp_str); + if (switch_channel_test_flag(channel, CF_NOMEDIA)) { + char *sdp = NULL; + switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA); + if ((sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE))) { + tech_pvt->local_sdp_str = switch_core_session_strdup(session, sdp); + } + } else { + if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) { + char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE); + if (tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { + switch_channel_set_variable(channel, "endpoint_disposition", "CODEC NEGOTIATION ERROR"); + nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + return SWITCH_STATUS_FALSE; + } + switch_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION); } - nua_respond(tech_pvt->nh, SIP_200_OK, - SIPTAG_CONTACT_STR(tech_pvt->profile->url), - SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), - SOATAG_AUDIO_AUX("cn telephone-event"), - NUTAG_INCLUDE_EXTRA_SDP(1), - TAG_END()); + if ((status = tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) { + return status; + } + + set_local_sdp(tech_pvt, NULL, 0, NULL, 0); + activate_rtp(tech_pvt); + + if (tech_pvt->nh) { + if (tech_pvt->local_sdp_str) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", + switch_channel_get_name(channel), + tech_pvt->local_sdp_str); + } + } } + nua_respond(tech_pvt->nh, SIP_200_OK, + SIPTAG_CONTACT_STR(tech_pvt->profile->url), + SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), + SOATAG_AUDIO_AUX("cn telephone-event"), + NUTAG_INCLUDE_EXTRA_SDP(1), + TAG_END()); } return SWITCH_STATUS_SUCCESS; @@ -1842,7 +1842,9 @@ static switch_status_t sofia_kill_channel(switch_core_session_t *session, int si switch(sig) { case SWITCH_SIG_BREAK: - switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK); + if (switch_rtp_ready(tech_pvt->rtp_session)) { + switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK); + } break; case SWITCH_SIG_KILL: default: @@ -2024,36 +2026,38 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - - if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) { - char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE); - if (tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { - switch_channel_set_variable(channel, "endpoint_disposition", "CODEC NEGOTIATION ERROR"); - nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); - return SWITCH_STATUS_FALSE; - } - switch_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION); - } - - if (!switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA) && !switch_test_flag(tech_pvt, TFLAG_ANS)) { + if (!switch_test_flag(tech_pvt, TFLAG_ANS)) { switch_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); - - if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { - tech_absorb_sdp(tech_pvt); - } - /* Transmit 183 Progress with SDP */ - if ((status=tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) { - return status; - } - set_local_sdp(tech_pvt, NULL, 0, NULL, 0); - activate_rtp(tech_pvt); - if (tech_pvt->local_sdp_str) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ring SDP:\n%s\n", tech_pvt->local_sdp_str); - } + if (switch_channel_test_flag(channel, CF_NOMEDIA)) { + char *sdp = NULL; + switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA); + if ((sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE))) { + tech_pvt->local_sdp_str = switch_core_session_strdup(session, sdp); + } + } else { + if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) { + char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE); + if (tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { + switch_channel_set_variable(channel, "endpoint_disposition", "CODEC NEGOTIATION ERROR"); + nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + return SWITCH_STATUS_FALSE; + } + switch_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION); + } + if ((status=tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) { + return status; + } + set_local_sdp(tech_pvt, NULL, 0, NULL, 0); + activate_rtp(tech_pvt); + if (tech_pvt->local_sdp_str) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ring SDP:\n%s\n", tech_pvt->local_sdp_str); + } + } + nua_respond(tech_pvt->nh, SIP_183_SESSION_PROGRESS, SIPTAG_CONTACT_STR(tech_pvt->profile->url), @@ -2786,24 +2790,31 @@ static void sip_i_state(int status, } } } + if (r_sdp) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA); switch_channel_mark_pre_answered(channel); if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) { other_channel = switch_core_session_get_channel(other_session); + if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) { + switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, (char *)r_sdp); + } + switch_channel_pre_answer(other_channel); switch_core_session_rwunlock(other_session); } goto done; - } else if (!switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) { - if (tech_media(tech_pvt, (char *)r_sdp) != SWITCH_STATUS_SUCCESS) { - switch_channel_set_variable(channel, "endpoint_disposition", "CODEC NEGOTIATION ERROR"); - nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); - } - goto done; - } else { - switch_channel_set_variable(channel, "endpoint_disposition", "DELAYED NEGOTIATION"); + } else { + if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) { + switch_channel_set_variable(channel, "endpoint_disposition", "DELAYED NEGOTIATION"); + } else { + if (tech_media(tech_pvt, (char *)r_sdp) != SWITCH_STATUS_SUCCESS) { + switch_channel_set_variable(channel, "endpoint_disposition", "CODEC NEGOTIATION ERROR"); + nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + } + } + goto done; } } } @@ -2932,12 +2943,29 @@ static void sip_i_state(int status, } if (channel) { + if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) { + switch_set_flag_locked(tech_pvt, TFLAG_ANS); + switch_channel_mark_answered(channel); + if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) { + other_channel = switch_core_session_get_channel(other_session); + switch_channel_answer(other_channel); + switch_core_session_rwunlock(other_session); + } + goto done; + } + + if (!r_sdp) { + r_sdp = (const char *) switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE); + } if (r_sdp) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { switch_set_flag_locked(tech_pvt, TFLAG_ANS); switch_channel_mark_answered(channel); if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) { other_channel = switch_core_session_get_channel(other_session); + if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) { + switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, (char *)r_sdp); + } switch_channel_answer(other_channel); switch_core_session_rwunlock(other_session); } @@ -2970,16 +2998,8 @@ static void sip_i_state(int status, switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS"); nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); } - } else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) { - switch_set_flag_locked(tech_pvt, TFLAG_ANS); - switch_channel_mark_answered(channel); - if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) { - other_channel = switch_core_session_get_channel(other_session); - switch_channel_answer(other_channel); - switch_core_session_rwunlock(other_session); - } - goto done; - } //else probably an ack + } + } break; diff --git a/src/switch_ivr.c b/src/switch_ivr.c index a740cbb36c..3b9a5f5d7d 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -2552,7 +2552,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess file = NULL; } - if ((var_val = switch_event_get_header(var_event, "noanswer_early_media")) && switch_true(var_val)) { + if ((var_val = switch_event_get_header(var_event, "ignore_early_media")) && switch_true(var_val)) { early_ok = 0; } @@ -2755,9 +2755,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess switch_channel_pre_answer(caller_channel); } - if (session && (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA))) { - read_codec = switch_core_session_get_read_codec(session); - assert(read_codec != NULL); + if (session && (read_codec = switch_core_session_get_read_codec(session)) && + (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA))) { if (!(pass = (uint8_t)switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) { if (switch_core_codec_init(&write_codec,