trtp_manager.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (C) 2012 Mamadou Diop
  3. * Copyright (C) 2012-2013 Doubango Telecom <http://www.doubango.org>
  4. *
  5. * This file is part of Open Source Doubango Framework.
  6. *
  7. * DOUBANGO is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * DOUBANGO is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with DOUBANGO.
  19. *
  20. */
  21. /**@file trtp_manager.h
  22. * @brief RTP/RTCP manager.
  23. */
  24. #ifndef TINYRTP_MANAGER_H
  25. #define TINYRTP_MANAGER_H
  26. #include "tinyrtp_config.h"
  27. #include "tinyrtp/rtp/trtp_rtp_session.h"
  28. #include "tinyrtp/rtcp/trtp_rtcp_session.h"
  29. #include "tinyrtp/trtp_srtp.h"
  30. #include "tinymedia/tmedia_defaults.h"
  31. #include "tinynet.h"
  32. TRTP_BEGIN_DECLS
  33. struct trtp_rtp_packet_s;
  34. struct tnet_proxyinfo_s;
  35. /** RTP/RTCP manager */
  36. typedef struct trtp_manager_s {
  37. TSK_DECLARE_OBJECT;
  38. char* local_ip;
  39. tsk_bool_t use_ipv6;
  40. tsk_bool_t is_started;
  41. tsk_bool_t use_rtcp;
  42. tsk_bool_t use_rtcpmux;
  43. tsk_bool_t is_socket_disabled;
  44. tsk_bool_t is_ice_neg_ok;
  45. tsk_bool_t is_ice_turn_active;
  46. tsk_bool_t is_force_symetric_rtp;
  47. tsk_bool_t is_symetric_rtp_checked;
  48. tsk_bool_t is_symetric_rtcp_checked;
  49. int32_t app_bw_max_upload; // application specific (kbps)
  50. int32_t app_bw_max_download; // application specific (kbps)
  51. float app_jitter_cng; // application specific jitter buffer congestion estimation (quality in ]0, 1], 1f meaning no congestion)
  52. tnet_transport_t* transport;
  53. struct tnet_ice_ctx_s* ice_ctx;
  54. tsk_timer_manager_handle_t* timer_mgr_global;
  55. struct {
  56. tmedia_rtcweb_type_t local;
  57. tmedia_rtcweb_type_t remote;
  58. } rtcweb_type;
  59. struct {
  60. tsk_bool_t auto_detect;
  61. struct tnet_proxyinfo_s* info;
  62. }
  63. proxy;
  64. struct {
  65. uint16_t start;
  66. uint16_t stop;
  67. } port_range;
  68. struct {
  69. uint16_t seq_num;
  70. uint32_t timestamp;
  71. uint8_t payload_type;
  72. int32_t dscp;
  73. char* remote_ip;
  74. tnet_port_t remote_port;
  75. struct sockaddr_storage remote_addr;
  76. struct {
  77. char* ip;
  78. tnet_port_t port;
  79. tnet_socket_type_t type;
  80. } public_addr;
  81. struct {
  82. uint32_t local;
  83. uint32_t remote;
  84. } ssrc;
  85. struct {
  86. const void* usrdata;
  87. trtp_rtp_cb_f fun;
  88. } cb;
  89. struct {
  90. void* ptr;
  91. tsk_size_t size;
  92. tsk_size_t index;
  93. } serial_buffer;
  94. } rtp;
  95. struct {
  96. char* cname;
  97. char* remote_ip;
  98. tnet_port_t remote_port;
  99. struct sockaddr_storage remote_addr;
  100. tnet_socket_t* local_socket;
  101. struct {
  102. char* ip;
  103. tnet_port_t port;
  104. tnet_socket_type_t type;
  105. } public_addr;
  106. struct {
  107. const void* usrdata;
  108. trtp_rtcp_cb_f fun;
  109. } cb;
  110. struct trtp_rtcp_session_s* session;
  111. } rtcp;
  112. TSK_DECLARE_SAFEOBJ;
  113. #if HAVE_SRTP
  114. enum tmedia_srtp_type_e srtp_type;
  115. enum tmedia_srtp_mode_e srtp_mode;
  116. trtp_srtp_state_t srtp_state;
  117. trtp_srtp_ctx_xt srtp_contexts[2/*LINE_IDX*/][2/*CRYPTO_TYPE*/];
  118. const struct trtp_srtp_ctx_xs* srtp_ctx_neg_local;
  119. const struct trtp_srtp_ctx_xs* srtp_ctx_neg_remote;
  120. struct {
  121. char* file_ca;
  122. char* file_pbk;
  123. char* file_pvk;
  124. tsk_bool_t cert_verif;
  125. trtp_srtp_state_t state;
  126. // enable() could be postponed if net transport not ready yet (e.g. when ICE is ON)
  127. tsk_bool_t enable_postponed;
  128. tsk_bool_t srtp_connected;
  129. tsk_bool_t srtcp_connected;
  130. tsk_bool_t srtp_handshake_succeed;
  131. tsk_bool_t srtcp_handshake_succeed;
  132. trtp_srtp_crypto_type_t crypto_selected;
  133. struct {
  134. uint64_t timeout;
  135. tsk_timer_id_t id;
  136. } timer_hanshaking;
  137. struct {
  138. const void* usrdata;
  139. trtp_srtp_dtls_cb_f fun;
  140. } cb;
  141. struct {
  142. tnet_fingerprint_t fp;
  143. tnet_dtls_hash_type_t fp_hash;
  144. } remote;
  145. struct {
  146. tnet_dtls_setup_t setup;
  147. tsk_bool_t connection_new;
  148. } local;
  149. } dtls;
  150. #endif
  151. }
  152. trtp_manager_t;
  153. TINYRTP_API trtp_manager_t* trtp_manager_create(tsk_bool_t use_rtcp, const char* local_ip, tsk_bool_t use_ipv6, enum tmedia_srtp_type_e srtp_type, enum tmedia_srtp_mode_e srtp_mode);
  154. TINYRTP_API trtp_manager_t* trtp_manager_create_2(struct tnet_ice_ctx_s* ice_ctx, enum tmedia_srtp_type_e srtp_type, enum tmedia_srtp_mode_e srtp_mode);
  155. TINYRTP_API int trtp_manager_set_ice_ctx(trtp_manager_t* self, struct tnet_ice_ctx_s* ice_ctx);
  156. TINYRTP_API int trtp_manager_prepare(trtp_manager_t* self);
  157. #if HAVE_SRTP
  158. TINYRTP_API int trtp_manager_set_dtls_certs(trtp_manager_t* self, const char* ca, const char* pbk, const char* pvk, tsk_bool_t verify);
  159. TINYRTP_API int trtp_manager_set_dtls_remote_fingerprint(trtp_manager_t* self, const tnet_fingerprint_t* fp, const char* hash);
  160. TINYRTP_API enum tnet_dtls_hash_type_e trtp_manager_get_dtls_remote_fingerprint_hash(trtp_manager_t* self);
  161. TINYRTP_API int trtp_manager_set_dtls_local_setup(trtp_manager_t* self, tnet_dtls_setup_t setup, tsk_bool_t connection_new);
  162. TINYRTP_API int trtp_manager_set_dtls_callback(trtp_manager_t* self, const void* usrdata, trtp_srtp_dtls_cb_f fun);
  163. TINYRTP_API const char* trtp_manager_get_dtls_local_fingerprint(trtp_manager_t* self, enum tnet_dtls_hash_type_e hash);
  164. TINYRTP_API tsk_bool_t trtp_manager_is_dtls_enabled(trtp_manager_t* self);
  165. TINYRTP_API tsk_bool_t trtp_manager_is_dtls_activated(trtp_manager_t* self);
  166. TINYRTP_API tsk_bool_t trtp_manager_is_dtls_started(trtp_manager_t* self);
  167. TINYRTP_API tsk_bool_t trtp_manager_is_srtp_activated(trtp_manager_t* self);
  168. TINYRTP_API tsk_bool_t trtp_manager_is_srtp_started(trtp_manager_t* self);
  169. TINYRTP_API int trtp_manager_set_srtp_type_remote(trtp_manager_t* self, enum tmedia_srtp_type_e srtp_type);
  170. TINYRTP_API int trtp_manager_set_srtp_type_local(trtp_manager_t* self, enum tmedia_srtp_type_e srtp_type, enum tmedia_srtp_mode_e srtp_mode);
  171. #endif /* HAVE_SRTP */
  172. TINYRTP_API tsk_bool_t trtp_manager_is_ready(trtp_manager_t* self);
  173. TINYRTP_API int trtp_manager_set_natt_ctx(trtp_manager_t* self, struct tnet_nat_ctx_s* natt_ctx);
  174. TINYRTP_API int trtp_manager_set_rtp_callback(trtp_manager_t* self, trtp_rtp_cb_f fun, const void* usrdata);
  175. TINYRTP_API int trtp_manager_set_rtcp_callback(trtp_manager_t* self, trtp_rtcp_cb_f fun, const void* usrdata);
  176. TINYRTP_API int trtp_manager_set_rtp_dscp(trtp_manager_t* self, int32_t dscp);
  177. TINYRTP_API int trtp_manager_set_payload_type(trtp_manager_t* self, uint8_t payload_type);
  178. TINYRTP_API int trtp_manager_set_rtp_remote(trtp_manager_t* self, const char* remote_ip, tnet_port_t remote_port);
  179. TINYRTP_API int trtp_manager_set_rtcp_remote(trtp_manager_t* self, const char* remote_ip, tnet_port_t remote_port);
  180. TINYRTP_API int trtp_manager_set_port_range(trtp_manager_t* self, uint16_t start, uint16_t stop);
  181. TINYRTP_API int trtp_manager_set_rtcweb_type_remote(trtp_manager_t* self, tmedia_rtcweb_type_t rtcweb_type);
  182. TINYRTP_API int trtp_manager_set_proxy_auto_detect(trtp_manager_t* self, tsk_bool_t auto_detect);
  183. TINYRTP_API int trtp_manager_set_proxy_info(trtp_manager_t* self, enum tnet_proxy_type_e type, const char* host, tnet_port_t port, const char* login, const char* password);
  184. TINYRTP_API int trtp_manager_start(trtp_manager_t* self);
  185. TINYRTP_API tsk_size_t trtp_manager_send_rtp(trtp_manager_t* self, const void* data, tsk_size_t size, uint32_t duration, tsk_bool_t marker, tsk_bool_t last_packet);
  186. TINYRTP_API tsk_size_t trtp_manager_send_rtp_packet(trtp_manager_t* self, const struct trtp_rtp_packet_s* packet, tsk_bool_t bypass_encrypt);
  187. TINYRTP_API int trtp_manager_get_bytes_count(trtp_manager_t* self, uint64_t* bytes_in, uint64_t* bytes_out);
  188. TINYRTP_API tsk_size_t trtp_manager_send_rtp_raw(trtp_manager_t* self, const void* data, tsk_size_t size);
  189. TINYRTP_API int trtp_manager_set_app_bw_and_jcng(trtp_manager_t* self, int32_t bw_upload_kbps, int32_t bw_download_kbps, float jcng_q);
  190. TINYRTP_API int trtp_manager_signal_pkt_loss(trtp_manager_t* self, uint32_t ssrc_media, const uint16_t* seq_nums, tsk_size_t count);
  191. TINYRTP_API int trtp_manager_signal_frame_corrupted(trtp_manager_t* self, uint32_t ssrc_media);
  192. TINYRTP_API int trtp_manager_signal_jb_error(trtp_manager_t* self, uint32_t ssrc_media);
  193. TINYRTP_API int trtp_manager_stop(trtp_manager_t* self);
  194. TINYRTP_GEXTERN const tsk_object_def_t *trtp_manager_def_t;
  195. TRTP_END_DECLS
  196. #endif /* TINYRTP_MANAGER_H */