avoid a memory leak in case of a restart
[sipe-libnice.git] / agent / component.h
blob1b196ce6e3990d01146d886f3dac0fec61e58303
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006, 2007 Collabora Ltd.
5 * Contact: Dafydd Harries
6 * (C) 2006, 2007 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
17 * License.
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
24 * Contributors:
25 * Dafydd Harries, Collabora Ltd.
26 * Kai Vehmanen, Nokia
28 * Alternatively, the contents of this file may be used under the terms of the
29 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
30 * case the provisions of LGPL are applicable instead of those above. If you
31 * wish to allow use of your version of this file only under the terms of the
32 * LGPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replace
34 * them with the notice and other provisions required by the LGPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the LGPL.
39 #ifndef _NICE_COMPONENT_H
40 #define _NICE_COMPONENT_H
42 #include <glib.h>
44 #include "agent.h"
45 #include "candidate.h"
46 #include "stun/stunagent.h"
47 #include "stun/usages/timer.h"
49 G_BEGIN_DECLS
52 /* (ICE ยง4.1.1.1, ID-19) ""For RTP-based media streams, the RTP itself has a component
53 * ID of 1, and RTCP a component ID of 2. If an agent is using RTCP it MUST
54 * obtain a candidate for it. If an agent is using both RTP and RTCP, it
55 * would end up with 2*K host candidates if an agent has K interfaces.""
58 typedef struct _Component Component;
59 typedef struct _CandidatePair CandidatePair;
60 typedef struct _CandidatePairKeepalive CandidatePairKeepalive;
61 typedef struct _IncomingCheck IncomingCheck;
63 struct _CandidatePairKeepalive
65 NiceAgent *agent;
66 GSource *tick_source;
67 guint stream_id;
68 guint component_id;
69 StunTimer timer;
70 uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE];
71 StunMessage stun_message;
74 struct _CandidatePair
76 NiceCandidate *local;
77 NiceCandidate *remote;
78 guint64 priority; /**< candidate pair priority */
79 CandidatePairKeepalive keepalive;
82 struct _IncomingCheck
84 NiceAddress from;
85 NiceSocket *local_socket;
86 guint32 priority;
87 gboolean use_candidate;
88 uint8_t *username;
89 uint16_t username_len;
92 struct _Component
94 NiceComponentType type;
95 guint id; /**< component id */
96 NiceComponentState state;
97 GSList *local_candidates; /**< list of Candidate objs */
98 GSList *remote_candidates; /**< list of Candidate objs */
99 GSList *sockets; /**< list of NiceSocket objs */
100 GSList *gsources; /**< list of GSource objs */
101 GSList *incoming_checks; /**< list of IncomingCheck objs */
102 GList *turn_servers; /**< List of TURN servers */
103 CandidatePair selected_pair; /**< independent from checklists,
104 see ICE 11.1. "Sending Media" (ID-19) */
105 NiceCandidate *restart_candidate; /**< for storing active remote candidate during a restart */
106 NiceAgentRecvFunc g_source_io_cb; /**< function called on io cb */
107 gpointer data; /**< data passed to the io function */
108 GMainContext *ctx; /**< context for data callbacks for this
109 component */
112 Component *
113 component_new (
114 G_GNUC_UNUSED
115 guint component_id);
117 void
118 component_free (Component *cmp);
120 gboolean
121 component_find_pair (Component *cmp, NiceAgent *agent, const gchar *lfoundation, const gchar *rfoundation, CandidatePair *pair);
123 gboolean
124 component_restart (Component *cmp);
126 void
127 component_update_selected_pair (Component *component, const CandidatePair *pair);
129 NiceCandidate *
130 component_find_remote_candidate (const Component *component, const NiceAddress *addr, NiceCandidateTransport transport);
132 NiceCandidate *
133 component_set_selected_remote_candidate (NiceAgent *agent, Component *component,
134 NiceCandidate *candidate);
136 G_END_DECLS
138 #endif /* _NICE_COMPONENT_H */