sip: initial call handling

* implement answering and hangup
 * (de)activate media pipeline
This commit is contained in:
Evangelos Ribeiro Tzaras
2021-02-19 17:34:57 +01:00
parent 967f30d688
commit e0482fc6e6
4 changed files with 106 additions and 27 deletions

View File

@@ -22,6 +22,8 @@
*
*/
#define G_LOG_DOMAIN "CallsSipCall"
#include "calls-sip-call.h"
#include "calls-message-source.h"
@@ -94,18 +96,34 @@ static void
answer (CallsCall *call)
{
CallsSipCall *self;
g_autofree gchar *local_sdp = NULL;
g_assert (CALLS_IS_CALL (call));
g_assert (CALLS_IS_SIP_CALL (call));
self = CALLS_SIP_CALL (call);
g_assert (self->nh);
if (self->state != CALLS_CALL_STATE_INCOMING) {
g_warning ("Call must be in 'incoming' state in order to answer");
return;
}
/* need to include SDP answer here */
/* XXX dynamically get free ports */
calls_sip_call_setup_local_media (self, 19042, 19043);
local_sdp = calls_sip_media_manager_static_capabilities (self->manager,
19042,
FALSE);
g_assert (local_sdp);
g_debug ("Setting local SDP to string:\n%s", local_sdp);
nua_respond (self->nh, 200, NULL,
SOATAG_USER_SDP_STR (local_sdp),
SOATAG_AF (SOA_AF_IP4_IP6),
TAG_END ());
change_state (self, CALLS_CALL_STATE_ACTIVE);
}
@@ -120,6 +138,31 @@ hang_up (CallsCall *call)
self = CALLS_SIP_CALL (call);
switch (self->state) {
case CALLS_CALL_STATE_DIALING:
nua_cancel (self->nh, TAG_END ());
g_debug ("Hanging up on outgoing ringing call");
break;
case CALLS_CALL_STATE_ACTIVE:
nua_bye (self->nh, TAG_END ());
g_debug ("Hanging up ongoing call");
break;
case CALLS_CALL_STATE_INCOMING:
nua_respond (self->nh, 480, NULL, TAG_END ());
g_debug ("Hanging up incoming call");
break;
case CALLS_CALL_STATE_DISCONNECTED:
g_warning ("Tried hanging up already disconnected call");
return;
default:
g_warning ("Hanging up not possible in state %d", self->state);
}
change_state (self, CALLS_CALL_STATE_DISCONNECTED);
}
@@ -301,14 +344,15 @@ calls_sip_call_setup_remote_media (CallsSipCall *self,
void
calls_sip_call_activate_media (CallsSipCall *self,
gboolean enabled)
gboolean enabled)
{
g_return_if_fail (CALLS_IS_SIP_CALL (self));
g_return_if_fail (CALLS_IS_SIP_MEDIA_PIPELINE (self->pipeline));
if (enabled) {
;
calls_sip_media_pipeline_start (self->pipeline);
} else {
;
calls_sip_media_pipeline_stop (self->pipeline);
}
}
@@ -336,3 +380,15 @@ calls_sip_call_new (const gchar *number,
return call;
}
void
calls_sip_call_set_state (CallsSipCall *self,
CallsCallState state)
{
g_return_if_fail (CALLS_IS_SIP_CALL (self));
g_print ("Changed call state to %d\n", state);
self->state = state;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_STATE]);
}