~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.2.1/pjnath/include/pjnath/ice_strans.h

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Mark Purcell
  • Date: 2014-10-18 15:08:50 UTC
  • mfrom: (1.1.12)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20141018150850-2exfk34ckb15pcwi
Tags: 1.4.1-0.1
[ Francois Marier ]
* Non-maintainer upload
* New upstream release (closes: #759576, #741130)
  - debian/rules +PJPROJECT_VERSION := 2.2.1
  - add upstream patch to fix broken TLS support
  - add patch to fix pjproject regression

[ Mark Purcell ]
* Build-Depends:
  - sflphone-daemon + libavformat-dev, libavcodec-dev, libswscale-dev,
  libavdevice-dev, libavutil-dev
  - sflphone-gnome + libclutter-gtk-1.0-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ice_strans.h 4606 2013-10-01 05:00:57Z ming $ */
 
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 __PJNATH_ICE_STRANS_H__
 
21
#define __PJNATH_ICE_STRANS_H__
 
22
 
 
23
 
 
24
/**
 
25
 * @file ice_strans.h
 
26
 * @brief ICE Stream Transport
 
27
 */
 
28
#include <pjnath/ice_session.h>
 
29
#include <pjnath/stun_sock.h>
 
30
#include <pjnath/turn_sock.h>
 
31
#include <pjlib-util/resolver.h>
 
32
#include <pj/ioqueue.h>
 
33
#include <pj/timer.h>
 
34
 
 
35
 
 
36
PJ_BEGIN_DECL
 
37
 
 
38
 
 
39
/**
 
40
 * @addtogroup PJNATH_ICE_STREAM_TRANSPORT
 
41
 * @{
 
42
 *
 
43
 * This module describes ICE stream transport, as represented by #pj_ice_strans
 
44
 * structure, and is part of PJNATH - the Open Source NAT traversal helper
 
45
 * library.
 
46
 *
 
47
 * ICE stream transport, as represented by #pj_ice_strans structure, is an ICE
 
48
 * capable class for transporting media streams within a media session. 
 
49
 * It consists of one or more transport sockets (typically two for RTP
 
50
 * based communication - one for RTP and one for RTCP), and an 
 
51
 * \ref PJNATH_ICE_SESSION for performing connectivity checks among the.
 
52
 * various candidates of the transport addresses.
 
53
 *
 
54
 *
 
55
 * \section ice_strans_using_sec Using the ICE stream transport
 
56
 *
 
57
 * The steps below describe how to use ICE session:
 
58
 *
 
59
 *  - initialize a #pj_ice_strans_cfg structure. This contains various 
 
60
 *    settings for the ICE stream transport, and among other things contains
 
61
 *    the STUN and TURN settings.\n\n
 
62
 *  - create the instance with #pj_ice_strans_create(). Among other things,
 
63
 *    the function needs the following arguments:
 
64
 *      - the #pj_ice_strans_cfg structure for the main configurations
 
65
 *      - number of components to be supported
 
66
 *      - instance of #pj_ice_strans_cb structure to report callbacks to
 
67
 *        application.\n\n
 
68
 *  - while the #pj_ice_strans_create() call completes immediately, the
 
69
 *    initialization will be running in the background to gather the 
 
70
 *    candidates (for example STUN and TURN candidates, if they are enabled
 
71
 *    in the #pj_ice_strans_cfg setting). Application will be notified when
 
72
 *    the initialization completes in the \a on_ice_complete callback of
 
73
 *    the #pj_ice_strans_cb structure (the \a op argument of this callback
 
74
 *    will be PJ_ICE_STRANS_OP_INIT).\n\n
 
75
 *  - when media stream is to be started (for example, a call is to be 
 
76
 *    started), create an ICE session by calling #pj_ice_strans_init_ice().\n\n
 
77
 *  - the application now typically will need to communicate local ICE
 
78
 *    information to remote host. It can achieve this by using the following
 
79
 *    functions to query local ICE information:
 
80
 *      - #pj_ice_strans_get_ufrag_pwd()
 
81
 *      - #pj_ice_strans_enum_cands()
 
82
 *      - #pj_ice_strans_get_def_cand()\n
 
83
 *    The application may need to encode the above information as SDP.\n\n
 
84
 *  - when the application receives remote ICE information (for example, from
 
85
 *    the SDP received from remote), it can now start ICE negotiation, by
 
86
 *    calling #pj_ice_strans_start_ice(). This function requires some
 
87
 *    information about remote ICE agent such as remote ICE username fragment
 
88
 *    and password as well as array of remote candidates.\n\n
 
89
 *  - note that the PJNATH library does not work with SDP; application would
 
90
 *    need to encode and parse the SDP itself.\n\n
 
91
 *  - once ICE negotiation has been started, application will be notified
 
92
 *    about the completion in the \a on_ice_complete() callback of the
 
93
 *    #pj_ice_strans_cb.\n\n
 
94
 *  - at any time, application may send or receive data. However the ICE
 
95
 *    stream transport may not be able to send it depending on its current
 
96
 *    state. Before ICE negotiation is started, the data will be sent using
 
97
 *    default candidate of the component. After negotiation is completed,
 
98
 *    data will be sent using the candidate from the successful/nominated
 
99
 *    pair. The ICE stream transport may not be able to send data while 
 
100
 *    negotiation is in progress.\n\n
 
101
 *  - application sends data by using #pj_ice_strans_sendto(). Incoming
 
102
 *    data will be reported in \a on_rx_data() callback of the
 
103
 *    #pj_ice_strans_cb.\n\n
 
104
 *  - once the media session has finished (e.g. user hangs up the call),
 
105
 *    destroy the ICE session with #pj_ice_strans_stop_ice().\n\n
 
106
 *  - at this point, application may destroy the ICE stream transport itself,
 
107
 *    or let it run so that it can be reused to create other ICE session.
 
108
 *    The benefit of letting the ICE stream transport alive (without any
 
109
 *    session active) is to avoid delay with the initialization, howerver
 
110
 *    keeping the transport alive means the transport needs to keep the
 
111
 *    STUN binding open by using keep-alive and also TURN allocation alive,
 
112
 *    and this will consume power which is an important issue for mobile
 
113
 *    applications.\n\n
 
114
 */
 
115
 
 
116
/** Forward declaration for ICE stream transport. */
 
117
typedef struct pj_ice_strans pj_ice_strans;
 
118
 
 
119
/** Transport operation types to be reported on \a on_status() callback */
 
120
typedef enum pj_ice_strans_op
 
121
{
 
122
    /** Initialization (candidate gathering) */
 
123
    PJ_ICE_STRANS_OP_INIT,
 
124
 
 
125
    /** Negotiation */
 
126
    PJ_ICE_STRANS_OP_NEGOTIATION,
 
127
 
 
128
    /** This operatino is used to report failure in keep-alive operation.
 
129
     *  Currently it is only used to report TURN Refresh failure.
 
130
     */
 
131
    PJ_ICE_STRANS_OP_KEEP_ALIVE
 
132
 
 
133
} pj_ice_strans_op;
 
134
 
 
135
/** 
 
136
 * This structure contains callbacks that will be called by the 
 
137
 * ICE stream transport.
 
138
 */
 
139
typedef struct pj_ice_strans_cb
 
140
{
 
141
    /**
 
142
     * This callback will be called when the ICE transport receives
 
143
     * incoming packet from the sockets which is not related to ICE
 
144
     * (for example, normal RTP/RTCP packet destined for application).
 
145
     *
 
146
     * @param ice_st        The ICE stream transport.
 
147
     * @param comp_id       The component ID.
 
148
     * @param pkt           The packet.
 
149
     * @param size          Size of the packet.
 
150
     * @param src_addr      Source address of the packet.
 
151
     * @param src_addr_len  Length of the source address.
 
152
     */
 
153
    void    (*on_rx_data)(pj_ice_strans *ice_st,
 
154
                          unsigned comp_id, 
 
155
                          void *pkt, pj_size_t size,
 
156
                          const pj_sockaddr_t *src_addr,
 
157
                          unsigned src_addr_len);
 
158
 
 
159
    /**
 
160
     * Callback to report status of various ICE operations.
 
161
     * 
 
162
     * @param ice_st        The ICE stream transport.
 
163
     * @param op            The operation which status is being reported.
 
164
     * @param status        Operation status.
 
165
     */
 
166
    void    (*on_ice_complete)(pj_ice_strans *ice_st, 
 
167
                               pj_ice_strans_op op,
 
168
                               pj_status_t status);
 
169
 
 
170
} pj_ice_strans_cb;
 
171
 
 
172
 
 
173
/**
 
174
 * This structure describes ICE stream transport configuration. Application
 
175
 * should initialize the structure by calling #pj_ice_strans_cfg_default()
 
176
 * before changing the settings.
 
177
 */
 
178
typedef struct pj_ice_strans_cfg
 
179
{
 
180
    /**
 
181
     * Address family, IPv4 or IPv6. Currently only pj_AF_INET() (IPv4)
 
182
     * is supported, and this is the default value.
 
183
     */
 
184
    int                 af;
 
185
 
 
186
    /**
 
187
     * STUN configuration which contains the timer heap and
 
188
     * ioqueue instance to be used, and STUN retransmission
 
189
     * settings. This setting is mandatory.
 
190
     *
 
191
     * The default value is all zero. Application must initialize
 
192
     * this setting with #pj_stun_config_init().
 
193
     */
 
194
    pj_stun_config       stun_cfg;
 
195
 
 
196
    /**
 
197
     * DNS resolver to be used to resolve servers. If DNS SRV
 
198
     * resolution is required, the resolver must be set.
 
199
     *
 
200
     * The default value is NULL.
 
201
     */
 
202
    pj_dns_resolver     *resolver;
 
203
 
 
204
    /**
 
205
     * This contains various STUN session options. Once the ICE stream
 
206
     * transport is created, application may also change the options
 
207
     * with #pj_ice_strans_set_options().
 
208
     */
 
209
    pj_ice_sess_options  opt;
 
210
 
 
211
    /**
 
212
     * STUN and local transport settings. This specifies the 
 
213
     * settings for local UDP socket, which will be resolved
 
214
     * to get the STUN mapped address.
 
215
     */
 
216
    struct {
 
217
        /**
 
218
         * Optional configuration for STUN transport. The default
 
219
         * value will be initialized with #pj_stun_sock_cfg_default().
 
220
         */
 
221
        pj_stun_sock_cfg     cfg;
 
222
 
 
223
        /**
 
224
         * Maximum number of host candidates to be added. If the
 
225
         * value is zero, no host candidates will be added.
 
226
         *
 
227
         * Default: 64
 
228
         */
 
229
        unsigned             max_host_cands;
 
230
 
 
231
        /**
 
232
         * Include loopback addresses in the host candidates.
 
233
         *
 
234
         * Default: PJ_FALSE
 
235
         */
 
236
        pj_bool_t            loop_addr;
 
237
 
 
238
        /**
 
239
         * Specify the STUN server domain or hostname or IP address.
 
240
         * If DNS SRV resolution is required, application must fill
 
241
         * in this setting with the domain name of the STUN server 
 
242
         * and set the resolver instance in the \a resolver field.
 
243
         * Otherwise if the \a resolver setting is not set, this
 
244
         * field will be resolved with hostname resolution and in
 
245
         * this case the \a port field must be set.
 
246
         *
 
247
         * The \a port field should also be set even when DNS SRV
 
248
         * resolution is used, in case the DNS SRV resolution fails.
 
249
         *
 
250
         * When this field is empty, STUN mapped address resolution
 
251
         * will not be performed. In this case only ICE host candidates
 
252
         * will be added to the ICE transport, unless if \a no_host_cands
 
253
         * field is set. In this case, both host and srflx candidates 
 
254
         * are disabled.
 
255
         *
 
256
         * The default value is empty.
 
257
         */
 
258
        pj_str_t             server;
 
259
 
 
260
        /**
 
261
         * The port number of the STUN server, when \a server
 
262
         * field specifies a hostname rather than domain name. This
 
263
         * field should also be set even when the \a server
 
264
         * specifies a domain name, to allow DNS SRV resolution
 
265
         * to fallback to DNS A/AAAA resolution when the DNS SRV
 
266
         * resolution fails.
 
267
         *
 
268
         * The default value is PJ_STUN_PORT.
 
269
         */
 
270
        pj_uint16_t          port;
 
271
 
 
272
        /**
 
273
         * Ignore STUN resolution error and proceed with just local
 
274
         * addresses.
 
275
         *
 
276
         * The default is PJ_FALSE
 
277
         */
 
278
        pj_bool_t            ignore_stun_error;
 
279
 
 
280
    } stun;
 
281
 
 
282
    /**
 
283
     * TURN specific settings.
 
284
     */
 
285
    struct {
 
286
        /**
 
287
         * Optional TURN socket settings. The default values will be
 
288
         * initialized by #pj_turn_sock_cfg_default(). This contains
 
289
         * settings such as QoS.
 
290
         */
 
291
        pj_turn_sock_cfg     cfg;
 
292
 
 
293
        /**
 
294
         * Specify the TURN server domain or hostname or IP address.
 
295
         * If DNS SRV resolution is required, application must fill
 
296
         * in this setting with the domain name of the TURN server 
 
297
         * and set the resolver instance in the \a resolver field.
 
298
         * Otherwise if the \a resolver setting is not set, this
 
299
         * field will be resolved with hostname resolution and in
 
300
         * this case the \a port field must be set.
 
301
         *
 
302
         * The \a port field should also be set even when DNS SRV
 
303
         * resolution is used, in case the DNS SRV resolution fails.
 
304
         *
 
305
         * When this field is empty, relay candidate will not be
 
306
         * created.
 
307
         *
 
308
         * The default value is empty.
 
309
         */
 
310
        pj_str_t             server;
 
311
 
 
312
        /**
 
313
         * The port number of the TURN server, when \a server
 
314
         * field specifies a hostname rather than domain name. This
 
315
         * field should also be set even when the \a server
 
316
         * specifies a domain name, to allow DNS SRV resolution
 
317
         * to fallback to DNS A/AAAA resolution when the DNS SRV
 
318
         * resolution fails.
 
319
         *
 
320
         * Default is zero.
 
321
         */
 
322
        pj_uint16_t          port;
 
323
 
 
324
        /**
 
325
         * Type of connection to the TURN server.
 
326
         *
 
327
         * Default is PJ_TURN_TP_UDP.
 
328
         */
 
329
        pj_turn_tp_type      conn_type;
 
330
 
 
331
        /**
 
332
         * Credential to be used for the TURN session. This setting
 
333
         * is mandatory.
 
334
         *
 
335
         * Default is to have no credential.
 
336
         */
 
337
        pj_stun_auth_cred    auth_cred;
 
338
 
 
339
        /**
 
340
         * Optional TURN Allocate parameter. The default value will be
 
341
         * initialized by #pj_turn_alloc_param_default().
 
342
         */
 
343
        pj_turn_alloc_param  alloc_param;
 
344
 
 
345
    } turn;
 
346
 
 
347
    /**
 
348
     * Component specific settings, which will override the settings in
 
349
     * the STUN and TURN settings above. For example, setting the QoS
 
350
     * parameters here allows the application to have different QoS
 
351
     * traffic type for RTP and RTCP component.
 
352
     */
 
353
    struct {
 
354
        /**
 
355
         * QoS traffic type to be set on this transport. When application
 
356
         * wants to apply QoS tagging to the transport, it's preferable to
 
357
         * set this field rather than \a qos_param fields since this is 
 
358
         * more portable.
 
359
         *
 
360
         * Default value is PJ_QOS_TYPE_BEST_EFFORT.
 
361
         */
 
362
        pj_qos_type qos_type;
 
363
 
 
364
        /**
 
365
         * Set the low level QoS parameters to the transport. This is a 
 
366
         * lower level operation than setting the \a qos_type field and
 
367
         * may not be supported on all platforms.
 
368
         *
 
369
         * By default all settings in this structure are disabled.
 
370
         */
 
371
        pj_qos_params qos_params;
 
372
 
 
373
        /**
 
374
         * Specify target value for socket receive buffer size. It will be
 
375
         * applied using setsockopt(). When it fails to set the specified
 
376
         * size, it will try with lower value until the highest possible is
 
377
         * successfully set.
 
378
         *
 
379
         * When this is set to zero, this component will apply socket receive
 
380
         * buffer size settings specified in STUN and TURN socket config
 
381
         * above, i.e: \a stun::cfg::so_rcvbuf_size and
 
382
         * \a turn::cfg::so_rcvbuf_size. Otherwise, this setting will be
 
383
         * applied to STUN and TURN sockets for this component, overriding
 
384
         * the setting specified in STUN/TURN socket config.
 
385
         *
 
386
         * Default: 0
 
387
         */
 
388
        unsigned so_rcvbuf_size;
 
389
 
 
390
        /**
 
391
         * Specify target value for socket send buffer size. It will be
 
392
         * applied using setsockopt(). When it fails to set the specified
 
393
         * size, it will try with lower value until the highest possible is
 
394
         * successfully set.
 
395
         *
 
396
         * When this is set to zero, this component will apply socket send
 
397
         * buffer size settings specified in STUN and TURN socket config
 
398
         * above, i.e: \a stun::cfg::so_sndbuf_size and
 
399
         * \a turn::cfg::so_sndbuf_size. Otherwise, this setting will be
 
400
         * applied to STUN and TURN sockets for this component, overriding
 
401
         * the setting specified in STUN/TURN socket config.
 
402
         *
 
403
         * Default: 0
 
404
         */
 
405
        unsigned so_sndbuf_size;
 
406
 
 
407
    } comp[PJ_ICE_MAX_COMP];
 
408
 
 
409
} pj_ice_strans_cfg;
 
410
 
 
411
 
 
412
/**
 
413
 * ICE stream transport's state.
 
414
 */
 
415
typedef enum pj_ice_strans_state
 
416
{
 
417
    /**
 
418
     * ICE stream transport is not created.
 
419
     */
 
420
    PJ_ICE_STRANS_STATE_NULL,
 
421
 
 
422
    /**
 
423
     * ICE candidate gathering process is in progress.
 
424
     */
 
425
    PJ_ICE_STRANS_STATE_INIT,
 
426
 
 
427
    /**
 
428
     * ICE stream transport initialization/candidate gathering process is
 
429
     * complete, ICE session may be created on this stream transport.
 
430
     */
 
431
    PJ_ICE_STRANS_STATE_READY,
 
432
 
 
433
    /**
 
434
     * New session has been created and the session is ready.
 
435
     */
 
436
    PJ_ICE_STRANS_STATE_SESS_READY,
 
437
 
 
438
    /**
 
439
     * ICE negotiation is in progress.
 
440
     */
 
441
    PJ_ICE_STRANS_STATE_NEGO,
 
442
 
 
443
    /**
 
444
     * ICE negotiation has completed successfully and media is ready
 
445
     * to be used.
 
446
     */
 
447
    PJ_ICE_STRANS_STATE_RUNNING,
 
448
 
 
449
    /**
 
450
     * ICE negotiation has completed with failure.
 
451
     */
 
452
    PJ_ICE_STRANS_STATE_FAILED
 
453
 
 
454
} pj_ice_strans_state;
 
455
 
 
456
 
 
457
/** 
 
458
 * Initialize ICE transport configuration with default values.
 
459
 *
 
460
 * @param cfg           The configuration to be initialized.
 
461
 */
 
462
PJ_DECL(void) pj_ice_strans_cfg_default(pj_ice_strans_cfg *cfg);
 
463
 
 
464
 
 
465
/**
 
466
 * Copy configuration.
 
467
 *
 
468
 * @param pool          Pool.
 
469
 * @param dst           Destination.
 
470
 * @param src           Source.
 
471
 */
 
472
PJ_DECL(void) pj_ice_strans_cfg_copy(pj_pool_t *pool,
 
473
                                     pj_ice_strans_cfg *dst,
 
474
                                     const pj_ice_strans_cfg *src);
 
475
 
 
476
 
 
477
/**
 
478
 * Create and initialize the ICE stream transport with the specified
 
479
 * parameters. 
 
480
 *
 
481
 * @param name          Optional name for logging identification.
 
482
 * @param cfg           Configuration.
 
483
 * @param comp_cnt      Number of components.
 
484
 * @param user_data     Arbitrary user data to be associated with this
 
485
 *                      ICE stream transport.
 
486
 * @param cb            Callback.
 
487
 * @param p_ice_st      Pointer to receive the ICE stream transport
 
488
 *                      instance.
 
489
 *
 
490
 * @return              PJ_SUCCESS if ICE stream transport is created
 
491
 *                      successfully.
 
492
 */
 
493
PJ_DECL(pj_status_t) pj_ice_strans_create(const char *name,
 
494
                                          const pj_ice_strans_cfg *cfg,
 
495
                                          unsigned comp_cnt,
 
496
                                          void *user_data,
 
497
                                          const pj_ice_strans_cb *cb,
 
498
                                          pj_ice_strans **p_ice_st);
 
499
 
 
500
/**
 
501
 * Get ICE session state.
 
502
 *
 
503
 * @param ice_st        The ICE stream transport.
 
504
 *
 
505
 * @return              ICE session state.
 
506
 */
 
507
PJ_DECL(pj_ice_strans_state) pj_ice_strans_get_state(pj_ice_strans *ice_st);
 
508
 
 
509
 
 
510
/**
 
511
 * Get string representation of ICE state.
 
512
 *
 
513
 * @param state         ICE stream transport state.
 
514
 *
 
515
 * @return              String.
 
516
 */
 
517
PJ_DECL(const char*) pj_ice_strans_state_name(pj_ice_strans_state state);
 
518
 
 
519
 
 
520
/**
 
521
 * Destroy the ICE stream transport. This will destroy the ICE session
 
522
 * inside the ICE stream transport, close all sockets and release all
 
523
 * other resources.
 
524
 *
 
525
 * @param ice_st        The ICE stream transport.
 
526
 *
 
527
 * @return              PJ_SUCCESS, or the appropriate error code.
 
528
 */
 
529
PJ_DECL(pj_status_t) pj_ice_strans_destroy(pj_ice_strans *ice_st);
 
530
 
 
531
 
 
532
/**
 
533
 * Get the user data associated with the ICE stream transport.
 
534
 *
 
535
 * @param ice_st        The ICE stream transport.
 
536
 *
 
537
 * @return              The user data.
 
538
 */
 
539
PJ_DECL(void*) pj_ice_strans_get_user_data(pj_ice_strans *ice_st);
 
540
 
 
541
 
 
542
/**
 
543
 * Get the value of various options of the ICE stream transport.
 
544
 *
 
545
 * @param ice_st        The ICE stream transport.
 
546
 * @param opt           The options to be initialized with the values
 
547
 *                      from the ICE stream transport.
 
548
 *
 
549
 * @return              PJ_SUCCESS on success, or the appropriate error.
 
550
 */
 
551
PJ_DECL(pj_status_t) pj_ice_strans_get_options(pj_ice_strans *ice_st,
 
552
                                               pj_ice_sess_options *opt);
 
553
 
 
554
/**
 
555
 * Specify various options for this ICE stream transport. Application 
 
556
 * should call #pj_ice_strans_get_options() to initialize the options 
 
557
 * with their default values.
 
558
 *
 
559
 * @param ice_st        The ICE stream transport.
 
560
 * @param opt           Options to be applied to this ICE stream transport.
 
561
 *
 
562
 * @return              PJ_SUCCESS on success, or the appropriate error.
 
563
 */
 
564
PJ_DECL(pj_status_t) pj_ice_strans_set_options(pj_ice_strans *ice_st,
 
565
                                               const pj_ice_sess_options *opt);
 
566
 
 
567
/**
 
568
 * Get the group lock for this ICE stream transport.
 
569
 *
 
570
 * @param ice_st        The ICE stream transport.
 
571
 *
 
572
 * @return              The group lock.
 
573
 */
 
574
PJ_DECL(pj_grp_lock_t *) pj_ice_strans_get_grp_lock(pj_ice_strans *ice_st);
 
575
 
 
576
/**
 
577
 * Initialize the ICE session in the ICE stream transport.
 
578
 * When application is about to send an offer containing ICE capability,
 
579
 * or when it receives an offer containing ICE capability, it must
 
580
 * call this function to initialize the internal ICE session. This would
 
581
 * register all transport address aliases for each component to the ICE
 
582
 * session as candidates. Then application can enumerate all local
 
583
 * candidates by calling #pj_ice_strans_enum_cands(), and encode these
 
584
 * candidates in the SDP to be sent to remote agent.
 
585
 *
 
586
 * @param ice_st        The ICE stream transport.
 
587
 * @param role          ICE role.
 
588
 * @param local_ufrag   Optional local username fragment.
 
589
 * @param local_passwd  Optional local password.
 
590
 *
 
591
 * @return              PJ_SUCCESS, or the appropriate error code.
 
592
 */
 
593
PJ_DECL(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
 
594
                                            pj_ice_sess_role role,
 
595
                                            const pj_str_t *local_ufrag,
 
596
                                            const pj_str_t *local_passwd);
 
597
 
 
598
/**
 
599
 * Check if the ICE stream transport has the ICE session created. The
 
600
 * ICE session is created with #pj_ice_strans_init_ice().
 
601
 *
 
602
 * @param ice_st        The ICE stream transport.
 
603
 *
 
604
 * @return              PJ_TRUE if #pj_ice_strans_init_ice() has been
 
605
 *                      called.
 
606
 */
 
607
PJ_DECL(pj_bool_t) pj_ice_strans_has_sess(pj_ice_strans *ice_st);
 
608
 
 
609
 
 
610
/**
 
611
 * Check if ICE negotiation is still running.
 
612
 *
 
613
 * @param ice_st        The ICE stream transport.
 
614
 *
 
615
 * @return              PJ_TRUE if ICE session has been created and ICE 
 
616
 *                      negotiation negotiation is in progress.
 
617
 */
 
618
PJ_DECL(pj_bool_t) pj_ice_strans_sess_is_running(pj_ice_strans *ice_st);
 
619
 
 
620
 
 
621
/**
 
622
 * Check if ICE negotiation has completed.
 
623
 *
 
624
 * @param ice_st        The ICE stream transport.
 
625
 *
 
626
 * @return              PJ_TRUE if ICE session has been created and the
 
627
 *                      negotiation is complete.
 
628
 */
 
629
PJ_DECL(pj_bool_t) pj_ice_strans_sess_is_complete(pj_ice_strans *ice_st);
 
630
 
 
631
 
 
632
/**
 
633
 * Get the current/running component count. If ICE negotiation has not
 
634
 * been started, the number of components will be equal to the number
 
635
 * when the ICE stream transport was created. Once negotiation been
 
636
 * started, the number of components will be the lowest number of 
 
637
 * component between local and remote agents.
 
638
 *
 
639
 * @param ice_st        The ICE stream transport.
 
640
 *
 
641
 * @return              The running number of components.
 
642
 */
 
643
PJ_DECL(unsigned) pj_ice_strans_get_running_comp_cnt(pj_ice_strans *ice_st);
 
644
 
 
645
 
 
646
/**
 
647
 * Get the ICE username fragment and password of the ICE session. The
 
648
 * local username fragment and password can only be retrieved once ICE
 
649
 * session has been created with #pj_ice_strans_init_ice(). The remote
 
650
 * username fragment and password can only be retrieved once ICE session
 
651
 * has been started with #pj_ice_strans_start_ice().
 
652
 *
 
653
 * Note that the string returned by this function is only valid throughout
 
654
 * the duration of the ICE session, and the application must not modify
 
655
 * these strings. Once the ICE session has been stopped with
 
656
 * #pj_ice_strans_stop_ice(), the pointer in the string will no longer be
 
657
 * valid.
 
658
 *
 
659
 * @param ice_st        The ICE stream transport.
 
660
 * @param loc_ufrag     Optional pointer to receive ICE username fragment
 
661
 *                      of local endpoint from the ICE session.
 
662
 * @param loc_pwd       Optional pointer to receive ICE password of local
 
663
 *                      endpoint from the ICE session.
 
664
 * @param rem_ufrag     Optional pointer to receive ICE username fragment
 
665
 *                      of remote endpoint from the ICE session.
 
666
 * @param rem_pwd       Optional pointer to receive ICE password of remote
 
667
 *                      endpoint from the ICE session.
 
668
 *
 
669
 * @return              PJ_SUCCESS if the strings have been retrieved
 
670
 *                      successfully.
 
671
 */
 
672
PJ_DECL(pj_status_t) pj_ice_strans_get_ufrag_pwd(pj_ice_strans *ice_st,
 
673
                                                 pj_str_t *loc_ufrag,
 
674
                                                 pj_str_t *loc_pwd,
 
675
                                                 pj_str_t *rem_ufrag,
 
676
                                                 pj_str_t *rem_pwd);
 
677
 
 
678
 
 
679
/**
 
680
 * Get the number of local candidates for the specified component ID.
 
681
 *
 
682
 * @param ice_st        The ICE stream transport.
 
683
 * @param comp_id       Component ID.
 
684
 *
 
685
 * @return              The number of candidates.
 
686
 */
 
687
PJ_DECL(unsigned) pj_ice_strans_get_cands_count(pj_ice_strans *ice_st,
 
688
                                                unsigned comp_id);
 
689
 
 
690
/**
 
691
 * Enumerate the local candidates for the specified component.
 
692
 *
 
693
 * @param ice_st        The ICE stream transport.
 
694
 * @param comp_id       Component ID.
 
695
 * @param count         On input, it specifies the maximum number of
 
696
 *                      elements. On output, it will be filled with
 
697
 *                      the number of candidates copied to the
 
698
 *                      array.
 
699
 * @param cand          Array of candidates.
 
700
 *
 
701
 * @return              PJ_SUCCESS, or the appropriate error code.
 
702
 */
 
703
PJ_DECL(pj_status_t) pj_ice_strans_enum_cands(pj_ice_strans *ice_st,
 
704
                                              unsigned comp_id,
 
705
                                              unsigned *count,
 
706
                                              pj_ice_sess_cand cand[]);
 
707
 
 
708
/**
 
709
 * Get the default candidate for the specified component. When this
 
710
 * function is called before ICE negotiation completes, the default
 
711
 * candidate is selected according to local preference criteria. When
 
712
 * this function is called after ICE negotiation completes, the
 
713
 * default candidate is the candidate that forms the valid pair.
 
714
 *
 
715
 * @param ice_st        The ICE stream transport.
 
716
 * @param comp_id       Component ID.
 
717
 * @param cand          Pointer to receive the default candidate
 
718
 *                      information.
 
719
 */
 
720
PJ_DECL(pj_status_t) pj_ice_strans_get_def_cand(pj_ice_strans *ice_st,
 
721
                                                unsigned comp_id,
 
722
                                                pj_ice_sess_cand *cand);
 
723
 
 
724
/**
 
725
 * Get the current ICE role. ICE session must have been initialized
 
726
 * before this function can be called.
 
727
 *
 
728
 * @param ice_st        The ICE stream transport.
 
729
 *
 
730
 * @return              Current ICE role.
 
731
 */
 
732
PJ_DECL(pj_ice_sess_role) pj_ice_strans_get_role(pj_ice_strans *ice_st);
 
733
 
 
734
 
 
735
/**
 
736
 * Change session role. This happens for example when ICE session was
 
737
 * created with controlled role when receiving an offer, but it turns out
 
738
 * that the offer contains "a=ice-lite" attribute when the SDP gets
 
739
 * inspected. ICE session must have been initialized before this function
 
740
 * can be called.
 
741
 *
 
742
 * @param ice_st        The ICE stream transport.
 
743
 * @param new_role      The new role to be set.
 
744
 *
 
745
 * @return              PJ_SUCCESS on success, or the appropriate error.
 
746
 */
 
747
PJ_DECL(pj_status_t) pj_ice_strans_change_role(pj_ice_strans *ice_st,
 
748
                                               pj_ice_sess_role new_role);
 
749
 
 
750
 
 
751
/**
 
752
 * Start ICE connectivity checks. This function can only be called
 
753
 * after the ICE session has been created in the ICE stream transport
 
754
 * with #pj_ice_strans_init_ice().
 
755
 *
 
756
 * This function must be called once application has received remote
 
757
 * candidate list (typically from the remote SDP). This function pairs
 
758
 * local candidates with remote candidates, and starts ICE connectivity
 
759
 * checks. The ICE session/transport will then notify the application 
 
760
 * via the callback when ICE connectivity checks completes, either 
 
761
 * successfully or with failure.
 
762
 *
 
763
 * @param ice_st        The ICE stream transport.
 
764
 * @param rem_ufrag     Remote ufrag, as seen in the SDP received from 
 
765
 *                      the remote agent.
 
766
 * @param rem_passwd    Remote password, as seen in the SDP received from
 
767
 *                      the remote agent.
 
768
 * @param rcand_cnt     Number of remote candidates in the array.
 
769
 * @param rcand         Remote candidates array.
 
770
 *
 
771
 * @return              PJ_SUCCESS, or the appropriate error code.
 
772
 */
 
773
PJ_DECL(pj_status_t) pj_ice_strans_start_ice(pj_ice_strans *ice_st,
 
774
                                             const pj_str_t *rem_ufrag,
 
775
                                             const pj_str_t *rem_passwd,
 
776
                                             unsigned rcand_cnt,
 
777
                                             const pj_ice_sess_cand rcand[]);
 
778
 
 
779
/**
 
780
 * Retrieve the candidate pair that has been nominated and successfully
 
781
 * checked for the specified component. If ICE negotiation is still in
 
782
 * progress or it has failed, this function will return NULL.
 
783
 *
 
784
 * @param ice_st        The ICE stream transport.
 
785
 * @param comp_id       Component ID.
 
786
 *
 
787
 * @return              The valid pair as ICE checklist structure if the
 
788
 *                      pair exist.
 
789
 */
 
790
PJ_DECL(const pj_ice_sess_check*) 
 
791
pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st,
 
792
                             unsigned comp_id);
 
793
 
 
794
/**
 
795
 * Stop and destroy the ICE session inside this media transport. Application
 
796
 * needs to call this function once the media session is over (the call has
 
797
 * been disconnected).
 
798
 *
 
799
 * Application MAY reuse this ICE stream transport for subsequent calls.
 
800
 * In this case, it must call #pj_ice_strans_stop_ice() when the call is
 
801
 * disconnected, and reinitialize the ICE stream transport for subsequent
 
802
 * call with #pj_ice_strans_init_ice()/#pj_ice_strans_start_ice(). In this
 
803
 * case, the ICE stream transport will maintain the internal sockets and
 
804
 * continue to send STUN keep-alive packets and TURN Refresh request to 
 
805
 * keep the NAT binding/TURN allocation open and to detect change in STUN
 
806
 * mapped address.
 
807
 *
 
808
 * If application does not want to reuse the ICE stream transport for
 
809
 * subsequent calls, it must call #pj_ice_strans_destroy() to destroy the
 
810
 * ICE stream transport altogether.
 
811
 *
 
812
 * @param ice_st        The ICE stream transport.
 
813
 *
 
814
 * @return              PJ_SUCCESS, or the appropriate error code.
 
815
 */
 
816
PJ_DECL(pj_status_t) pj_ice_strans_stop_ice(pj_ice_strans *ice_st);
 
817
 
 
818
 
 
819
/**
 
820
 * Send outgoing packet using this transport. 
 
821
 * Application can send data (normally RTP or RTCP packets) at any time
 
822
 * by calling this function. This function takes a destination
 
823
 * address as one of the arguments, and this destination address should
 
824
 * be taken from the default transport address of the component (that is
 
825
 * the address in SDP c= and m= lines, or in a=rtcp attribute). 
 
826
 * If ICE negotiation is in progress, this function will send the data 
 
827
 * to the destination address. Otherwise if ICE negotiation has completed
 
828
 * successfully, this function will send the data to the nominated remote 
 
829
 * address, as negotiated by ICE.
 
830
 *
 
831
 * @param ice_st        The ICE stream transport.
 
832
 * @param comp_id       Component ID.
 
833
 * @param data          The data or packet to be sent.
 
834
 * @param data_len      Size of data or packet, in bytes.
 
835
 * @param dst_addr      The destination address.
 
836
 * @param dst_addr_len  Length of destination address.
 
837
 *
 
838
 * @return              PJ_SUCCESS if data is sent successfully.
 
839
 */
 
840
PJ_DECL(pj_status_t) pj_ice_strans_sendto(pj_ice_strans *ice_st,
 
841
                                          unsigned comp_id,
 
842
                                          const void *data,
 
843
                                          pj_size_t data_len,
 
844
                                          const pj_sockaddr_t *dst_addr,
 
845
                                          int dst_addr_len);
 
846
 
 
847
 
 
848
/**
 
849
 * @}
 
850
 */
 
851
 
 
852
 
 
853
PJ_END_DECL
 
854
 
 
855
 
 
856
 
 
857
#endif  /* __PJNATH_ICE_STRANS_H__ */
 
858