]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_pjsip: set correct Endpoint Device State on multiple channels
authorAlexei Gradinari <alex2grad@gmail.com>
Tue, 25 Mar 2025 21:24:29 +0000 (17:24 -0400)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 1 May 2025 12:39:48 +0000 (12:39 +0000)
1. When one channel is placed on hold, the device state is set to ONHOLD
without checking other channels states.
In case of AST_CONTROL_HOLD set the device state as AST_DEVICE_UNKNOWN
to calculate aggregate device state of all active channels.

2. The current implementation incorrectly classifies channels in use.
The only channels that has the states: UP, RING and BUSY are considered as "in use".
A channel should be considered "in use" if its state is anything other than
DOWN or RESERVED.

3. Currently, if the number of channels "in use" is greater than device_state_busy_at,
the system does not set the state to BUSY. Instead, it incorrectly assigns an aggregate
device state.
The endpoint device state should be BUSY if the number of channels "in use" is greater
than or equal to device_state_busy_at.

Fixes: #1181
(cherry picked from commit ad178d155db599483aedf9936eaedf4ee4b7940f)

channels/chan_pjsip.c
res/res_pjsip/pjsip_config.xml

index 9eb6a4e7df9aa213d1cddda7f6bb6829d8f2c44d..374470e9dd3a2b30cc3f5e5a7ada33d48fc35fd1 100644 (file)
@@ -1221,15 +1221,14 @@ static int chan_pjsip_devicestate(const char *data)
                        ast_devstate_aggregate_add(&aggregate, ast_state_chan2dev(snapshot->state));
                }
 
-               if ((snapshot->state == AST_STATE_UP) || (snapshot->state == AST_STATE_RING) ||
-                       (snapshot->state == AST_STATE_BUSY)) {
+               if (snapshot->state != AST_STATE_DOWN && snapshot->state != AST_STATE_RESERVED) {
                        inuse++;
                }
 
                ao2_ref(snapshot, -1);
        }
 
-       if (endpoint->devicestate_busy_at && (inuse == endpoint->devicestate_busy_at)) {
+       if (endpoint->devicestate_busy_at && (inuse >= endpoint->devicestate_busy_at)) {
                state = AST_DEVICE_BUSY;
        } else if (ast_devstate_aggregate_result(&aggregate) != AST_DEVICE_INVALID) {
                state = ast_devstate_aggregate_result(&aggregate);
@@ -1791,7 +1790,7 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi
                device_buf_size = strlen(ast_channel_name(ast)) + 1;
                device_buf = alloca(device_buf_size);
                ast_channel_get_device_name(ast, device_buf, device_buf_size);
-               ast_devstate_changed_literal(AST_DEVICE_ONHOLD, 1, device_buf);
+               ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, device_buf);
                if (!channel->session->moh_passthrough) {
                        ast_moh_start(ast, data, NULL);
                } else {
@@ -1807,7 +1806,7 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi
                device_buf_size = strlen(ast_channel_name(ast)) + 1;
                device_buf = alloca(device_buf_size);
                ast_channel_get_device_name(ast, device_buf, device_buf_size);
-               ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, 1, device_buf);
+               ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, device_buf);
                if (!channel->session->moh_passthrough) {
                        ast_moh_stop(ast);
                } else {
index ed3a407eb9f55e1cd727af811f2bce9f552909c5..6ad625613ca077c7b9cf5cb77095a71ae0028dfa 100644 (file)
                                        </since>
                                        <synopsis>The number of in-use channels which will cause busy to be returned as device state</synopsis>
                                        <description><para>
-                                               When the number of in-use channels for the endpoint matches the devicestate_busy_at setting the
-                                               PJSIP channel driver will return busy as the device state instead of in use.
+                                               When the number of in-use channels for the endpoint equal to or greater than the devicestate_busy_at setting
+                                               the PJSIP channel driver will return busy as the device state instead of in use.
                                        </para></description>
                                </configOption>
                                <configOption name="t38_udptl" default="no">