]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_loopback] Don't block channel too long if already hangup, also add option to...
authorSeven Du <seven@signalwire.com>
Thu, 14 Nov 2019 16:05:03 +0000 (00:05 +0800)
committerAndrey Volk <andywolk@gmail.com>
Wed, 6 May 2020 22:21:38 +0000 (02:21 +0400)
src/mod/endpoints/mod_loopback/mod_loopback.c

index 347ac52abcb329c8f49c2f6aa20d52375d6432ba..c4f9112f92346ed2ea9074691ed93fd465512d27 100644 (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;