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 
59 #define NR_ICE_MEDIA_STREAM_UNPAIRED           1
60 #define NR_ICE_MEDIA_STREAM_CHECKS_FROZEN      2
61 #define NR_ICE_MEDIA_STREAM_CHECKS_ACTIVE      3
62 #define NR_ICE_MEDIA_STREAM_CHECKS_CONNECTED   4
63 #define NR_ICE_MEDIA_STREAM_CHECKS_FAILED      5
64 
65   int disconnected;
66 
67 #define NR_ICE_MEDIA_STREAM_CONNECTED    0
68 #define NR_ICE_MEDIA_STREAM_DISCONNECTED 1
69 
70   nr_ice_cand_pair_head check_list;
71   nr_ice_cand_pair_head trigger_check_queue;
72   void *timer;  /* Check list periodic timer */
73 
74 /*  nr_ice_cand_pair_head valid_list; */
75 
76   STAILQ_ENTRY(nr_ice_media_stream_) entry;
77 };
78 
79 typedef STAILQ_HEAD(nr_ice_media_stream_head_,nr_ice_media_stream_) nr_ice_media_stream_head;
80 
81 int nr_ice_media_stream_create(struct nr_ice_ctx_ *ctx,char *label, int components, nr_ice_media_stream **streamp);
82 int nr_ice_media_stream_destroy(nr_ice_media_stream **streamp);
83 int nr_ice_media_stream_finalize(nr_ice_media_stream *lstr,nr_ice_media_stream *rstr);
84 int nr_ice_media_stream_initialize(struct nr_ice_ctx_ *ctx, nr_ice_media_stream *stream);
85 int nr_ice_media_stream_get_attributes(nr_ice_media_stream *stream, char ***attrsp,int *attrctp);
86 int nr_ice_media_stream_get_default_candidate(nr_ice_media_stream *stream, int component, nr_ice_candidate **candp);
87 int nr_ice_media_stream_pair_candidates(nr_ice_peer_ctx *pctx,nr_ice_media_stream *lstream,nr_ice_media_stream *pstream);
88 int nr_ice_media_stream_start_checks(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
89 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);
90 int nr_ice_media_stream_unfreeze_pairs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
91 int nr_ice_media_stream_unfreeze_pairs_foundation(nr_ice_media_stream *stream, char *foundation);
92 int nr_ice_media_stream_dump_state(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream,FILE *out);
93 int nr_ice_media_stream_component_nominated(nr_ice_media_stream *stream,nr_ice_component *component);
94 int nr_ice_media_stream_component_failed(nr_ice_media_stream *stream,nr_ice_component *component);
95 void nr_ice_media_stream_refresh_consent_all(nr_ice_media_stream *stream);
96 void nr_ice_media_stream_disconnect_all_components(nr_ice_media_stream *stream);
97 void nr_ice_media_stream_set_disconnected(nr_ice_media_stream *stream, int disconnected);
98 int nr_ice_media_stream_check_if_connected(nr_ice_media_stream *stream);
99 int nr_ice_media_stream_set_state(nr_ice_media_stream *str, int state);
100 int nr_ice_media_stream_get_best_candidate(nr_ice_media_stream *str, int component, nr_ice_candidate **candp);
101 int nr_ice_media_stream_send(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, UCHAR *data, int len);
102 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);
103 int nr_ice_media_stream_find_component(nr_ice_media_stream *str, int comp_id, nr_ice_component **compp);
104 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);
105 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);
106 int
107 nr_ice_peer_ctx_parse_media_stream_attribute(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char *attr);
108 int nr_ice_media_stream_get_consent_status(nr_ice_media_stream *stream, int component_id, int *can_send, struct timeval *ts);
109 int nr_ice_media_stream_disable_component(nr_ice_media_stream *stream, int component_id);
110 int nr_ice_media_stream_pair_new_trickle_candidate(nr_ice_peer_ctx *pctx, nr_ice_media_stream *pstream, nr_ice_candidate *cand);
111 void nr_ice_media_stream_role_change(nr_ice_media_stream *stream);
112 
113 #ifdef __cplusplus
114 }
115 #endif /* __cplusplus */
116 #endif
117 
118