diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c index fe5cc6319ab16d63b5118255624c8da434650ff2..3caba49170daa6154222bac704c0fe4948e27b1f 100644 --- a/channels/chan_brcm.c +++ b/channels/chan_brcm.c @@ -417,6 +417,16 @@ static int pvt_unlock_silent(struct brcm_pvt *pvt) #define pvt_unlock_silent(pvt) ast_mutex_unlock(&(pvt)->lock) #endif +// Get call_id state based on the call_id value +static callid_state get_callid_state(int call_id) { + if (call_id <= CALLID_INVALID) + return CALLID_INVALID; + else if (call_id == CALLID_OBTAINING) + return CALLID_OBTAINING; + else + return CALLID_ESTABLISHED; +} + // Get the endptmngr ubus address. It's dynamically updated // by another thread without locking. static uint32_t get_ubus_endpt_id(int log) { @@ -587,7 +597,7 @@ static int brcm_indicate(struct ast_channel *ast, int condition, const void *dat // Play local ringback tone only if there is no incoming media packet if (sub->codec == -1) endpt_signal(sub->parent->line_id, "ringback", "on", NULL); - if (sub->owner && (sub->call_id == 0)) { + if (sub->owner && (get_callid_state(sub->call_id) != CALLID_ESTABLISHED)) { sub->call_id = ast_channel_callid(sub->owner); endpt_connection(sub->parent->line_id, sub->call_id, "update"); } @@ -654,17 +664,19 @@ static int brcm_indicate(struct ast_channel *ast, int condition, const void *dat if (sub->call_id == ast_channel_callid(bridge_channel->chan)) { endpt_connection(sub_peer->parent->line_id, sub_peer->call_id, "release"); sub_peer->channel_state = ONHOOK; + sub_peer->call_id = CALLID_INVALID; } else if(sub_peer->call_id == ast_channel_callid(bridge_channel->chan)) { endpt_connection(sub->parent->line_id, sub->call_id, "release"); sub->channel_state = ONHOOK; + sub->call_id = CALLID_INVALID; } } } res = 0; } } - if (sub->owner && (sub->call_id == 0)) { + if (sub->owner && (get_callid_state(sub->call_id) != CALLID_ESTABLISHED)) { sub->call_id = ast_channel_callid(sub->owner); endpt_connection(sub->parent->line_id, sub->call_id, "update"); res = 0; @@ -3240,7 +3252,7 @@ static struct brcm_pvt *brcm_allocate_pvt(void) sub = ast_calloc(1, sizeof(*sub)); if (sub) { sub->id = i; - sub->call_id = 0; + sub->call_id = CALLID_INVALID; sub->owner = NULL; sub->connection_id = -1; sub->connection_init = 0; @@ -4777,13 +4789,13 @@ static int brcm_create_connection(struct brcm_subchannel *sub) { if (sub->owner) { sub->call_id = ast_channel_callid(sub->owner); } else { - sub->call_id = 0; + sub->call_id = CALLID_OBTAINING; } if(!brcm_in_onhold(sub->parent) && !brcm_in_call(sub->parent)) { // Is there another connection already? ast_debug(1, "Creating real endpoint connection for pvt line_id=%i, connection_id: %d, call_id: %d\n", sub->parent->line_id, sub->connection_id, sub->call_id); endpt_connection(sub->parent->line_id, sub->call_id, "create"); - } else if (sub->call_id != 0) { + } else if (get_callid_state(sub->call_id) == CALLID_ESTABLISHED) { ast_debug(1, "Updating real endpoint connection for pvt line_id=%i, connection_id: %d, call_id: %d\n", sub->parent->line_id, sub->connection_id, sub->call_id); endpt_connection(sub->parent->line_id, sub->call_id, "update"); } @@ -5010,6 +5022,7 @@ static int brcm_close_connection(struct brcm_subchannel *sub) } sub->connection_init = 0; sub->codec = -1; + sub->call_id = CALLID_INVALID; ast_debug(1, "Virtual Asterisk connection %d/%d destroyed\n", p->line_id, sub->connection_id); } diff --git a/channels/chan_brcm.h b/channels/chan_brcm.h index 14520b940f9e745975c95bcd5a1f693537b3ebfb..f0bdb5d0d758539680b68a4570477b697e0419a1 100644 --- a/channels/chan_brcm.h +++ b/channels/chan_brcm.h @@ -109,9 +109,15 @@ typedef enum dialtone_state { DIALTONE_LAST, } dialtone_state; +typedef enum callid_state { + CALLID_INVALID = -1, + CALLID_OBTAINING = 0, + CALLID_ESTABLISHED = 1 +} callid_state; + struct brcm_subchannel { int id; - unsigned int call_id; /* The call_id of connection assigned by pjsip */ + int call_id; /* The call_id of connection assigned by pjsip */ struct ast_channel *owner; /* Channel we belong to, possibly NULL */ int connection_id; /* Current connection id, may be -1 */ enum brcm_channel_state channel_state; /* Channel states */