summaryrefslogtreecommitdiff
path: root/pjnath/include/pjnath/ice_stream_transport.h
blob: fbdd9b43a191e49aa908679a619615707da00066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* $Id$ */
/* 
 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
#ifndef __PJNATH_ICE_STREAM_TRANSPORT_H__
#define __PJNATH_ICE_STREAM_TRANSPORT_H__


/**
 * @file ice_mt.h
 * @brief ICE Media Transport.
 */
#include <pjnath/ice.h>
#include <pjlib-util/resolver.h>
#include <pj/ioqueue.h>


PJ_BEGIN_DECL


/**
 * @defgroup PJNATH_ICE_STREAM_TRANSPORT ICE Stream Transport
 * @brief Transport for media stream using ICE
 * @ingroup PJNATH_ICE
 * @{
 */

typedef struct pj_ice_st pj_ice_st;

typedef struct pj_ice_st_cb
{
    void    (*on_rx_data)(pj_ice_st *ice_st,
			  unsigned comp_id, 
			  void *pkt, pj_size_t size,
			  const pj_sockaddr_t *src_addr,
			  unsigned src_addr_len);
    void    (*on_ice_complete)(pj_ice_st *ice_st, 
			       pj_status_t status);

} pj_ice_st_cb;


#ifndef PJ_ICE_ST_MAX_ALIASES
#   define PJ_ICE_ST_MAX_ALIASES	8
#endif

enum pj_ice_st_option
{
    PJ_ICE_ST_OPT_DISABLE_STUN	= 1,
    PJ_ICE_ST_OPT_DISABLE_RELAY	= 2,
    PJ_ICE_ST_OPT_NO_PORT_RETRY	= 4,
};


typedef struct pj_ice_st_cand
{
    pj_ice_cand_type	type;
    pj_status_t		status;
    pj_sockaddr		addr;
    int			cand_id;
    pj_uint16_t		local_pref;
    pj_str_t		foundation;
} pj_ice_st_cand;


typedef struct pj_ice_st_comp
{
    pj_ice_st		*ice_st;
    unsigned		 comp_id;
    pj_uint32_t		 options;
    pj_sock_t		 sock;

    pj_stun_session	*stun_sess;

    pj_sockaddr		 local_addr;

    unsigned		 pending_cnt;
    pj_status_t		 last_status;

    unsigned		 cand_cnt;
    pj_ice_st_cand	 cand_list[PJ_ICE_ST_MAX_ALIASES];
    int			 default_cand;

    pj_ioqueue_key_t	*key;
    pj_uint8_t		 pkt[1500];
    pj_ioqueue_op_key_t	 read_op;
    pj_ioqueue_op_key_t	 write_op;
    pj_sockaddr		 src_addr;
    int			 src_addr_len;

} pj_ice_st_comp;


struct pj_ice_st
{
    char		     obj_name[PJ_MAX_OBJ_NAME];
    pj_pool_t		    *pool;
    void		    *user_data;
    pj_stun_config	     stun_cfg;
    pj_ice_st_cb	     cb;

    pj_ice		    *ice;

    unsigned		     comp_cnt;
    pj_ice_st_comp	   **comp;

    pj_dns_resolver	    *resolver;
    pj_bool_t		     has_resolver_job;
    pj_sockaddr_in	     stun_srv;
    pj_sockaddr_in	     turn_srv;
};


PJ_DECL(pj_status_t) pj_ice_st_create(pj_stun_config *stun_cfg,
				      const char *name,
				      unsigned comp_cnt,
				      void *user_data,
				      const pj_ice_st_cb *cb,
				      pj_ice_st **p_ice_st);
PJ_DECL(pj_status_t) pj_ice_st_destroy(pj_ice_st *ice_st);

PJ_DECL(pj_status_t) pj_ice_st_set_stun_domain(pj_ice_st *ice_st,
					       pj_dns_resolver *resolver,
					       const pj_str_t *domain);
PJ_DECL(pj_status_t) pj_ice_st_set_stun_srv(pj_ice_st *ice_st,
					    const pj_sockaddr_in *stun_srv,
					    const pj_sockaddr_in *turn_srv);

PJ_DECL(pj_status_t) pj_ice_st_create_comp(pj_ice_st *ice_st,
					   unsigned comp_id,
					   pj_uint32_t options,
					   const pj_sockaddr_in *addr,
				    	   unsigned *p_itf_id);

PJ_DECL(pj_status_t) pj_ice_st_get_comps_status(pj_ice_st *ice_st);

PJ_DECL(pj_status_t) pj_ice_st_init_ice(pj_ice_st *ice_st,
					pj_ice_role role,
					const pj_str_t *local_ufrag,
					const pj_str_t *local_passwd);
PJ_DECL(pj_status_t) pj_ice_st_enum_cands(pj_ice_st *ice_st,
					  unsigned *count,
					  pj_ice_cand cand[]);
PJ_DECL(pj_status_t) pj_ice_st_start_ice(pj_ice_st *ice_st,
					 const pj_str_t *rem_ufrag,
					 const pj_str_t *rem_passwd,
					 unsigned rem_cand_cnt,
					 const pj_ice_cand rem_cand[]);
PJ_DECL(pj_status_t) pj_ice_st_stop_ice(pj_ice_st *ice_st);

PJ_DECL(pj_status_t) pj_ice_st_sendto(pj_ice_st *ice_st,
				      unsigned comp_id,
				      const void *data,
				      pj_size_t data_len,
				      const pj_sockaddr_t *dst_addr,
				      int dst_addr_len);


/**
 * @}
 */


PJ_END_DECL



#endif	/* __PJNATH_ICE_STREAM_TRANSPORT_H__ */