tsip_ssession.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file tsip_ssession.h
  23. * @brief SIP ssession.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TSIP_SSESSION_H
  29. #define TSIP_SSESSION_H
  30. #include "tinysip_config.h"
  31. #include "tinymedia/tmedia_common.h"
  32. #include "tinymedia/tmedia_session.h"
  33. #include "tsk_object.h"
  34. #include "tsk_list.h"
  35. #include "tsk_params.h"
  36. #include "tsk_options.h"
  37. TSIP_BEGIN_DECLS
  38. // Forward declarations
  39. struct tsip_message_s;
  40. struct tsip_action_s;
  41. typedef uint64_t tsip_ssession_id_t;
  42. #define TSIP_SSESSION_INVALID_ID 0
  43. #define TSIP_SSESSION_INVALID_HANDLE tsk_null
  44. #if defined(DEBUG) || defined(_DEBUG)
  45. # define TSIP_SSESSION_EXPIRES_DEFAULT 3600000 /* miliseconds. */
  46. #else
  47. # define TSIP_SSESSION_EXPIRES_DEFAULT 600000000
  48. #endif
  49. #define TSIP_SSESSION(self) ((tsip_ssession_t*)(self))
  50. typedef enum tsip_ssession_param_type_e {
  51. sstype_null = 0,
  52. sstype_header,
  53. sstype_caps,
  54. sstype_userdata,
  55. sstype_to_str,
  56. sstype_from_str,
  57. sstype_to_obj,
  58. sstype_from_obj,
  59. sstype_nocontact,
  60. sstype_expires,
  61. sstype_silent_hangup,
  62. sstype_sigcomp_id,
  63. sstype_auth_ha1,
  64. sstype_auth_impi,
  65. sstype_parent_id,
  66. sstype_ws_src,
  67. sstype_media
  68. }
  69. tsip_ssession_param_type_t;
  70. #define TSIP_SSESSION_SET_PARENT_ID(PARENT_ID_SSID) sstype_parent_id, ((tsip_ssession_id_t)PARENT_ID_SSID)
  71. #define TSIP_SSESSION_SET_HEADER(NAME_STR, VALUE_STR) sstype_header, (const char*)NAME_STR, (const char*)VALUE_STR
  72. #define TSIP_SSESSION_UNSET_HEADER(NAME_STR) TSIP_SSESSION_SET_HEADER(NAME_STR, (const char*)-1)
  73. #define TSIP_SSESSION_SET_CAPS(NAME_STR, VALUE_STR) sstype_caps, (const char*)NAME_STR, (const char*)VALUE_STR /* RFC 3840 */
  74. #define TSIP_SSESSION_UNSET_CAPS(NAME_STR) TSIP_SSESSION_SET_CAPS(NAME_STR, (const char*)-1)
  75. #define TSIP_SSESSION_SET_USERDATA(DATA_PTR) sstype_userdata, (const void*)DATA_PTR
  76. #define TSIP_SSESSION_SET_TO_STR(URI_STR) sstype_to_str, (const char*)URI_STR
  77. #define TSIP_SSESSION_SET_FROM_STR(URI_STR) sstype_from_str, (const char*)URI_STR
  78. #define TSIP_SSESSION_SET_TO(URI_STR) TSIP_SSESSION_SET_TO_STR(URI_STR)
  79. #define TSIP_SSESSION_SET_FROM(URI_STR) TSIP_SSESSION_SET_FROM_STR(URI_STR)
  80. #define TSIP_SSESSION_SET_TO_OBJ(URI_OBJ) sstype_to_obj, (const tsip_uri_t*)URI_OBJ
  81. #define TSIP_SSESSION_SET_FROM_OBJ(URI_OBJ) sstype_from_obj, (const tsip_uri_t*)URI_OBJ
  82. #define TSIP_SSESSION_SET_NO_CONTACT(ENABLED_BOOL) sstype_nocontact, (tsk_bool_t)ENABLED_BOOL
  83. #define TSIP_SSESSION_SET_EXPIRES(VALUE_UINT) sstype_expires, (unsigned)VALUE_UINT
  84. #define TSIP_SSESSION_SET_SILENT_HANGUP(ENABLED_BOOL) sstype_silent_hangup, (tsk_bool_t)ENABLED_BOOL
  85. #define TSIP_SSESSION_SET_SIGCOMP_COMPARTMENT(COMPARTMENT_ID_STR) sstype_sigcomp_id, (const char*)COMPARTMENT_ID_STR
  86. #define TSIP_SSESSION_UNSET_SIGCOMP_COMPARTMENT() TSIP_SSESSION_SET_SIGCOMP_COMPARTMENT((const char*)-1)
  87. #define TSIP_SSESSION_SET_AUTH_HA1(AUTH_HA1_STR) sstype_auth_ha1, (const char*)AUTH_HA1_STR
  88. #define TSIP_SSESSION_SET_AUTH_IMPI(AUTH_IMPI_STR) sstype_auth_impi, (const char*)AUTH_IMPI_STR
  89. #define TSIP_SSESSION_SET_WEBSOCKET_SRC(SRC_HOST_STR, SRC_PORT_INT, SRC_PROTO_STR) sstype_ws_src, (const char*)SRC_HOST_STR, (int32_t)SRC_PORT_INT, (const char*)SRC_PROTO_STR
  90. #define TSIP_SSESSION_SET_MEDIA(...) sstype_media, ##__VA_ARGS__
  91. #define TSIP_SSESSION_SET_NULL() sstype_null
  92. typedef enum tsip_msession_param_type_e {
  93. mstype_null = 0,
  94. mstype_set_profile,
  95. mstype_set_srtp_mode,
  96. mstype_set_avpf_mode,
  97. mstype_set_100rel,
  98. mstype_set_rtcp,
  99. mstype_set_rtcpmux,
  100. mstype_set_ice,
  101. mstype_set_ice_stun,
  102. mstype_set_ice_turn,
  103. mstype_set_stun_server,
  104. mstype_set_stun_cred,
  105. mstype_set_video_fps,
  106. mstype_set_video_bw_up,
  107. mstype_set_video_bw_down,
  108. mstype_set_video_prefsize,
  109. mstype_set_qos,
  110. mstype_unset_qos,
  111. mstype_set_timers,
  112. mstype_unset_timers,
  113. mstype_set_codecs,
  114. mstype_set_bypass_encoding,
  115. mstype_set_bypass_decoding,
  116. mstype_set_rtp_ssrc,
  117. mstype_set_msrp_cb
  118. }
  119. tsip_msession_param_type_t;
  120. #define TSIP_MSESSION_SET_SRTP_MODE(SRTP_MODE_ENUM) mstype_set_srtp_mode, (tmedia_srtp_mode_t)SRTP_MODE_ENUM
  121. #define TSIP_MSESSION_SET_AVPF_MODE(MEDIA_MODE_ENUM) mstype_set_avpf_mode, (tmedia_mode_t)MEDIA_MODE_ENUM
  122. #define TSIP_MSESSION_SET_PROFILE(PROFILE_ENUM) mstype_set_srtp_mode, (tmedia_profile_t)PROFILE_ENUM
  123. #define TSIP_MSESSION_SET_100rel(ENABLED_BOOL) mstype_set_100rel, (tsk_bool_t)ENABLED_BOOL
  124. #define TSIP_MSESSION_SET_RTCP(ENABLED_BOOL) mstype_set_rtcp, (tsk_bool_t)ENABLED_BOOL
  125. #define TSIP_MSESSION_SET_RTCPMUX(ENABLED_BOOL) mstype_set_rtcpmux, (tsk_bool_t)ENABLED_BOOL
  126. #define TSIP_MSESSION_SET_ICE(ENABLED_BOOL) mstype_set_ice, (tsk_bool_t)ENABLED_BOOL
  127. #define TSIP_MSESSION_SET_ICE_STUN(ENABLED_BOOL) mstype_set_ice_stun, (tsk_bool_t)ENABLED_BOOL
  128. #define TSIP_MSESSION_SET_ICE_TURN(ENABLED_BOOL) mstype_set_ice_turn, (tsk_bool_t)ENABLED_BOOL
  129. #define TSIP_MSESSION_SET_STUN_SERVER(HOSTNAME, PORT) mstype_set_stun_server, (const char*)HOSTNAME, (uint16_t)PORT
  130. #define TSIP_MSESSION_SET_STUN_CRED(USERNAME, PASSWORD) mstype_set_stun_cred, (const char*)USERNAME, (const char*)PASSWORD
  131. #define TSIP_MSESSION_SET_QOS(TYPE_ENUM, STRENGTH_ENUM) mstype_set_qos, (tmedia_qos_stype_t)TYPE_ENUM, (tmedia_qos_strength_t)STRENGTH_ENUM
  132. #define TSIP_MSESSION_UNSET_QOS() mstype_unset_qos
  133. #define TSIP_MSESSION_SET_VIDEO_FPS(FPS_INT) mstype_set_video_fps, (int32_t)FPS_INT
  134. #define TSIP_MSESSION_SET_VIDEO_BW_UP(BW_INT) mstype_set_video_bw_up, (int32_t)(BW_INT)
  135. #define TSIP_MSESSION_SET_VIDEO_BW_DOWN(BW_INT) mstype_set_video_bw_down, (int32_t)(BW_INT)
  136. #define TSIP_MSESSION_SET_VIDEO_PREFSIZE(PREFSIZE_ENUM) mstype_set_video_prefsize, (int32_t)(PREFSIZE_ENUM)
  137. #define TSIP_MSESSION_SET_TIMERS(TIMEOUT_UINT, REFRESHER_STR) mstype_set_timers, (unsigned)TIMEOUT_UINT, (const char*)REFRESHER_STR
  138. #define TSIP_MSESSION_UNSET_TIMERS() mstype_unset_timers
  139. #define TSIP_MSESSION_SET_CODECS(CODECS_INT) mstype_set_codecs, (signed)CODECS_INT
  140. #define TSIP_MSESSION_SET_BYPASS_ENCODING(ENABLED_BOOL) mstype_set_bypass_encoding, (tsk_bool_t)ENABLED_BOOL
  141. #define TSIP_MSESSION_UNSET_BYPASS_ENCODING() TSIP_MSESSION_SET_BYPASS_ENCODING(tsk_false)
  142. #define TSIP_MSESSION_SET_BYPASS_DECODING(ENABLED_BOOL) mstype_set_bypass_decoding, (tsk_bool_t)ENABLED_BOOL
  143. #define TSIP_MSESSION_SET_RTP_SSRC(MEDIA_ENUM, SSRC_UINT) mstype_set_rtp_ssrc, (tmedia_type_t)MEDIA_ENUM, (uint32_t)SSRC_UINT
  144. #define TSIP_MSESSION_SET_RTP_SSRC_AUDIO(SSRC_UINT) TSIP_MSESSION_SET_RTP_SSRC(tmedia_audio, (SSRC_UINT))
  145. #define TSIP_MSESSION_SET_RTP_SSRC_VIDEO(SSRC_UINT) TSIP_MSESSION_SET_RTP_SSRC(tmedia_video, (SSRC_UINT))
  146. #define TSIP_MSESSION_UNSET_BYPASS_DECODING() TSIP_MSESSION_SET_BYPASS_DECODING(tsk_false)
  147. #define TSIP_MSESSION_SET_MSRP_CB(TMEDIA_SESSION_MSRP_CB_F) mstype_set_msrp_cb, (tmedia_session_msrp_cb_f)TMEDIA_SESSION_MSRP_CB_F
  148. #define TSIP_MSESSION_SET_NULL() mstype_null
  149. typedef struct tsip_ssession_s {
  150. TSK_DECLARE_OBJECT;
  151. tsip_ssession_id_t id;
  152. tsip_ssession_id_t id_parent; //for call transfer
  153. unsigned owner:1;
  154. const struct tsip_stack_s* stack;
  155. const void* userdata;
  156. //=======
  157. // SIP
  158. //=======
  159. tsk_params_L_t *caps;
  160. tsk_params_L_t *headers;
  161. unsigned no_contact:1;
  162. struct tsip_uri_s* from;
  163. struct tsip_uri_s* to;
  164. int64_t expires;
  165. tsk_bool_t silent_hangup;
  166. char* sigcomp_id;
  167. char* auth_ha1;
  168. char* auth_impi;
  169. //=======
  170. // WebSocket
  171. //=======
  172. struct {
  173. // used when the stack is running in webrtc2sip mode to store the 'origin' (a.k.a 'src')
  174. struct {
  175. char* host;
  176. tsk_istr_t port;
  177. char* proto;
  178. } src;
  179. } ws;
  180. //=======
  181. // Media
  182. //=======
  183. struct {
  184. tmedia_type_t type;
  185. tmedia_profile_t profile;
  186. tmedia_srtp_mode_t srtp_mode;
  187. tmedia_mode_t avpf_mode;
  188. tmedia_codec_id_t codecs;
  189. tsk_bool_t bypass_encoding;
  190. tsk_bool_t bypass_decoding;
  191. /* Video */
  192. int32_t video_fps;
  193. int32_t video_bw_up;
  194. int32_t video_bw_down;
  195. tmedia_pref_video_size_t video_pref_size;
  196. /* RTP*/
  197. struct {
  198. struct {
  199. uint32_t audio;
  200. uint32_t video;
  201. } ssrc;
  202. } rtp;
  203. /* Session timers */
  204. struct {
  205. char* refresher;
  206. unsigned timeout;
  207. } timers;
  208. /* QoS */
  209. struct {
  210. tmedia_qos_stype_t type;
  211. tmedia_qos_strength_t strength;
  212. } qos;
  213. /* MSRP */
  214. struct {
  215. tmedia_session_msrp_cb_f callback;
  216. } msrp;
  217. /* STUN */
  218. struct {
  219. char* username;
  220. char* password;
  221. char* hostname;
  222. uint16_t port;
  223. } stun;
  224. /* Features */
  225. unsigned enable_conditional_ringing:1;
  226. unsigned enable_100rel:1;
  227. unsigned enable_ice:1;
  228. unsigned enable_icestun:1;
  229. unsigned enable_iceturn:1;
  230. unsigned enable_rtcp:1;
  231. unsigned enable_rtcpmux:1;
  232. } media;
  233. }
  234. tsip_ssession_t;
  235. /** A pointer to a SIP Session */
  236. typedef void tsip_ssession_handle_t;
  237. /** A pointer to a LTE/IMS stack */
  238. typedef void tsip_stack_handle_t;
  239. TINYSIP_API tsip_ssession_handle_t* tsip_ssession_create(tsip_stack_handle_t *stack, ...);
  240. TINYSIP_API int tsip_ssession_set(tsip_ssession_handle_t *self, ...);
  241. TINYSIP_API tsip_ssession_id_t tsip_ssession_get_id(const tsip_ssession_handle_t *self);
  242. TINYSIP_API tsip_ssession_id_t tsip_ssession_get_id_parent(const tsip_ssession_handle_t *self);
  243. TINYSIP_API int tsip_ssession_take_ownership(tsip_ssession_handle_t *self);
  244. TINYSIP_API tsk_bool_t tsip_ssession_have_ownership(const tsip_ssession_handle_t *self);
  245. TINYSIP_API int tsip_ssession_respond(const tsip_ssession_handle_t *self, short status, const char* phrase, const void* payload, tsk_size_t size, const struct tsip_message_s* request, ...);
  246. TINYSIP_API const void* tsip_ssession_get_userdata(const tsip_ssession_handle_t *self);
  247. TINYSIP_API tmedia_type_t tsip_ssession_get_mediatype(const tsip_ssession_handle_t *self);
  248. TINYSIP_API tmedia_session_mgr_t* tsip_session_get_mediamgr(const tsip_ssession_handle_t *self);
  249. TINYSIP_API const tsip_stack_handle_t* tsip_ssession_get_stack(const tsip_ssession_handle_t *self);
  250. TINYSIP_API tmedia_codec_id_t tsip_ssession_get_codecs_neg(tsip_ssession_handle_t *self);
  251. int tsip_ssession_handle(const tsip_ssession_t *self, const struct tsip_action_s* action);
  252. typedef tsk_list_t tsip_ssessions_L_t; /**< List of @ref tsip_ssession_handle_t elements. */
  253. TINYSIP_GEXTERN const tsk_object_def_t *tsip_ssession_def_t;
  254. TSIP_END_DECLS
  255. #endif /* TSIP_SSESSION_H */