1 /*
2 Copyright (c) 2007, Adobe Systems, Incorporated
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9 * Redistributions of source code must retain the above copyright
10   notice, this list of conditions and the following disclaimer.
11 
12 * Redistributions in binary form must reproduce the above copyright
13   notice, this list of conditions and the following disclaimer in the
14   documentation and/or other materials provided with the distribution.
15 
16 * Neither the name of Adobe Systems, Network Resonance nor the names of its
17   contributors may be used to endorse or promote products derived from
18   this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
33 
34 
35 #ifndef _ice_media_stream_h
36 #define _ice_media_stream_h
37 #ifdef __cplusplus
38 using namespace std;
39 extern "C" {
40 #endif /* __cplusplus */
41 
42 #include "transport_addr.h"
43 
44 typedef struct nr_ice_stun_server_ {
45   nr_transport_addr addr;
46   int id;
47 } nr_ice_stun_server;
48 
49 typedef struct nr_ice_turn_server_ {
50     nr_ice_stun_server    turn_server;
51     char                 *username;
52     Data                 *password;
53 } nr_ice_turn_server;
54 
55 struct nr_ice_media_stream_ {
56   char *label;
57   struct nr_ice_ctx_ *ctx;
58   struct nr_ice_peer_ctx_ *pctx;
59 
60   struct nr_ice_media_stream_ *local_stream; /* used when this is a peer */
61   int component_ct;
62   nr_ice_component_head components;
63 
64   char *ufrag;    /* ICE username */
65   char *pwd;    /* ICE password */
66   char *r2l_user;  /* The username for incoming requests */
67   char *l2r_user;  /* The username for outgoing requests */
68   Data r2l_pass;   /* The password for incoming requests */
69   Data l2r_pass;   /* The password for outcoming requests */
70   int ice_state;
71   /* The stream is being replaced by another, so it will not continue any ICE
72    * processing. If this stream is connected already, traffic can continue to
73    * flow for a limited time while the new stream gets ready. */
74   int obsolete;
75 
76 #define NR_ICE_MEDIA_STREAM_UNPAIRED           1
77 #define NR_ICE_MEDIA_STREAM_CHECKS_FROZEN      2
78 #define NR_ICE_MEDIA_STREAM_CHECKS_ACTIVE      3
79 #define NR_ICE_MEDIA_STREAM_CHECKS_CONNECTED   4
80 #define NR_ICE_MEDIA_STREAM_CHECKS_FAILED      5
81 
82   int disconnected;
83 
84 #define NR_ICE_MEDIA_STREAM_CONNECTED    0
85 #define NR_ICE_MEDIA_STREAM_DISCONNECTED 1
86 
87   /* Copy of flags field from nr_ice_ctx */
88   int flags;
89 
90   /* Copy of STUN/TURN servers from nr_ice_ctx */
91   nr_ice_stun_server *stun_servers;           /* The list of stun servers */
92   int stun_server_ct;
93   nr_ice_turn_server *turn_servers;           /* The list of turn servers */
94   int turn_server_ct;
95 
96   nr_ice_cand_pair_head check_list;
97   nr_ice_cand_pair_head trigger_check_queue;
98   void *timer;  /* Check list periodic timer */
99 
100 /*  nr_ice_cand_pair_head valid_list; */
101 
102   STAILQ_ENTRY(nr_ice_media_stream_) entry;
103 };
104 
105 typedef STAILQ_HEAD(nr_ice_media_stream_head_,nr_ice_media_stream_) nr_ice_media_stream_head;
106 
107 int nr_ice_media_stream_create(struct nr_ice_ctx_ *ctx,const char *label,const char *ufrag,const char *pwd,int components, nr_ice_media_stream **streamp);
108 int nr_ice_media_stream_destroy(nr_ice_media_stream **streamp);
109 int nr_ice_media_stream_finalize(nr_ice_media_stream *lstr,nr_ice_media_stream *rstr);
110 int nr_ice_media_stream_initialize(struct nr_ice_ctx_ *ctx, nr_ice_media_stream *stream);
111 int nr_ice_media_stream_get_attributes(nr_ice_media_stream *stream, char ***attrsp,int *attrctp);
112 int nr_ice_media_stream_get_default_candidate(nr_ice_media_stream *stream, int component, nr_ice_candidate **candp);
113 int nr_ice_media_stream_pair_candidates(nr_ice_peer_ctx *pctx,nr_ice_media_stream *lstream,nr_ice_media_stream *pstream);
114 int nr_ice_media_stream_start_checks(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
115 int nr_ice_media_stream_service_pre_answer_requests(nr_ice_peer_ctx *pctx,nr_ice_media_stream *lstream,nr_ice_media_stream *pstream, int *serviced);
116 int nr_ice_media_stream_unfreeze_pairs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
117 int nr_ice_media_stream_unfreeze_pairs_foundation(nr_ice_media_stream *stream, char *foundation);
118 void nr_ice_media_stream_dump_state(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, int log_level);
119 void nr_ice_media_stream_component_nominated(nr_ice_media_stream *stream,nr_ice_component *component);
120 void nr_ice_media_stream_component_failed(nr_ice_media_stream *stream,nr_ice_component *component);
121 void nr_ice_media_stream_refresh_consent_all(nr_ice_media_stream *stream);
122 void nr_ice_media_stream_disconnect_all_components(nr_ice_media_stream *stream);
123 void nr_ice_media_stream_set_disconnected(nr_ice_media_stream *stream, int disconnected);
124 int nr_ice_media_stream_check_if_connected(nr_ice_media_stream *stream);
125 int nr_ice_media_stream_set_state(nr_ice_media_stream *str, int state);
126 void nr_ice_media_stream_stop_checking(nr_ice_media_stream *str);
127 void nr_ice_media_stream_set_obsolete(nr_ice_media_stream *str);
128 int nr_ice_media_stream_is_done_gathering(nr_ice_media_stream *str);
129 int nr_ice_media_stream_get_best_candidate(nr_ice_media_stream *str, int component, nr_ice_candidate **candp);
130 int nr_ice_media_stream_send(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, UCHAR *data, int len);
131 int nr_ice_media_stream_get_active(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_ice_candidate **local, nr_ice_candidate **remote);
132 int nr_ice_media_stream_find_component(nr_ice_media_stream *str, int comp_id, nr_ice_component **compp);
133 int nr_ice_media_stream_find_pair(nr_ice_media_stream *str, nr_ice_candidate *local, nr_ice_candidate *remote, nr_ice_cand_pair **pair);
134 int nr_ice_media_stream_addrs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_transport_addr *local, nr_transport_addr *remote);
135 int
136 nr_ice_peer_ctx_parse_media_stream_attribute(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char *attr);
137 int nr_ice_media_stream_get_consent_status(nr_ice_media_stream *stream, int component_id, int *can_send, struct timeval *ts);
138 int nr_ice_media_stream_disable_component(nr_ice_media_stream *stream, int component_id);
139 int nr_ice_media_stream_pair_new_trickle_candidate(nr_ice_peer_ctx *pctx, nr_ice_media_stream *pstream, nr_ice_candidate *cand);
140 void nr_ice_media_stream_role_change(nr_ice_media_stream *stream);
141 
142 #ifdef __cplusplus
143 }
144 #endif /* __cplusplus */
145 #endif
146 
147