blob: a461bdf6e43fb456b67b4f7dfffb7d7f5529bd34 [file] [log] [blame]
Alexandre Lision8af73cb2013-12-10 14:11:20 -05001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJMEDIA_TRANSPORT_ICE_H__
21#define __PJMEDIA_TRANSPORT_ICE_H__
22
23
24/**
25 * @file transport_ice.h
26 * @brief ICE capable media transport.
27 */
28
29#include <pjmedia/stream.h>
30#include <pjnath/ice_strans.h>
31
32
33/**
34 * @defgroup PJMEDIA_TRANSPORT_ICE ICE Media Transport
35 * @ingroup PJMEDIA_TRANSPORT
36 * @brief Interactive Connectivity Establishment (ICE) transport
37 * @{
38 *
39 * This describes the implementation of media transport using
40 * Interactive Connectivity Establishment (ICE) protocol.
41 */
42
43PJ_BEGIN_DECL
44
45
46/**
47 * Structure containing callbacks to receive ICE notifications.
48 */
49typedef struct pjmedia_ice_cb
50{
51 /**
52 * This callback will be called when ICE negotiation completes.
53 *
54 * @param tp PJMEDIA ICE transport.
55 * @param op The operation
56 * @param status Operation status.
57 */
58 void (*on_ice_complete)(pjmedia_transport *tp,
59 pj_ice_strans_op op,
60 pj_status_t status);
61
62} pjmedia_ice_cb;
63
64
65/**
66 * This structure specifies ICE transport specific info. This structure
67 * will be filled in media transport specific info.
68 */
69typedef struct pjmedia_ice_transport_info
70{
71 /**
72 * Specifies whether ICE is used, i.e. SDP offer and answer indicates
73 * that both parties support ICE and ICE should be used for the session.
74 */
75 pj_bool_t active;
76
77 /**
78 * ICE sesion state.
79 */
80 pj_ice_strans_state sess_state;
81
82 /**
83 * Session role.
84 */
85 pj_ice_sess_role role;
86
87 /**
88 * Number of components in the component array. Before ICE negotiation
89 * is complete, the number represents the number of components of the
90 * local agent. After ICE negotiation has been completed successfully,
91 * the number represents the number of common components between local
92 * and remote agents.
93 */
94 unsigned comp_cnt;
95
96 /**
97 * Array of ICE components. Typically the first element denotes RTP and
98 * second element denotes RTCP.
99 */
100 struct
101 {
102 /**
103 * Local candidate type.
104 */
105 pj_ice_cand_type lcand_type;
106
107 /**
108 * The local address.
109 */
110 pj_sockaddr lcand_addr;
111
112 /**
113 * Remote candidate type.
114 */
115 pj_ice_cand_type rcand_type;
116
117 /**
118 * Remote address.
119 */
120 pj_sockaddr rcand_addr;
121
122 } comp[2];
123
124} pjmedia_ice_transport_info;
125
126
127/**
128 * Options that can be specified when creating ICE transport.
129 */
130enum pjmedia_transport_ice_options
131{
132 /**
133 * Normally when remote doesn't use ICE, the ICE transport will
134 * continuously check the source address of incoming packets to see
135 * if it is different than the configured remote address, and switch
136 * the remote address to the source address of the packet if they
137 * are different after several packets are received.
138 * Specifying this option will disable this feature.
139 */
140 PJMEDIA_ICE_NO_SRC_ADDR_CHECKING = 1
141};
142
143
144/**
145 * Create the Interactive Connectivity Establishment (ICE) media transport
146 * using the specified configuration. When STUN or TURN (or both) is used,
147 * the creation operation will complete asynchronously, when STUN resolution
148 * and TURN allocation completes. When the initialization completes, the
149 * \a on_ice_complete() complete will be called with \a op parameter equal
150 * to PJ_ICE_STRANS_OP_INIT.
151 *
152 * In addition, this transport will also notify the application about the
153 * result of ICE negotiation, also in \a on_ice_complete() callback. In this
154 * case the callback will be called with \a op parameter equal to
155 * PJ_ICE_STRANS_OP_NEGOTIATION.
156 *
157 * Other than this, application should use the \ref PJMEDIA_TRANSPORT API
158 * to manipulate this media transport.
159 *
160 * @param endpt The media endpoint.
161 * @param name Optional name to identify this ICE media transport
162 * for logging purposes.
163 * @param comp_cnt Number of components to be created.
164 * @param cfg Pointer to configuration settings.
165 * @param cb Optional structure containing ICE specific callbacks.
166 * @param p_tp Pointer to receive the media transport instance.
167 *
168 * @return PJ_SUCCESS on success, or the appropriate error code.
169 */
170PJ_DECL(pj_status_t) pjmedia_ice_create(pjmedia_endpt *endpt,
171 const char *name,
172 unsigned comp_cnt,
173 const pj_ice_strans_cfg *cfg,
174 const pjmedia_ice_cb *cb,
175 pjmedia_transport **p_tp);
176
177
178/**
179 * The same as #pjmedia_ice_create() with additional \a options param.
180 *
181 * @param endpt The media endpoint.
182 * @param name Optional name to identify this ICE media transport
183 * for logging purposes.
184 * @param comp_cnt Number of components to be created.
185 * @param cfg Pointer to configuration settings.
186 * @param cb Optional structure containing ICE specific callbacks.
187 * @param options Options, see #pjmedia_transport_ice_options.
188 * @param p_tp Pointer to receive the media transport instance.
189 *
190 * @return PJ_SUCCESS on success, or the appropriate error code.
191 */
192PJ_DECL(pj_status_t) pjmedia_ice_create2(pjmedia_endpt *endpt,
193 const char *name,
194 unsigned comp_cnt,
195 const pj_ice_strans_cfg *cfg,
196 const pjmedia_ice_cb *cb,
197 unsigned options,
198 pjmedia_transport **p_tp);
199
200/**
201 * The same as #pjmedia_ice_create2() with additional \a user_data param.
202 *
203 * @param endpt The media endpoint.
204 * @param name Optional name to identify this ICE media transport
205 * for logging purposes.
206 * @param comp_cnt Number of components to be created.
207 * @param cfg Pointer to configuration settings.
208 * @param cb Optional structure containing ICE specific callbacks.
209 * @param options Options, see #pjmedia_transport_ice_options.
210 * @param user_data User data to be attached to the transport.
211 * @param p_tp Pointer to receive the media transport instance.
212 *
213 * @return PJ_SUCCESS on success, or the appropriate error code.
214 */
215PJ_DECL(pj_status_t) pjmedia_ice_create3(pjmedia_endpt *endpt,
216 const char *name,
217 unsigned comp_cnt,
218 const pj_ice_strans_cfg *cfg,
219 const pjmedia_ice_cb *cb,
220 unsigned options,
221 void *user_data,
222 pjmedia_transport **p_tp);
223
224/**
225 * Get the group lock for the ICE media transport.
226 *
227 * @param tp The ICE media transport.
228 *
229 * @return The group lock.
230 */
231PJ_DECL(pj_grp_lock_t *) pjmedia_ice_get_grp_lock(pjmedia_transport *tp);
232
233PJ_END_DECL
234
235
236/**
237 * @}
238 */
239
240
241#endif /* __PJMEDIA_TRANSPORT_ICE_H__ */
242
243