[mod_loopback] Don't block channel too long if already hangup, also add option to hangup immediately with cause

This commit is contained in:
Seven Du 2019-11-15 00:05:03 +08:00 committed by Andrey Volk
parent e0aef355db
commit 16f782f979
1 changed files with 17 additions and 2 deletions

View File

@ -1462,8 +1462,15 @@ static switch_status_t null_channel_on_consume_media(switch_core_session_t *sess
}
if (tech_pvt->auto_answer > 0) {
int sanity = tech_pvt->auto_answer;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "CHANNEL CONSUME_MEDIA - answering in %d ms\n", tech_pvt->auto_answer);
switch_yield(tech_pvt->auto_answer * 1000);
while(switch_channel_ready(channel) && sanity > 0) {
switch_yield(1000 * 1000);
sanity -= 1000;
}
switch_channel_mark_answered(channel);
}
@ -1602,6 +1609,7 @@ static switch_call_cause_t null_channel_outgoing_channel(switch_core_session_t *
switch_channel_t *ochannel = NULL;
const char *auto_answer = switch_event_get_header(var_event, "null_auto_answer");
const char *pre_answer = switch_event_get_header(var_event, "null_pre_answer");
const char *hangup_cause = switch_event_get_header(var_event, "null_hangup_cause");
if (session) {
ochannel = switch_core_session_get_channel(session);
@ -1615,7 +1623,7 @@ static switch_call_cause_t null_channel_outgoing_channel(switch_core_session_t *
if ((*new_session = switch_core_session_request(null_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, flags, pool)) != 0) {
null_private_t *tech_pvt;
switch_channel_t *channel;
switch_caller_profile_t *caller_profile;
switch_caller_profile_t *caller_profile = NULL;
switch_core_session_add_stream(*new_session, NULL);
@ -1671,6 +1679,13 @@ static switch_call_cause_t null_channel_outgoing_channel(switch_core_session_t *
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
switch_assert(caller_profile);
if (hangup_cause || !strncmp(caller_profile->destination_number, "cause-", 6)) {
if (!hangup_cause) hangup_cause = caller_profile->destination_number + 6;
return switch_channel_str2cause(hangup_cause);
}
switch_channel_set_state(channel, CS_INIT);
switch_channel_set_flag(channel, CF_AUDIO);
return SWITCH_CAUSE_SUCCESS;