SipSession.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.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. #ifndef TINYWRAP_SIPSESSION_H
  23. #define TINYWRAP_SIPSESSION_H
  24. #include "tinyWRAP_config.h"
  25. #include "tinysip.h"
  26. #include "tinymedia/tmedia_qos.h"
  27. #include "ActionConfig.h"
  28. class SipUri;
  29. class SipStack;
  30. class MsrpCallback;
  31. class MediaSessionMgr;
  32. /* ======================== T140Callback ========================*/
  33. class TINYWRAP_API T140CallbackData
  34. {
  35. public:
  36. #if !defined(SWIG)
  37. T140CallbackData(enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size) {
  38. m_eType = data_type;
  39. m_pPtr = data_ptr;
  40. m_nSize = data_size;
  41. }
  42. #endif
  43. virtual ~T140CallbackData() {}
  44. inline enum tmedia_t140_data_type_e getType()const {
  45. return m_eType;
  46. }
  47. inline unsigned getSize()const {
  48. return m_nSize;
  49. }
  50. inline unsigned getData(void* pOutput, unsigned nMaxsize)const {
  51. unsigned nRetsize = 0;
  52. if(pOutput && nMaxsize && m_pPtr) {
  53. nRetsize = (m_nSize > nMaxsize) ? nMaxsize : m_nSize;
  54. memcpy(pOutput, m_pPtr, nRetsize);
  55. }
  56. return nRetsize;
  57. }
  58. private:
  59. enum tmedia_t140_data_type_e m_eType;
  60. const void* m_pPtr;
  61. unsigned m_nSize;
  62. };
  63. class TINYWRAP_API T140Callback
  64. {
  65. public:
  66. T140Callback() {}
  67. virtual ~T140Callback() {}
  68. virtual int ondata(const T140CallbackData* pData) {
  69. return 0;
  70. }
  71. };
  72. #if !defined(SWIG)
  73. class RtcpCallbackData
  74. {
  75. public:
  76. RtcpCallbackData(enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media) {
  77. m_eType = event_type;
  78. m_nSSRC = ssrc_media;
  79. }
  80. virtual ~RtcpCallbackData() {}
  81. inline enum tmedia_rtcp_event_type_e getType()const {
  82. return m_eType;
  83. }
  84. inline uint32_t getSSRC()const {
  85. return m_nSSRC;
  86. }
  87. private:
  88. enum tmedia_rtcp_event_type_e m_eType;
  89. uint32_t m_nSSRC;
  90. };
  91. class TINYWRAP_API RtcpCallback
  92. {
  93. public:
  94. RtcpCallback() {}
  95. virtual ~RtcpCallback() {}
  96. virtual int onevent(const RtcpCallbackData* e) {
  97. return 0;
  98. }
  99. };
  100. #endif /* #if !defined(SWIG) */
  101. /* ======================== SipSession ========================*/
  102. class TINYWRAP_API SipSession
  103. {
  104. public:
  105. SipSession(SipStack* stack);
  106. #if !defined(SWIG)
  107. SipSession(SipStack* stack, tsip_ssession_handle_t* pHandle);
  108. #endif
  109. virtual ~SipSession();
  110. public:
  111. bool haveOwnership();
  112. bool addHeader(const char* name, const char* value);
  113. bool removeHeader(const char* name);
  114. bool addCaps(const char* name, const char* value);
  115. bool addCaps(const char* name);
  116. bool removeCaps(const char* name);
  117. bool setExpires(unsigned expires);
  118. bool setFromUri(const char* fromUriString);
  119. bool setFromUri(const SipUri* fromUri);
  120. bool setToUri(const char* toUriString);
  121. bool setToUri(const SipUri* toUri);
  122. bool setSilentHangup(bool silent);
  123. bool addSigCompCompartment(const char* compId);
  124. bool removeSigCompCompartment();
  125. #if !defined(SWIG)
  126. bool setAuth(const char* authHa1, const char* authIMPI);
  127. #endif
  128. unsigned getId()const;
  129. #if !defined(SWIG)
  130. bool setWebSocketSrc(const char* host, int32_t port, const char* proto);
  131. const SipStack* getStack() const;
  132. const tsip_ssession_handle_t* getWrappedSession() {
  133. return m_pHandle;
  134. }
  135. #endif
  136. private:
  137. void init(SipStack* stack, tsip_ssession_handle_t* pHandle=tsk_null);
  138. protected:
  139. tsip_ssession_handle_t* m_pHandle;
  140. const SipStack* m_pStack;
  141. };
  142. /* ======================== InviteSession ========================*/
  143. class TINYWRAP_API InviteSession : public SipSession
  144. {
  145. public: /* ctor() and dtor() */
  146. InviteSession(SipStack* Stack);
  147. #if !defined(SWIG)
  148. InviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  149. #endif
  150. virtual ~InviteSession();
  151. public: /* Public functions */
  152. bool accept(ActionConfig* config=tsk_null);
  153. bool hangup(ActionConfig* config=tsk_null);
  154. bool reject(ActionConfig* config=tsk_null);
  155. bool sendInfo(const void* payload, unsigned len, ActionConfig* config=tsk_null);
  156. const MediaSessionMgr* getMediaMgr();
  157. private:
  158. MediaSessionMgr* m_pMediaMgr;
  159. };
  160. /* ======================== CallSession ========================*/
  161. class TINYWRAP_API CallSession : public InviteSession
  162. {
  163. public: /* ctor() and dtor() */
  164. CallSession(SipStack* pStack);
  165. #if !defined(SWIG)
  166. CallSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  167. #endif
  168. virtual ~CallSession();
  169. public: /* Public functions */
  170. bool callAudio(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */
  171. bool callAudio(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */
  172. bool callAudioVideo(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */
  173. bool callAudioVideo(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */
  174. bool callVideo(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */
  175. bool callVideo(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */
  176. bool call(const char* remoteUriString, twrap_media_type_t media, ActionConfig* config=tsk_null);
  177. bool call(const SipUri* remoteUri, twrap_media_type_t media, ActionConfig* config=tsk_null);
  178. #if !defined(SWIG)
  179. bool setSupportedCodecs(int32_t codecs);
  180. int32_t getNegotiatedCodecs();
  181. bool setMediaSSRC(twrap_media_type_t media, uint32_t ssrc);
  182. #endif
  183. bool setSessionTimer(unsigned timeout, const char* refresher);
  184. bool set100rel(bool enabled);
  185. bool setRtcp(bool enabled);
  186. bool setRtcpMux(bool enabled);
  187. bool setSRtpMode(enum tmedia_srtp_mode_e mode);
  188. bool setAvpfMode(enum tmedia_mode_e mode);
  189. bool setICE(bool enabled);
  190. bool setICEStun(bool enabled);
  191. bool setICETurn(bool enabled);
  192. bool setSTUNServer(const char* hostname, uint16_t port);
  193. bool setSTUNCred(const char* username, const char* password);
  194. bool setVideoFps(int32_t fps);
  195. bool setVideoBandwidthUploadMax(int32_t max);
  196. bool setVideoBandwidthDownloadMax(int32_t max);
  197. bool setVideoPrefSize(tmedia_pref_video_size_t pref_video_size);
  198. bool setQoS(tmedia_qos_stype_t type, tmedia_qos_strength_t strength);
  199. bool hold(ActionConfig* config=tsk_null);
  200. bool resume(ActionConfig* config=tsk_null);
  201. bool transfer(const char* referToUriString, ActionConfig* config=tsk_null);
  202. bool acceptTransfer(ActionConfig* config=tsk_null);
  203. bool rejectTransfer(ActionConfig* config=tsk_null);
  204. bool sendDTMF(int number);
  205. unsigned getSessionTransferId();
  206. bool sendT140Data(enum tmedia_t140_data_type_e data_type, const void* data_ptr = NULL, unsigned data_size = 0);
  207. bool setT140Callback(const T140Callback* pT140Callback);
  208. #if !defined(SWIG)
  209. bool sendRtcpEvent(enum tmedia_rtcp_event_type_e event_type, twrap_media_type_t media_type, uint32_t ssrc_media = 0);
  210. bool setRtcpCallback(const RtcpCallback* pRtcpCallback, twrap_media_type_t media_type);
  211. const T140Callback* getT140Callback() const;
  212. static int t140OnDataCallback(const void* context, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size);
  213. const RtcpCallback* getRtcpCallback() const;
  214. static int rtcpOnCallback(const void* context, enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media);
  215. #endif /* #if !defined(SWIG) */
  216. private:
  217. const T140Callback* m_pT140Callback;
  218. const RtcpCallback* m_pRtcpCallback;
  219. };
  220. /* ======================== MsrpSession ========================*/
  221. class TINYWRAP_API MsrpSession : public InviteSession
  222. {
  223. public: /* ctor() and dtor() */
  224. MsrpSession(SipStack* pStack, MsrpCallback* pCallback);
  225. #if !defined(SWIG)
  226. MsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  227. #endif
  228. virtual ~MsrpSession();
  229. public: /* Public functions */
  230. bool setCallback(MsrpCallback* pCallback);
  231. bool callMsrp(const char* remoteUriString, ActionConfig* config=tsk_null);
  232. bool callMsrp(const SipUri* remoteUri, ActionConfig* config=tsk_null);
  233. bool sendMessage(const void* payload, unsigned len, ActionConfig* config=tsk_null);
  234. bool sendFile(ActionConfig* config=tsk_null);
  235. public: /* Public helper function */
  236. #if !defined(SWIG)
  237. inline MsrpCallback* getCallback()const {
  238. return m_pCallback;
  239. }
  240. #endif
  241. private:
  242. MsrpCallback* m_pCallback;
  243. };
  244. /* ======================== MessagingSession ========================*/
  245. class TINYWRAP_API MessagingSession : public SipSession
  246. {
  247. public: /* ctor() and dtor() */
  248. MessagingSession(SipStack* pStack);
  249. #if !defined(SWIG)
  250. MessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  251. #endif
  252. virtual ~MessagingSession();
  253. public: /* Public functions */
  254. bool send(const void* payload, unsigned len, ActionConfig* config=tsk_null);
  255. bool accept(ActionConfig* config=tsk_null);
  256. bool reject(ActionConfig* config=tsk_null);
  257. };
  258. /* ======================== InfoSession ========================*/
  259. class TINYWRAP_API InfoSession : public SipSession
  260. {
  261. public: /* ctor() and dtor() */
  262. InfoSession(SipStack* pStack);
  263. #if !defined(SWIG)
  264. InfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  265. #endif
  266. virtual ~InfoSession();
  267. public: /* Public functions */
  268. bool send(const void* payload, unsigned len, ActionConfig* config=tsk_null);
  269. bool accept(ActionConfig* config=tsk_null);
  270. bool reject(ActionConfig* config=tsk_null);
  271. };
  272. /* ======================== OptionsSession ========================*/
  273. class TINYWRAP_API OptionsSession : public SipSession
  274. {
  275. public: /* ctor() and dtor() */
  276. OptionsSession(SipStack* pStack);
  277. #if !defined(SWIG)
  278. OptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  279. #endif
  280. virtual ~OptionsSession();
  281. public: /* Public functions */
  282. bool send(ActionConfig* config=tsk_null);
  283. bool accept(ActionConfig* config=tsk_null);
  284. bool reject(ActionConfig* config=tsk_null);
  285. };
  286. /* ======================== PublicationSession ========================*/
  287. class TINYWRAP_API PublicationSession : public SipSession
  288. {
  289. public: /* ctor() and dtor() */
  290. PublicationSession(SipStack* pStack);
  291. #if !defined(SWIG)
  292. PublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  293. #endif
  294. virtual ~PublicationSession();
  295. public: /* Public functions */
  296. bool publish(const void* payload, unsigned len, ActionConfig* config=tsk_null);
  297. bool unPublish(ActionConfig* config=tsk_null);
  298. };
  299. /* ======================== RegistrationSession ========================*/
  300. class TINYWRAP_API RegistrationSession : public SipSession
  301. {
  302. public: /* ctor() and dtor() */
  303. RegistrationSession(SipStack* pStack);
  304. #if !defined(SWIG)
  305. RegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  306. #endif
  307. virtual ~RegistrationSession();
  308. public: /* Public functions */
  309. bool register_(ActionConfig* config=tsk_null);
  310. bool unRegister(ActionConfig* config=tsk_null);
  311. bool accept(ActionConfig* config=tsk_null);
  312. bool reject(ActionConfig* config=tsk_null);
  313. };
  314. /* ======================== SubscriptionSession ========================*/
  315. class TINYWRAP_API SubscriptionSession : public SipSession
  316. {
  317. public: /* ctor() and dtor() */
  318. SubscriptionSession(SipStack* pStack);
  319. #if !defined(SWIG)
  320. SubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  321. #endif
  322. virtual ~SubscriptionSession();
  323. public: /* Public functions */
  324. bool subscribe();
  325. bool unSubscribe();
  326. };
  327. #endif /* TINYWRAP_SIPSESSION_H */