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 struct nr_ice_media_stream_ {
43   char *label;
44   struct nr_ice_ctx_ *ctx;
45   struct nr_ice_peer_ctx_ *pctx;
46 
47   struct nr_ice_media_stream_ *local_stream; /* used when this is a peer */
48   int component_ct;
49   nr_ice_component_head components;
50 
51   char *ufrag;    /* ICE username */
52   char *pwd;    /* ICE password */
53   char *r2l_user;  /* The username for incoming requests */
54   char *l2r_user;  /* The username for outgoing requests */
55   Data r2l_pass;   /* The password for incoming requests */
56   Data l2r_pass;   /* The password for outcoming requests */
57   int ice_state;
58   /* The stream is being replaced by another, so it will not continue any ICE
59    * processing. If this stream is connected already, traffic can continue to
60    * flow for a limited time while the new stream gets ready. */
61   int obsolete;
62 
63 #define NR_ICE_MEDIA_STREAM_UNPAIRED           1
64 #define NR_ICE_MEDIA_STREAM_CHECKS_FROZEN      2
65 #define NR_ICE_MEDIA_STREAM_CHECKS_ACTIVE      3
66 #define NR_ICE_MEDIA_STREAM_CHECKS_CONNECTED   4
67 #define NR_ICE_MEDIA_STREAM_CHECKS_FAILED      5
68 
69   int disconnected;
70 
71 #define NR_ICE_MEDIA_STREAM_CONNECTED    0
72 #define NR_ICE_MEDIA_STREAM_DISCONNECTED 1
73 
74   nr_ice_cand_pair_head check_list;
75   nr_ice_cand_pair_head trigger_check_queue;
76   void *timer;  /* Check list periodic timer */
77 
78 /*  nr_ice_cand_pair_head valid_list; */
79 
80   STAILQ_ENTRY(nr_ice_media_stream_) entry;
81 };
82 
83 typedef STAILQ_HEAD(nr_ice_media_stream_head_,nr_ice_media_stream_) nr_ice_media_stream_head;
84 
85 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);
86 int nr_ice_media_stream_destroy(nr_ice_media_stream **streamp);
87 int nr_ice_media_stream_finalize(nr_ice_media_stream *lstr,nr_ice_media_stream *rstr);
88 int nr_ice_media_stream_initialize(struct nr_ice_ctx_ *ctx, nr_ice_media_stream *stream);
89 int nr_ice_media_stream_get_attributes(nr_ice_media_stream *stream, char ***attrsp,int *attrctp);
90 int nr_ice_media_stream_get_default_candidate(nr_ice_media_stream *stream, int component, nr_ice_candidate **candp);
91 int nr_ice_media_stream_pair_candidates(nr_ice_peer_ctx *pctx,nr_ice_media_stream *lstream,nr_ice_media_stream *pstream);
92 int nr_ice_media_stream_start_checks(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
93 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);
94 int nr_ice_media_stream_unfreeze_pairs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
95 int nr_ice_media_stream_unfreeze_pairs_foundation(nr_ice_media_stream *stream, char *foundation);
96 void nr_ice_media_stream_dump_state(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, int log_level);
97 void nr_ice_media_stream_component_nominated(nr_ice_media_stream *stream,nr_ice_component *component);
98 void nr_ice_media_stream_component_failed(nr_ice_media_stream *stream,nr_ice_component *component);
99 void nr_ice_media_stream_refresh_consent_all(nr_ice_media_stream *stream);
100 void nr_ice_media_stream_disconnect_all_components(nr_ice_media_stream *stream);
101 void nr_ice_media_stream_set_disconnected(nr_ice_media_stream *stream, int disconnected);
102 int nr_ice_media_stream_check_if_connected(nr_ice_media_stream *stream);
103 int nr_ice_media_stream_set_state(nr_ice_media_stream *str, int state);
104 void nr_ice_media_stream_stop_checking(nr_ice_media_stream *str);
105 void nr_ice_media_stream_set_obsolete(nr_ice_media_stream *str);
106 int nr_ice_media_stream_is_done_gathering(nr_ice_media_stream *str);
107 int nr_ice_media_stream_get_best_candidate(nr_ice_media_stream *str, int component, nr_ice_candidate **candp);
108 int nr_ice_media_stream_send(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, UCHAR *data, int len);
109 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);
110 int nr_ice_media_stream_find_component(nr_ice_media_stream *str, int comp_id, nr_ice_component **compp);
111 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);
112 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);
113 int
114 nr_ice_peer_ctx_parse_media_stream_attribute(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char *attr);
115 int nr_ice_media_stream_get_consent_status(nr_ice_media_stream *stream, int component_id, int *can_send, struct timeval *ts);
116 int nr_ice_media_stream_disable_component(nr_ice_media_stream *stream, int component_id);
117 int nr_ice_media_stream_pair_new_trickle_candidate(nr_ice_peer_ctx *pctx, nr_ice_media_stream *pstream, nr_ice_candidate *cand);
118 void nr_ice_media_stream_role_change(nr_ice_media_stream *stream);
119 
120 #ifdef __cplusplus
121 }
122 #endif /* __cplusplus */
123 #endif
124 
125