Fork me on GitHub
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ice.h
Go to the documentation of this file.
1 
17 #ifndef _JANUS_ICE_H
18 #define _JANUS_ICE_H
19 
20 #include <glib.h>
21 #include <agent.h>
22 
23 #include "dtls.h"
24 #include "sctp.h"
25 #include "utils.h"
26 #include "plugins/plugin.h"
27 
28 
35 void janus_ice_init(gboolean ice_lite, gboolean ice_tcp, gboolean ipv6, uint16_t rtp_min_port, uint16_t rtp_max_port);
37 void janus_ice_deinit(void);
42 int janus_ice_set_stun_server(gchar *stun_server, uint16_t stun_port);
50 int janus_ice_set_turn_server(gchar *turn_server, uint16_t turn_port, gchar *turn_type, gchar *turn_user, gchar *turn_pwd);
57 int janus_ice_set_turn_rest_api(gchar *api_server, gchar *api_key);
60 char *janus_ice_get_stun_server(void);
63 uint16_t janus_ice_get_stun_port(void);
66 char *janus_ice_get_turn_server(void);
69 uint16_t janus_ice_get_turn_port(void);
72 char *janus_ice_get_turn_rest_api(void);
78 void janus_ice_ignore_interface(const char *ip);
82 gboolean janus_ice_is_ignored(const char *ip);
85 gboolean janus_ice_is_ice_lite_enabled(void);
88 gboolean janus_ice_is_ice_tcp_enabled(void);
91 gboolean janus_ice_is_ipv6_enabled(void);
94 gboolean janus_ice_is_bundle_forced(void);
97 void janus_ice_force_bundle(gboolean forced);
100 gboolean janus_ice_is_rtcpmux_forced(void);
103 void janus_ice_force_rtcpmux(gboolean forced);
106 void janus_set_max_nack_queue(uint mnq);
109 uint janus_get_max_nack_queue(void);
114 void janus_ice_debugging_enable(void);
116 void janus_ice_debugging_disable(void);
117 
118 
122 const gchar *janus_get_ice_state_name(gint state);
123 
124 
133 
134 
135 #define JANUS_ICE_HANDLE_WEBRTC_PROCESSING_OFFER (1 << 0)
136 #define JANUS_ICE_HANDLE_WEBRTC_START (1 << 1)
137 #define JANUS_ICE_HANDLE_WEBRTC_READY (1 << 2)
138 #define JANUS_ICE_HANDLE_WEBRTC_STOP (1 << 3)
139 #define JANUS_ICE_HANDLE_WEBRTC_ALERT (1 << 4)
140 #define JANUS_ICE_HANDLE_WEBRTC_BUNDLE (1 << 5)
141 #define JANUS_ICE_HANDLE_WEBRTC_RTCPMUX (1 << 6)
142 #define JANUS_ICE_HANDLE_WEBRTC_TRICKLE (1 << 7)
143 #define JANUS_ICE_HANDLE_WEBRTC_ALL_TRICKLES (1 << 8)
144 #define JANUS_ICE_HANDLE_WEBRTC_TRICKLE_SYNCED (1 << 9)
145 #define JANUS_ICE_HANDLE_WEBRTC_DATA_CHANNELS (1 << 10)
146 #define JANUS_ICE_HANDLE_WEBRTC_PLAN_B (1 << 11)
147 #define JANUS_ICE_HANDLE_WEBRTC_CLEANING (1 << 12)
148 #define JANUS_ICE_HANDLE_WEBRTC_HAS_AUDIO (1 << 13)
149 #define JANUS_ICE_HANDLE_WEBRTC_HAS_VIDEO (1 << 14)
150 
151 
154 typedef struct janus_ice_stats {
156  guint64 audio_bytes;
162  guint32 audio_nacks;
164  guint64 video_bytes;
170  guint32 video_nacks;
172  guint64 data_bytes;
174 
177 typedef struct janus_ice_stats_item {
179  guint64 bytes;
181  gint64 when;
183 
187 
191 void janus_ice_notify_hangup(janus_ice_handle *handle, const char *reason);
192 
193 
197 gboolean janus_plugin_session_is_alive(janus_plugin_session *plugin_session);
198 
199 
201 typedef struct janus_seq_info {
202  gint64 ts;
203  guint16 seq;
204  guint16 state;
207 } seq_info_t;
208 enum {
213 };
214 
215 
219  void *session;
221  guint64 handle_id;
223  void *app;
229  gint cdone;
231  GMainContext *icectx;
233  GMainLoop *iceloop;
235  GThread *icethread;
237  NiceAgent *agent;
239  guint audio_id;
241  guint video_id;
243  guint data_id;
245  gchar *audio_mid;
247  gchar *video_mid;
249  gchar *data_mid;
253  GHashTable *streams;
265  gchar *local_sdp;
267  gchar *remote_sdp;
269  GAsyncQueue *queued_packets;
271  GThread *send_thread;
274 };
275 
281  guint stream_id;
283  gint cdone:1;
285  guint disabled;
287  guint32 audio_ssrc;
289  guint32 video_ssrc;
299  gchar *ruser;
301  gchar *rpass;
303  GHashTable *components;
309  gint noerrorlog:1;
312 };
313 
314 #define LAST_SEQS_MAX_LEN 160
315 
320  guint stream_id;
324  guint state;
326  GSList *candidates;
334  gboolean process_started;
336  GSource *source;
364  gint noerrorlog:1;
367 };
368 
369 #define JANUS_ICE_PACKET_AUDIO 0
370 #define JANUS_ICE_PACKET_VIDEO 1
371 #define JANUS_ICE_PACKET_DATA 2
372 
375  char *data;
377  gint length;
379  gint type;
381  gboolean control;
383  gboolean encrypted;
384 };
385 
388 
389 
392 janus_ice_handle *janus_ice_handle_create(void *gateway_session);
397 janus_ice_handle *janus_ice_handle_find(void *gateway_session, guint64 handle_id);
404 gint janus_ice_handle_attach_plugin(void *gateway_session, guint64 handle_id, janus_plugin *plugin);
409 gint janus_ice_handle_destroy(void *gateway_session, guint64 handle_id);
412 void janus_ice_free(janus_ice_handle *handle);
422 void janus_ice_stream_free(GHashTable *container, janus_ice_stream *stream);
426 void janus_ice_component_free(GHashTable *container, janus_ice_component *component);
428 
429 
432 
433 
437 void janus_ice_cb_candidate_gathering_done (NiceAgent *agent, guint stream_id, gpointer ice);
444 void janus_ice_cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer ice);
452 #ifndef HAVE_LIBNICE_TCP
453 void janus_ice_cb_new_selected_pair (NiceAgent *agent, guint stream_id, guint component_id, gchar *local, gchar *remote, gpointer ice);
454 #else
455 void janus_ice_cb_new_selected_pair (NiceAgent *agent, guint stream_id, guint component_id, NiceCandidate *local, NiceCandidate *remote, gpointer ice);
456 #endif
457 
464 void janus_ice_cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer ice);
465 
471 void janus_ice_relay_rtp(janus_ice_handle *handle, int video, char *buf, int len);
477 void janus_ice_relay_rtcp(janus_ice_handle *handle, int video, char *buf, int len);
482 void janus_ice_relay_data(janus_ice_handle *handle, char *buf, int len);
487 void janus_ice_incoming_data(janus_ice_handle *handle, char *buffer, int length);
489 
490 
493 
494 
495 void *janus_ice_thread(void *data);
497 void *janus_ice_send_thread(void *data);
508 int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int video, int data, int bundle, int rtcpmux, int trickle);
514 void janus_ice_candidates_to_sdp(janus_ice_handle *handle, char *sdp, guint stream_id, guint component_id);
519 void janus_ice_setup_remote_candidates(janus_ice_handle *handle, guint stream_id, guint component_id);
526 
527 #endif