diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2012-01-10 17:51:53 -0500 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2012-01-10 17:51:53 -0500 |
commit | e0b0f82852ea73743c31b0ccf854bc438e7fcb1a (patch) | |
tree | 5dc11840c5e050c1b652213677aa2db00f328a1e | |
parent | b495f29113a05ed4aaa57546cbb3ef3911e61c9a (diff) |
Add SipSession/SipMedia abstractions
-rw-r--r-- | rakia/Makefile.am | 4 | ||||
-rw-r--r-- | rakia/sip-media.c | 108 | ||||
-rw-r--r-- | rakia/sip-media.h | 62 | ||||
-rw-r--r-- | rakia/sip-session.c | 165 | ||||
-rw-r--r-- | rakia/sip-session.h | 118 |
5 files changed, 457 insertions, 0 deletions
diff --git a/rakia/Makefile.am b/rakia/Makefile.am index 18a6b0c..819a906 100644 --- a/rakia/Makefile.am +++ b/rakia/Makefile.am @@ -40,6 +40,10 @@ librakia_la_SOURCES = \ handles.c \ debug.c \ media-manager.c \ + sip-media.c \ + sip-media.h \ + sip-session.c \ + sip-session.h \ text-channel.h \ text-channel.c \ text-manager.c \ diff --git a/rakia/sip-media.c b/rakia/sip-media.c new file mode 100644 index 0000000..b32ec4b --- /dev/null +++ b/rakia/sip-media.c @@ -0,0 +1,108 @@ +/* + * rakia-sip-media.c - Source for RakiaSipMedia + * Copyright (C) 2005-2011 Collabora Ltd. + * @author Olivier Crete <olivier.crete@collabora.com> + * Copyright (C) 2005-2010 Nokia Corporation + * @author Kai Vehmanen <first.surname@nokia.com> + * @author Mikhail Zabaluev <mikhail.zabaluev@nokia.com> + * + * Based on telepathy-gabble implementation + * @author Ole Andre Vadla Ravnaas <ole.andre.ravnaas@collabora.co.uk> + * + * This work is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this work; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "rakia/sip-media.h" + +#include <sofia-sip/sip_status.h> + + +#define DEBUG_FLAG RAKIA_DEBUG_MEDIA +#include "rakia/debug.h" + + +/* The timeout for outstanding re-INVITE transactions in seconds. + * Chosen to match the allowed cancellation timeout for proxies + * described in RFC 3261 Section 13.3.1.1 */ +#define RAKIA_REINVITE_TIMEOUT 180 + +G_DEFINE_TYPE(RakiaSipMedia, + rakia_sip_media, + G_TYPE_OBJECT) + + + +/* private structure */ +struct _RakiaSipMediaPrivate +{ + int empty; +}; + + +#define RAKIA_SIP_MEDIA_GET_PRIVATE(media) ((media)->priv) + + + +static void rakia_sip_media_dispose (GObject *object); +static void rakia_sip_media_finalize (GObject *object); + + +static void +rakia_sip_media_init (RakiaSipMedia *self) +{ + RakiaSipMediaPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + RAKIA_TYPE_SIP_MEDIA, RakiaSipMediaPrivate); + + self->priv = priv; +} + +static void +rakia_sip_media_class_init (RakiaSipMediaClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (RakiaSipMediaPrivate)); + + object_class->dispose = rakia_sip_media_dispose; + object_class->finalize = rakia_sip_media_finalize; +} + + +static void +rakia_sip_media_dispose (GObject *object) +{ + // RakiaSipMedia *self = RAKIA_SIP_MEDIA (object); + + DEBUG("enter"); + + if (G_OBJECT_CLASS (rakia_sip_media_parent_class)->dispose) + G_OBJECT_CLASS (rakia_sip_media_parent_class)->dispose (object); + + DEBUG("exit"); +} + +static void +rakia_sip_media_finalize (GObject *object) +{ + //RakiaSipMedia *self = RAKIA_SIP_MEDIA (object); + + G_OBJECT_CLASS (rakia_sip_media_parent_class)->finalize (object); + + DEBUG("exit"); +} + + diff --git a/rakia/sip-media.h b/rakia/sip-media.h new file mode 100644 index 0000000..d318bfb --- /dev/null +++ b/rakia/sip-media.h @@ -0,0 +1,62 @@ +/* + * rakia-sip-media.h - Header for RakiaSipMedia + * Copyright (C) 2005-2012 Collabora Ltd. + * Copyright (C) 2005-2010 Nokia Corporation + * + * This work is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this work; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __RAKIA_SIP_MEDIA_H__ +#define __RAKIA_SIP_MEDIA_H__ + +#include <glib-object.h> +#include <telepathy-glib/handle.h> +#include <sofia-sip/sdp.h> + +G_BEGIN_DECLS + + +typedef struct _RakiaSipMedia RakiaSipMedia; +typedef struct _RakiaSipMediaClass RakiaSipMediaClass; +typedef struct _RakiaSipMediaPrivate RakiaSipMediaPrivate; + +struct _RakiaSipMediaClass { + GObjectClass parent_class; +}; + +struct _RakiaSipMedia { + GObject parent; + RakiaSipMediaPrivate *priv; +}; + +GType rakia_sip_media_get_type(void); + +/* TYPE MACROS */ +#define RAKIA_TYPE_SIP_MEDIA \ + (rakia_sip_media_get_type()) +#define RAKIA_SIP_MEDIA(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), RAKIA_TYPE_SIP_MEDIA, RakiaSipMedia)) +#define RAKIA_SIP_MEDIA_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), RAKIA_TYPE_SIP_MEDIA, RakiaSipMediaClass)) +#define RAKIA_IS_SIP_MEDIA(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), RAKIA_TYPE_SIP_MEDIA)) +#define RAKIA_IS_SIP_MEDIA_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), RAKIA_TYPE_SIP_MEDIA)) +#define RAKIA_SIP_MEDIA_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), RAKIA_TYPE_SIP_MEDIA, RakiaSipMediaClass)) + +G_END_DECLS + +#endif /* #ifndef __RAKIA_SIP_MEDIA_H__*/ diff --git a/rakia/sip-session.c b/rakia/sip-session.c new file mode 100644 index 0000000..57d2a8c --- /dev/null +++ b/rakia/sip-session.c @@ -0,0 +1,165 @@ +/* + * rakia-sip-session.c - Source for RakiaSipSession + * Copyright (C) 2005-2011 Collabora Ltd. + * @author Olivier Crete <olivier.crete@collabora.com> + * Copyright (C) 2005-2010 Nokia Corporation + * @author Kai Vehmanen <first.surname@nokia.com> + * @author Mikhail Zabaluev <mikhail.zabaluev@nokia.com> + * + * Based on telepathy-gabble implementation + * @author Ole Andre Vadla Ravnaas <ole.andre.ravnaas@collabora.co.uk> + * + * This work is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this work; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "rakia/sip-session.h" + +#include <sofia-sip/sip_status.h> + + +#define DEBUG_FLAG RAKIA_DEBUG_MEDIA +#include "rakia/debug.h" + + +/* The timeout for outstanding re-INVITE transactions in seconds. + * Chosen to match the allowed cancellation timeout for proxies + * described in RFC 3261 Section 13.3.1.1 */ +#define RAKIA_REINVITE_TIMEOUT 180 + +G_DEFINE_TYPE(RakiaSipSession, + rakia_sip_session, + G_TYPE_OBJECT) + + + +#ifdef ENABLE_DEBUG + +/** + * Sip session states: + * - created, objects created, local cand/codec query ongoing + * - invite-sent, an INVITE with local SDP sent, awaiting response + * - invite-received, a remote INVITE received, response is pending + * - response-received, a 200 OK received, codec intersection is in progress + * - active, codecs and candidate pairs have been negotiated (note, + * SteamEngine might still fail to verify connectivity and report + * an error) + * - reinvite-sent, a local re-INVITE sent, response is pending + * - reinvite-received, a remote re-INVITE received, response is pending + * - ended, session has ended + */ +static const char *const session_states[NUM_RAKIA_SIP_SESSION_STATES] = +{ + "created", + "invite-sent", + "invite-received", + "response-received", + "active", + "reinvite-sent", + "reinvite-received", + "reinvite-pending", + "ended" +}; + +#define SESSION_DEBUG(session, format, ...) \ + rakia_log (DEBUG_FLAG, G_LOG_LEVEL_DEBUG, "session [%-17s]: " format, \ + session_states[(session)->priv->state],##__VA_ARGS__) + +#define SESSION_MESSAGE(session, format, ...) \ + rakia_log (DEBUG_FLAG, G_LOG_LEVEL_MESSAGE, "session [%-17s]: " format, \ + session_states[(session)->priv->state],##__VA_ARGS__) + +#else /* !ENABLE_DEBUG */ + +#define SESSION_DEBUG(session, format, ...) G_STMT_START { } G_STMT_END +#define SESSION_MESSAGE(session, format, ...) G_STMT_START { } G_STMT_END + +#endif /* ENABLE_DEBUG */ + + +/* private structure */ +struct _RakiaSipSessionPrivate +{ + RakiaSipSessionState state; /* session state */ + + GPtrArray *streams; +}; + + +#define RAKIA_SIP_SESSION_GET_PRIVATE(session) ((session)->priv) + + + +static void rakia_sip_session_dispose (GObject *object); +static void rakia_sip_session_finalize (GObject *object); + + +static void +rakia_sip_session_init (RakiaSipSession *self) +{ + RakiaSipSessionPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + RAKIA_TYPE_SIP_SESSION, RakiaSipSessionPrivate); + + self->priv = priv; + + priv->state = RAKIA_SIP_SESSION_STATE_CREATED; + + /* allocate any data required by the object here */ + priv->streams = g_ptr_array_new_with_free_func (g_object_unref); +} + +static void +rakia_sip_session_class_init (RakiaSipSessionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (RakiaSipSessionPrivate)); + + object_class->dispose = rakia_sip_session_dispose; + object_class->finalize = rakia_sip_session_finalize; +} + + +static void +rakia_sip_session_dispose (GObject *object) +{ + RakiaSipSession *self = RAKIA_SIP_SESSION (object); + + DEBUG("enter"); + + if (self->priv->streams) + { + g_ptr_array_unref (self->priv->streams); + self->priv->streams = NULL; + } + + if (G_OBJECT_CLASS (rakia_sip_session_parent_class)->dispose) + G_OBJECT_CLASS (rakia_sip_session_parent_class)->dispose (object); + + DEBUG("exit"); +} + +static void +rakia_sip_session_finalize (GObject *object) +{ + //RakiaSipSession *self = RAKIA_SIP_SESSION (object); + + G_OBJECT_CLASS (rakia_sip_session_parent_class)->finalize (object); + + DEBUG("exit"); +} + + diff --git a/rakia/sip-session.h b/rakia/sip-session.h new file mode 100644 index 0000000..515c137 --- /dev/null +++ b/rakia/sip-session.h @@ -0,0 +1,118 @@ +/* + * rakia-sip-session.h - Header for RakiaSipSession + * Copyright (C) 2005-2012 Collabora Ltd. + * Copyright (C) 2005-2010 Nokia Corporation + * + * This work is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this work; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __RAKIA_SIP_SESSION_H__ +#define __RAKIA_SIP_SESSION_H__ + +#include <glib-object.h> +#include <telepathy-glib/handle.h> +#include <sofia-sip/sdp.h> + +G_BEGIN_DECLS + +typedef enum { + RAKIA_SIP_SESSION_STATE_CREATED = 0, + RAKIA_SIP_SESSION_STATE_INVITE_SENT, + RAKIA_SIP_SESSION_STATE_INVITE_RECEIVED, + RAKIA_SIP_SESSION_STATE_RESPONSE_RECEIVED, + RAKIA_SIP_SESSION_STATE_ACTIVE, + RAKIA_SIP_SESSION_STATE_REINVITE_SENT, + RAKIA_SIP_SESSION_STATE_REINVITE_RECEIVED, + RAKIA_SIP_SESSION_STATE_REINVITE_PENDING, + RAKIA_SIP_SESSION_STATE_ENDED, + + NUM_RAKIA_SIP_SESSION_STATES +} RakiaSipSessionState; + + +typedef enum { + RAKIA_SIP_MEDIA_TYPE_AUDIO, + RAKIA_SIP_MEDIA_TYPE_VIDEO +} RakiaSipMediaType; + +typedef struct _RakiaSipSession RakiaSipSession; +typedef struct _RakiaSipSessionClass RakiaSipSessionClass; +typedef struct _RakiaSipSessionPrivate RakiaSipSessionPrivate; + +struct _RakiaSipSessionClass { + GObjectClass parent_class; +}; + +struct _RakiaSipSession { + GObject parent; + RakiaSipSessionPrivate *priv; +}; + +GType rakia_sip_session_get_type(void); + +/* TYPE MACROS */ +#define RAKIA_TYPE_SIP_SESSION \ + (rakia_sip_session_get_type()) +#define RAKIA_SIP_SESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), RAKIA_TYPE_SIP_SESSION, RakiaSipSession)) +#define RAKIA_SIP_SESSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), RAKIA_TYPE_SIP_SESSION, RakiaSipSessionClass)) +#define RAKIA_IS_SIP_SESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), RAKIA_TYPE_SIP_SESSION)) +#define RAKIA_IS_SIP_SESSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), RAKIA_TYPE_SIP_SESSION)) +#define RAKIA_SIP_SESSION_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), RAKIA_TYPE_SIP_SESSION, RakiaSipSessionClass)) + +void rakia_sip_session_terminate (RakiaSipSession *session); +RakiaSipSessionState rakia_sip_session_get_state (RakiaSipSession *session); +void rakia_sip_session_change_state (RakiaSipSession *session, + RakiaSipSessionState new_state); +gboolean rakia_sip_session_set_remote_sip (RakiaSipSession *chan, + const sdp_session_t* r_sdp); +#if 0 +RakiaSipMedia* rakia_sip_session_add_media (RakiaSipSession *self, + guint media_type, + TpMediaMediaDirection direction, + gboolean created_locally); +#endif + +void rakia_sip_session_receive_invite (RakiaSipSession *self); +void rakia_sip_session_receive_reinvite (RakiaSipSession *self); +void rakia_sip_session_accept (RakiaSipSession *self); +void rakia_sip_session_respond (RakiaSipSession *self, + gint status, + const char *message); +gboolean rakia_sip_session_is_accepted (RakiaSipSession *self); +void rakia_sip_session_resolve_glare (RakiaSipSession *self); + +TpLocalHoldState rakia_sip_session_get_hold_state (RakiaSipSession *session); +void rakia_sip_session_request_hold (RakiaSipSession *session, + gboolean hold); + +gboolean rakia_sip_session_has_sip (RakiaSipSession *self, + RakiaSipMediaType media_type); + +gint rakia_sip_session_rate_native_transport (RakiaSipSession *session, + const GValue *transport); + +gboolean rakia_sdp_rtcp_bandwidth_throttled (const sdp_bandwidth_t *b); + +gchar * rakia_sdp_get_string_attribute (const sdp_attribute_t *attrs, + const char *name); + +G_END_DECLS + +#endif /* #ifndef __RAKIA_SIP_SESSION_H__*/ |