summaryrefslogtreecommitdiff
path: root/pjnath/include/pjnath/ice_stream_transport.h
blob: 5920732460cf03f46e3021c77075b82e4f500370 (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
/* $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, unsigned cand_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;


typedef struct pj_ice_st_comp
{
    unsigned		 comp_id;
} pj_ice_st_comp;


typedef struct pj_ice_st_interface
{
    pj_ice_st		*ice_st;
    pj_ice_cand_type	 type;
    pj_status_t		 status;
    unsigned		 comp_id;
    int			 cand_id;
    pj_str_t		 foundation;
    pj_uint16_t		 local_pref;
    pj_sock_t		 sock;
    pj_sockaddr		 addr;
    pj_sockaddr		 base_addr;
    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_stun_session	*stun_sess;
} pj_ice_st_interface;


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;
    unsigned		     comps[PJ_ICE_MAX_COMP];

    unsigned		     itf_cnt;
    pj_ice_st_interface	    *itfs[PJ_ICE_MAX_CAND];

    pj_dns_resolver	    *resolver;
    pj_bool_t		     relay_enabled;
    pj_str_t		     stun_domain;
    pj_sockaddr_in	     stun_srv;
};


PJ_DECL(pj_status_t) pj_ice_st_create(pj_stun_config *stun_cfg,
				      const char *name,
				      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(pj_ice_st *ice_st,
					pj_dns_resolver *resolver,
					pj_bool_t enable_relay,
					const pj_str_t *domain);
PJ_DECL(pj_status_t) pj_ice_st_set_stun_addr(pj_ice_st *ice_st,
					     pj_bool_t enable_relay,
					     const pj_sockaddr_in *srv_addr);

PJ_DECL(pj_status_t) pj_ice_st_add_comp(pj_ice_st *ice_st,
					unsigned comp_id);

PJ_DECL(pj_status_t) pj_ice_st_add_host_interface(pj_ice_st *ice_st,
						  unsigned comp_id,
						  pj_uint16_t local_pref,
					          const pj_sockaddr_in *addr,
				    		  unsigned *p_itf_id);
PJ_DECL(pj_status_t) pj_ice_st_add_all_host_interfaces(pj_ice_st *ice_st,
						       unsigned comp_id,
						       unsigned port);
PJ_DECL(pj_status_t) pj_ice_st_add_stun_interface(pj_ice_st *ice_st,
						  unsigned comp_id,
						  unsigned local_port,
						  unsigned *p_itf_id);
PJ_DECL(pj_status_t) pj_ice_st_add_relay_interface(pj_ice_st *ice_st,
						   unsigned comp_id,
						   unsigned local_port,
						   pj_bool_t notify,
						   void *notify_data);
PJ_DECL(pj_status_t) pj_ice_st_get_interfaces_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_send_data(pj_ice_st *ice_st,
					 unsigned comp_id,
					 const void *data,
					 pj_size_t data_len);
PJ_DECL(pj_status_t) pj_ice_st_sendto(pj_ice_st *ice_st,
				      unsigned comp_id,
				      unsigned itf_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__ */