From 3133f25c6b304b1d7e38cd8847156ea12515fd1c Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Thu, 25 Feb 2021 14:26:11 +0100 Subject: [PATCH] sip: call: rework call state changes --- plugins/sip/calls-sip-call.c | 49 +++++++++++++--------------------- plugins/sip/calls-sip-origin.c | 14 +++++----- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/plugins/sip/calls-sip-call.c b/plugins/sip/calls-sip-call.c index 553bd73..889c25d 100644 --- a/plugins/sip/calls-sip-call.c +++ b/plugins/sip/calls-sip-call.c @@ -68,30 +68,6 @@ enum { static GParamSpec *props[PROP_LAST_PROP]; -static void -change_state (CallsSipCall *self, - CallsCallState state) -{ - CallsCallState old_state; - - g_assert (CALLS_IS_CALL (self)); - g_assert (CALLS_IS_SIP_CALL (self)); - - old_state = self->state; - - if (old_state == state) - { - return; - } - - self->state = state; - g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_STATE]); - g_signal_emit_by_name (CALLS_CALL (self), - "state-changed", - state, - old_state); -} - static void answer (CallsCall *call) { @@ -125,7 +101,7 @@ answer (CallsCall *call) SOATAG_AF (SOA_AF_IP4_IP6), TAG_END ()); - change_state (self, CALLS_CALL_STATE_ACTIVE); + calls_sip_call_set_state (self, CALLS_CALL_STATE_ACTIVE); } static void @@ -157,13 +133,13 @@ hang_up (CallsCall *call) case CALLS_CALL_STATE_DISCONNECTED: g_warning ("Tried hanging up already disconnected call"); - return; + break; default: g_warning ("Hanging up not possible in state %d", self->state); } - change_state (self, CALLS_CALL_STATE_DISCONNECTED); + calls_sip_call_set_state (self, CALLS_CALL_STATE_DISCONNECTED); } static void @@ -383,12 +359,25 @@ calls_sip_call_new (const gchar *number, void -calls_sip_call_set_state (CallsSipCall *self, - CallsCallState state) +calls_sip_call_set_state (CallsSipCall *self, + CallsCallState state) { + CallsCallState old_state; + + g_return_if_fail (CALLS_IS_CALL (self)); g_return_if_fail (CALLS_IS_SIP_CALL (self)); - g_print ("Changed call state to %d\n", state); + old_state = self->state; + + if (old_state == state) { + return; + } + self->state = state; g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_STATE]); + g_signal_emit_by_name (CALLS_CALL (self), + "state-changed", + state, + old_state); } + diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c index f23df96..4008c55 100644 --- a/plugins/sip/calls-sip-origin.c +++ b/plugins/sip/calls-sip-origin.c @@ -246,6 +246,7 @@ sip_i_state (int status, case nua_callstate_received: state = CALLS_CALL_STATE_INCOMING; + g_debug ("Call incoming"); break; case nua_callstate_ready: @@ -260,7 +261,13 @@ sip_i_state (int status, calls_sip_call_activate_media (call, FALSE); state = CALLS_CALL_STATE_DISCONNECTED; - break; + + g_hash_table_remove (origin->call_handles, nh); + + calls_sip_call_set_state (call, state); + g_object_unref (G_OBJECT (call)); + + return; case nua_callstate_authenticating: g_warning ("TODO Move authentication (INVITE) here"); @@ -579,12 +586,7 @@ remove_call (CallsSipOrigin *self, if (self->oper->call_handle == nh) self->oper->call_handle = NULL; - g_hash_table_remove (self->call_handles, nh); - nua_handle_unref (nh); - g_signal_emit_by_name (origin, "call-removed", call, reason); - - g_object_unref (G_OBJECT (call)); }