test_sessions.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)yahoo.fr>
  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 _TEST_SESSIONS_H_
  23. #define _TEST_SESSIONS_H_
  24. #define SDP_RO \
  25. "v=0\r\n" \
  26. "o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n" \
  27. "s=\r\n" \
  28. "i=A Seminar on the session description protocol\r\n" \
  29. "u=http://www.example.com/seminars/sdp.pdf\r\n" \
  30. "e=j.doe@example.com (Jane Doe)\r\n" \
  31. "p=+1 617 555-6011\r\n" \
  32. "c=IN IP4 host.atlanta.example.com\r\n" \
  33. "b=X-YZ:128\r\n" \
  34. "z=2882844526 -1h 2898848070 0\r\n" \
  35. "k=base64:ZWFzdXJlLg==\r\n" \
  36. "t=3034423619 3042462419\r\n" \
  37. "r=7d 1h 0 25h\r\n" \
  38. "r=604800 3600 0 90000\r\n" \
  39. "w=my dummy header\r\n" \
  40. "m=audio 49170 RTP/AVP 8 0 97 98\r\n" \
  41. "i=Audio line\r\n" \
  42. "c=IN IP4 otherhost.biloxi.example.com\r\n" \
  43. "k=base64:ZWFzdXJlLgdddddddddddddddddddddd==\r\n" \
  44. "a=rtpmap:8 PCMA/8000\r\n" \
  45. "a=rtpmap:0 PCMU/8000\r\n" \
  46. "a=rtpmap:97 iLBC/8000\r\n" \
  47. "a=rtpmap:98 AMR-WB/16000\r\n" \
  48. "a=curr:qos local none\r\n" \
  49. "a=curr:qos remote none\r\n" \
  50. "a=des:qos mandatory local sendrecv\r\n" \
  51. "a=des:qos mandatory remote sendrecv\r\n" \
  52. "a=conf:qos remote sendrecv\r\n" \
  53. "a=fmtp:98 octet-align=1\r\n" \
  54. "m=video 51372 RTP/AVP 31 32 98\r\n" \
  55. "i=Video line\r\n" \
  56. "b=A-YZ:92\r\n" \
  57. "b=B-YZ:256\r\n" \
  58. "a=rtpmap:31 H261/90000\r\n" \
  59. "a=rtpmap:32 MPV/90000\r\n" \
  60. "a=rtpmap:98 H264/90000\r\n" \
  61. "a=fmtp:98 profile-level-id=42A01E\r\n" \
  62. "a=recvonly\r\n" \
  63. "m=toto 51372 RTP/AVP 31 32\r\n" \
  64. "i=Video line\r\n" \
  65. "b=A-YZ:92\r\n" \
  66. "b=B-YZ:256\r\n" \
  67. "a=rtpmap:31 H261/90000\r\n" \
  68. "a=rtpmap:32 MPV/90000\r\n" \
  69. "a=recvonly\r\n"
  70. void test_sessions_client()
  71. {
  72. tmedia_session_mgr_t* mgr;
  73. const tsdp_message_t* sdp_lo;
  74. tsdp_message_t* sdp_ro;
  75. char* temp;
  76. tsk_bool_t canresume;
  77. tmedia_type_t media_type = (tmedia_audio | tmedia_video | tmedia_msrp | tmedia_t38);
  78. int32_t width = 176;
  79. int64_t height = 144LL;
  80. /* create manager */
  81. mgr = tmedia_session_mgr_create((tmedia_audio | tmedia_video | tmedia_msrp | tmedia_t38),
  82. "0.0.0.0", tsk_false, tsk_true);
  83. tmedia_session_mgr_set_qos(mgr, tmedia_qos_stype_segmented, tmedia_qos_strength_mandatory);
  84. tmedia_session_mgr_set(mgr,
  85. TMEDIA_SESSION_VIDEO_SET_INT32("width", width),
  86. TMEDIA_SESSION_VIDEO_SET_INT64("height", height),
  87. TMEDIA_SESSION_VIDEO_SET_STR("description", "This is my session"),
  88. TMEDIA_SESSION_AUDIO_SET_INT32("rate", "8000"),
  89. TMEDIA_SESSION_SET_STR(tmedia_audio | tmedia_video, "hello", "world"),
  90. TMEDIA_SESSION_SET_NULL());
  91. /* get lo */
  92. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  93. if((temp = tsdp_message_tostring(sdp_lo))) {
  94. TSK_DEBUG_INFO("sdp_lo=%s", temp);
  95. TSK_FREE(temp);
  96. }
  97. /* set ro */
  98. if((sdp_ro = tsdp_message_parse(SDP_RO, tsk_strlen(SDP_RO)))) {
  99. tmedia_session_mgr_set_ro(mgr, sdp_ro);
  100. TSK_OBJECT_SAFE_FREE(sdp_ro);
  101. }
  102. /* get lo */
  103. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  104. if((temp = tsdp_message_tostring(sdp_lo))) {
  105. TSK_DEBUG_INFO("sdp_lo=%s", temp);
  106. TSK_FREE(temp);
  107. }
  108. tmedia_session_mgr_start(mgr);
  109. canresume = tmedia_session_mgr_canresume(mgr);
  110. TSK_OBJECT_SAFE_FREE(mgr);
  111. }
  112. void test_sessions_server()
  113. {
  114. tmedia_session_mgr_t* mgr = tsk_null;
  115. const tsdp_message_t* sdp_lo;
  116. tsdp_message_t* sdp_ro = tsk_null;
  117. char* temp;
  118. tmedia_type_t type;
  119. /* parse ro */
  120. if(!(sdp_ro = tsdp_message_parse(SDP_RO, tsk_strlen(SDP_RO)))) {
  121. TSK_DEBUG_ERROR("Failed to parse ro");
  122. return;
  123. }
  124. else {
  125. /* get ro media type */
  126. type = tmedia_type_from_sdp(sdp_ro);
  127. }
  128. /* create manager */
  129. mgr = tmedia_session_mgr_create(type, "192.168.16.82", tsk_false, tsk_false);
  130. /* set ro */
  131. tmedia_session_mgr_set_ro(mgr, sdp_ro);
  132. /* get lo */
  133. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  134. if((temp = tsdp_message_tostring(sdp_lo))) {
  135. TSK_DEBUG_INFO("sdp_lo=%s", temp);
  136. TSK_FREE(temp);
  137. }
  138. TSK_OBJECT_SAFE_FREE(sdp_ro);
  139. TSK_OBJECT_SAFE_FREE(mgr);
  140. }
  141. void test_sessions_hold_resume()
  142. {
  143. tmedia_session_mgr_t* mgr;
  144. const tsdp_message_t* sdp_lo;
  145. char* temp;
  146. tmedia_type_t type = tmedia_audio | tmedia_video | tmedia_msrp | tmedia_t38;
  147. /* create manager */
  148. mgr = tmedia_session_mgr_create(type, "192.168.16.82", tsk_false, tsk_true);
  149. /* get lo */
  150. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  151. if((temp = tsdp_message_tostring(sdp_lo))) {
  152. TSK_DEBUG_INFO("sdp_lo=%s", temp);
  153. TSK_FREE(temp);
  154. }
  155. /* hold */
  156. tmedia_session_mgr_hold(mgr, type);
  157. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  158. if((temp = tsdp_message_tostring(sdp_lo))) {
  159. TSK_DEBUG_INFO("sdp_lo(hold)=%s", temp);
  160. TSK_FREE(temp);
  161. }
  162. TSK_DEBUG_INFO("Hold local=%s and remote=%s",
  163. tmedia_session_mgr_is_held(mgr, type, tsk_true) ? "yes" : "no",
  164. tmedia_session_mgr_is_held(mgr, type, tsk_false) ? "yes" : "no"
  165. );
  166. /* resume */
  167. tmedia_session_mgr_resume(mgr, type, tsk_true);
  168. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  169. if((temp = tsdp_message_tostring(sdp_lo))) {
  170. TSK_DEBUG_INFO("sdp_lo(resume)=%s", temp);
  171. TSK_FREE(temp);
  172. }
  173. TSK_DEBUG_INFO("Hold local=%s and remote=%s",
  174. tmedia_session_mgr_is_held(mgr, type, tsk_true) ? "yes" : "no",
  175. tmedia_session_mgr_is_held(mgr, type, tsk_false) ? "yes" : "no"
  176. );
  177. TSK_OBJECT_SAFE_FREE(mgr);
  178. }
  179. void test_sessions_add_remove()
  180. {
  181. tmedia_session_mgr_t* mgr = tsk_null;
  182. const tsdp_message_t* sdp_lo;
  183. tsdp_message_t* sdp_ro = tsk_null;
  184. char* temp;
  185. tmedia_type_t type;
  186. /* parse ro */
  187. if(!(sdp_ro = tsdp_message_parse(SDP_RO, tsk_strlen(SDP_RO)))) {
  188. TSK_DEBUG_ERROR("Failed to parse ro");
  189. return;
  190. }
  191. else {
  192. /* get ro media type */
  193. type = tmedia_type_from_sdp(sdp_ro);
  194. }
  195. /* create manager */
  196. mgr = tmedia_session_mgr_create(type, "192.168.16.82", tsk_false, tsk_false);
  197. /* set ro */
  198. tmedia_session_mgr_set_ro(mgr, sdp_ro);
  199. /* get lo */
  200. sdp_lo = tmedia_session_mgr_get_lo(mgr);
  201. if((temp = tsdp_message_tostring(sdp_lo))) {
  202. TSK_DEBUG_INFO("sdp_lo=%s", temp);
  203. TSK_FREE(temp);
  204. }
  205. TSK_OBJECT_SAFE_FREE(sdp_ro);
  206. TSK_OBJECT_SAFE_FREE(mgr);
  207. }
  208. void test_sessions()
  209. {
  210. test_sessions_client();
  211. //test_sessions_server();
  212. //test_sessions_hold_resume();
  213. }
  214. #endif /* _TEST_SESSIONS_H_ */