mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-11 03:57:14 +00:00
device state tweaks
This commit is contained in:
1 parent
8ab31493d7
commit
916a75e9cf
2 files changed
+106
-5
No files matched your search
+84
-5
@@ -277,7 +277,11 @@ SWITCH_DECLARE(void) switch_channel_perform_set_callstate(switch_channel_t *chan
|
||||
switch_channel_callstate2str(o_callstate), switch_channel_callstate2str(callstate));
|
||||
|
||||
switch_channel_check_device_state(channel, channel->callstate);
|
||||
|
||||
|
||||
if (callstate == CCS_HANGUP) {
|
||||
process_device_hup(channel);
|
||||
}
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Original-Channel-Call-State", switch_channel_callstate2str(o_callstate));
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number", "%d", callstate);
|
||||
@@ -3137,8 +3141,6 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
|
||||
channel->state = CS_HANGUP;
|
||||
switch_mutex_unlock(channel->state_mutex);
|
||||
|
||||
process_device_hup(channel);
|
||||
|
||||
channel->hangup_cause = hangup_cause;
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n",
|
||||
channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
|
||||
@@ -4664,28 +4666,64 @@ static void fetch_device_stats(switch_device_record_t *drec)
|
||||
{
|
||||
switch_device_node_t *np;
|
||||
|
||||
|
||||
memset(&drec->stats, 0, sizeof(switch_device_stats_t));
|
||||
|
||||
switch_mutex_lock(drec->mutex);
|
||||
for(np = drec->uuid_list; np; np = np->next) {
|
||||
drec->stats.total++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.total_in++;
|
||||
} else {
|
||||
drec->stats.total_out++;
|
||||
}
|
||||
|
||||
if (!np->hup_profile) {
|
||||
drec->stats.offhook++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.offhook_in++;
|
||||
} else {
|
||||
drec->stats.offhook_out++;
|
||||
}
|
||||
|
||||
if (np->callstate == CCS_HELD) {
|
||||
drec->stats.held++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.held_in++;
|
||||
} else {
|
||||
drec->stats.held_out++;
|
||||
}
|
||||
} else {
|
||||
if (np->callstate == CCS_EARLY) {
|
||||
drec->stats.early++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.early_in++;
|
||||
} else {
|
||||
drec->stats.early_out++;
|
||||
}
|
||||
} else if (np->callstate == CCS_RINGING) {
|
||||
drec->stats.ringing++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.ringing_in++;
|
||||
} else {
|
||||
drec->stats.ringing_out++;
|
||||
}
|
||||
} else if (np->callstate != CCS_DOWN) {
|
||||
drec->stats.active++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.active_in++;
|
||||
} else {
|
||||
drec->stats.active_out++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
drec->stats.hup++;
|
||||
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
|
||||
drec->stats.hup_in++;
|
||||
} else {
|
||||
drec->stats.hup_out++;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(drec->mutex);
|
||||
@@ -4826,7 +4864,7 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
drec->state = SDS_HANGUP;
|
||||
} else {
|
||||
if (drec->stats.active == 0) {
|
||||
if ((drec->stats.ringing + drec->stats.early) > 0) {
|
||||
if ((drec->stats.ringing_out + drec->stats.early_out) > 0) {
|
||||
drec->state = SDS_RINGING;
|
||||
} else {
|
||||
if (drec->stats.held > 0) {
|
||||
@@ -4848,7 +4886,15 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
return;
|
||||
}
|
||||
|
||||
if (!drec->call_start) {
|
||||
drec->call_start = switch_micro_time_now();
|
||||
}
|
||||
|
||||
switch(drec->state) {
|
||||
case SDS_RINGING:
|
||||
drec->ring_start = switch_micro_time_now();
|
||||
drec->ring_stop = 0;
|
||||
break;
|
||||
case SDS_ACTIVE:
|
||||
case SDS_ACTIVE_MULTI:
|
||||
if (drec->last_state != SDS_HELD && drec->active_start) {
|
||||
@@ -4857,6 +4903,9 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
drec->active_start = switch_micro_time_now();
|
||||
}
|
||||
break;
|
||||
case SDS_HELD:
|
||||
drec->hold_start = switch_micro_time_now();
|
||||
drec->hold_stop = 0;
|
||||
default:
|
||||
if (drec->last_state != SDS_HELD) {
|
||||
drec->active_stop = switch_micro_time_now();
|
||||
@@ -4864,6 +4913,15 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
break;
|
||||
}
|
||||
|
||||
if (drec->ring_start && !drec->ring_stop && drec->state != SDS_RINGING) {
|
||||
drec->ring_stop = switch_micro_time_now();
|
||||
}
|
||||
|
||||
if (drec->hold_start && !drec->hold_stop && drec->state != SDS_HELD) {
|
||||
drec->hold_stop = switch_micro_time_now();
|
||||
}
|
||||
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_DEVICE_STATE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-ID", drec->device_id);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-Device-State", switch_channel_device_state2str(drec->last_state));
|
||||
@@ -4884,7 +4942,8 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1,
|
||||
"%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u Ringing:%u Early:%u Active:%u Held:%u Hungup:%u Dur: %u %s\n",
|
||||
"%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u "
|
||||
"Ringing:%u Early:%u Active:%u Held:%u Hungup:%u Dur: %u Ringtime: %u Holdtime: %u %s\n",
|
||||
switch_channel_get_name(channel),
|
||||
drec->device_id,
|
||||
switch_channel_callstate2str(callstate),
|
||||
@@ -4898,12 +4957,16 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
drec->stats.held,
|
||||
drec->stats.hup,
|
||||
drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0,
|
||||
drec->ring_stop ? (uint32_t)(drec->ring_stop - drec->ring_start) / 1000 : 0,
|
||||
drec->hold_stop ? (uint32_t)(drec->hold_stop - drec->hold_start) / 1000 : 0,
|
||||
switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : "");
|
||||
|
||||
for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
|
||||
ptr->function(channel->session, callstate, drec);
|
||||
}
|
||||
|
||||
drec->last_stats = drec->stats;
|
||||
|
||||
if (drec->active_stop) {
|
||||
drec->active_start = drec->active_stop = 0;
|
||||
if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) {
|
||||
@@ -4911,6 +4974,20 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
|
||||
}
|
||||
}
|
||||
|
||||
if (drec->hold_stop) {
|
||||
drec->hold_start = drec->hold_stop = 0;
|
||||
if (drec->state == SDS_HELD) {
|
||||
drec->hold_start = switch_micro_time_now();
|
||||
}
|
||||
}
|
||||
|
||||
if (drec->ring_stop) {
|
||||
drec->ring_start = drec->ring_stop = 0;
|
||||
if (drec->state == SDS_RINGING) {
|
||||
drec->ring_start = switch_micro_time_now();
|
||||
}
|
||||
}
|
||||
|
||||
drec->last_call_time = switch_micro_time_now();
|
||||
|
||||
drec->last_state = drec->state;
|
||||
@@ -4938,6 +5015,8 @@ static void add_uuid(switch_device_record_t *drec, switch_channel_t *channel)
|
||||
node->uuid = switch_core_strdup(drec->pool, switch_core_session_get_uuid(channel->session));
|
||||
node->parent = drec;
|
||||
node->callstate = channel->callstate;
|
||||
node->direction = channel->direction == SWITCH_CALL_DIRECTION_INBOUND ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND;
|
||||
|
||||
channel->device_node = node;
|
||||
|
||||
if (!drec->uuid_list) {
|
||||
|
||||
Reference in new issue
Block a user