test_parser.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. * Copyright (C) 2012 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. #ifndef _TEST_SDPPARSER_H
  22. #define _TEST_SDPPARSER_H
  23. #include "tinysdp/headers/tsdp_header_Dummy.h"
  24. #include "tinysdp/headers/tsdp_header_A.h"
  25. #include "tinysdp/headers/tsdp_header_C.h"
  26. #include "tinysdp/headers/tsdp_header_E.h"
  27. #include "tinysdp/headers/tsdp_header_I.h"
  28. #include "tinysdp/headers/tsdp_header_P.h"
  29. #define SDP_MSG1 \
  30. "v=0\r\n" \
  31. "o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n" \
  32. "s=\r\n" \
  33. "i=A Seminar on the session description protocol\r\n" \
  34. "u=http://www.example.com/seminars/sdp.pdf\r\n" \
  35. "e=j.doe@example.com (Jane Doe)\r\n" \
  36. "p=+1 617 555-6011\r\n" \
  37. "c=IN IP4 host.atlanta.example.com\r\n" \
  38. "b=X-YZ:128\r\n" \
  39. "z=2882844526 -1h 2898848070 0\r\n" \
  40. "k=base64:ZWFzdXJlLg==\r\n" \
  41. "t=3034423619 3042462419\r\n" \
  42. "r=7d 1h 0 25h\r\n" \
  43. "r=604800 3600 0 90000\r\n" \
  44. "w=my dummy header\r\n" \
  45. "m=audio 49170 RTP/AVP 0 8 97 98\r\n" \
  46. "i=Audio line\r\n" \
  47. "c=IN IP4 otherhost.biloxi.example.com\r\n" \
  48. "k=base64:ZWFzdXJlLgdddddddddddddddddddddd==\r\n" \
  49. "a=rtpmap:0 PCMU/8000\r\n" \
  50. "a=rtpmap:8 PCMA/8000\r\n" \
  51. "a=rtpmap:97 iLBC/8000\r\n" \
  52. "a=rtpmap:98 AMR-WB/16000\r\n" \
  53. "a=fmtp:98 octet-align=1\r\n" \
  54. "m=video 51372 RTP/AVP 31 32\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=recvonly\r\n"
  61. #define SDP_MSG2 \
  62. "v=0\r\n"
  63. #define SDP_MSG3 \
  64. "v=0\r\n" \
  65. "o=lgevcs 1 1 IN IP4 192.168.1.115\r\n" \
  66. "s=-\r\n" \
  67. "c=IN IP4 192.168.1.115\r\n" \
  68. "b=AS:512\r\n" \
  69. "t=0 0\r\n" \
  70. "m=audio 2000 RTP/AVP 9 8 0 101\r\n" \
  71. "a=rtpmap:9 G722/8000\r\n" \
  72. "a=rtpmap:8 PCMA/8000\r\n" \
  73. "a=rtpmap:0 PCMU/8000\r\n" \
  74. "a=rtpmap:101 telephone-event/8000\r\n" \
  75. "a=fmtp:101 0-11,16\r\n" \
  76. "a=sendrecv\r\n" \
  77. "m=video 2002 RTP/AVP 34\r\n" \
  78. "b=TIAS:512000\r\n" \
  79. "a=content:main\r\n" \
  80. "a=rtpmap:34 H263/90000\r\n" \
  81. "a=fmtp:34 CIF=2\r\n" \
  82. "a=sendrecv\r\n"
  83. #define SDP_FF \
  84. "v=0\r\no=Mozilla-SIPUA-33.1.1 21626 0 IN IP4 0.0.0.0\r\ns=SIP Call\r\nt=0 0\r\na=ice-ufrag:d0a7e7c7\r\na=ice-pwd:f079952b194bac309ea77ff813540eb0\r\na=fingerprint:sha-256 10:B9:12:6F:F3:21:6B:F4:53:E2:70:BA:13:A3:3A:3C:DF:3F:28:FD:6D:E4:09:A4:6F:EC:57:95:7D:83:3E:46\r\nm=video 59587 UDP/TLS/RTP/SAVPF 120 126 97\r\nc=IN IP4 188.165.231.30\r\na=rtpmap:120 VP8/90000\r\na=rtpmap:126 H264/90000\r\na=fmtp:126 profile-level-id=42e01f;packetization-mode=1\r\na=rtpmap:97 H264/90000\r\na=fmtp:97 profile-level-id=42e01f\r\na=sendrecv\r\na=rtcp-fb:120 nack\r\na=rtcp-fb:120 nack pli\r\na=rtcp-fb:120 ccm fir\r\na=rtcp-fb:126 nack\r\na=rtcp-fb:126 nack pli\r\na=rtcp-fb:126 ccm fir\r\na=rtcp-fb:97 nack\r\na=rtcp-fb:97 nack pli\r\na=rtcp-fb:97 ccm fir\r\na=setup:actpass\r\na=candidate:0 1 UDP 2130379007 192.168.0.28 60862 typ host\r\na=candidate:1 1 UDP 1694236671 88.179.39.5 60862 typ srflx raddr 192.168.0.28 rport 60862\r\na=candidate:2 1 UDP 16515071 188.165.231.30 59587 typ relay raddr 188.165.231.30 rport 59587\r\na=candidate:0 2 UDP 2130379006 192.168.0.28 61634 typ host\r\na=candidate:1 2 UDP 1694236670 88.179.39.5 61634 typ srflx raddr 192.168.0.28 rport 61634\r\na=candidate:2 2 UDP 16515070 188.165.231.30 62984 typ relay raddr 188.165.231.30 rport 62984\r\na=rtcp-mux\r\n"
  85. #define SDP_MSG_TO_TEST SDP_FF
  86. void test_caps();
  87. void test_holdresume();
  88. void test_M();
  89. void test_parser()
  90. {
  91. tsdp_message_t *message = tsk_null;
  92. char* str;
  93. //test_caps();
  94. //test_holdresume();
  95. //test_M();
  96. //
  97. // deserialize/serialize the message
  98. //
  99. if((message = tsdp_message_parse(SDP_MSG_TO_TEST, strlen(SDP_MSG_TO_TEST)))) {
  100. /* serialize the message */
  101. if((str = tsdp_message_tostring(message))) {
  102. TSK_DEBUG_INFO("SDP Message=\n%s", str);
  103. TSK_FREE(str);
  104. }
  105. TSK_OBJECT_SAFE_FREE(message);
  106. }
  107. else {
  108. TSK_DEBUG_ERROR("Failed to parse SDP message.");
  109. }
  110. //
  111. // create empty message
  112. //
  113. if((message = tsdp_message_create_empty("127.0.0.1", tsk_false, 1))) {
  114. /* add media */
  115. tsdp_message_add_media(message, "audio", 8956, "RTP/AVP",
  116. TSDP_HEADER_I_VA_ARGS("this is the information line"),
  117. // pcmu
  118. TSDP_FMT_VA_ARGS("0"),
  119. TSDP_HEADER_A_VA_ARGS("rtpmap", "0 pcmu/8000"),
  120. TSDP_HEADER_A_VA_ARGS("3gpp_sync_info", "No Sync"),
  121. // pcma
  122. TSDP_FMT_VA_ARGS("8"),
  123. TSDP_HEADER_A_VA_ARGS("rtpmap", "8 pcma/8000"),
  124. // telephone event
  125. TSDP_FMT_VA_ARGS("101"),
  126. TSDP_HEADER_A_VA_ARGS("rtpmap", "101 telephone-event/8000"),
  127. TSDP_HEADER_A_VA_ARGS("fmtp", "101 0-11"),
  128. // common values
  129. TSDP_HEADER_A_VA_ARGS("sendrecv", tsk_null),
  130. TSDP_HEADER_A_VA_ARGS("ptime", "20"),
  131. tsk_null);
  132. //tsdp_message_remove_media(message, "video");
  133. //tsdp_message_remove_media(message, "audio");
  134. /* serialize the message */
  135. if((str = tsdp_message_tostring(message))) {
  136. TSK_DEBUG_INFO("\n\nEmpty SDP Message=\n%s", str);
  137. TSK_FREE(str);
  138. }
  139. TSK_OBJECT_SAFE_FREE(message);
  140. }
  141. }
  142. void test_caps()
  143. {
  144. tsdp_message_t *message = tsk_null;
  145. char* str;
  146. if((message = tsdp_message_create_empty("100.3.6.6", tsk_false, 1))) {
  147. tsdp_message_add_headers(message,
  148. TSDP_HEADER_C_VA_ARGS("IN", "IP4", "192.0.2.4"),
  149. TSDP_HEADER_E_VA_ARGS("j.doe@example.com (Jane Doe)"),
  150. TSDP_HEADER_P_VA_ARGS("+44 (123)456789"),
  151. tsk_null);
  152. /* add (audio) media */
  153. tsdp_message_add_media(message, "audio", 0, "RTP/AVP",
  154. TSDP_HEADER_I_VA_ARGS("this is the (audio)information line"),
  155. // PCMU
  156. TSDP_FMT_VA_ARGS("0"),
  157. TSDP_HEADER_A_VA_ARGS("rtpmap", "0 PCMU/8000"),
  158. // 1016
  159. TSDP_FMT_VA_ARGS("1"),
  160. TSDP_HEADER_A_VA_ARGS("rtpmap", "1 1016/8000"),
  161. // GSM
  162. TSDP_FMT_VA_ARGS("3"),
  163. TSDP_HEADER_A_VA_ARGS("rtpmap", "3 GSM/8000"),
  164. tsk_null);
  165. /* add (video) media */
  166. tsdp_message_add_media(message, "video", 0, "RTP/AVP",
  167. TSDP_HEADER_I_VA_ARGS("this is the (video)information line"),
  168. // H261
  169. TSDP_FMT_VA_ARGS("31"),
  170. TSDP_HEADER_A_VA_ARGS("rtpmap", "31 H261/90000"),
  171. // H263
  172. TSDP_FMT_VA_ARGS("34"),
  173. TSDP_HEADER_A_VA_ARGS("rtpmap", "34 H263/90000"),
  174. tsk_null);
  175. /* serialize the message */
  176. if((str = tsdp_message_tostring(message))) {
  177. TSK_DEBUG_INFO("\n\nCapabilities SDP Message=\n%s", str);
  178. TSK_FREE(str);
  179. }
  180. TSK_OBJECT_SAFE_FREE(message);
  181. }
  182. }
  183. void test_holdresume()
  184. {
  185. tsdp_message_t *message = tsk_null;
  186. char* str;
  187. if((message = tsdp_message_parse(SDP_MSG_TO_TEST, strlen(SDP_MSG_TO_TEST)))) {
  188. // hold audio
  189. tsdp_message_hold(message, "audio");
  190. tsdp_message_hold(message, "audio");
  191. tsdp_message_hold(message, "video");
  192. tsdp_message_resume(message, "video");
  193. /* serialize the message */
  194. if((str = tsdp_message_tostring(message))) {
  195. TSK_DEBUG_INFO("SDP Message=\n%s", str);
  196. TSK_FREE(str);
  197. }
  198. TSK_OBJECT_SAFE_FREE(message);
  199. }
  200. else {
  201. TSK_DEBUG_ERROR("Failed to parse SDP message.");
  202. }
  203. }
  204. void test_M()
  205. {
  206. char* rtpmap, *fmtp;
  207. const tsk_list_item_t* item;
  208. const tsdp_header_M_t* M;
  209. tsdp_message_t *message = tsk_null;
  210. if((message = tsdp_message_parse(SDP_MSG_TO_TEST, strlen(SDP_MSG_TO_TEST)))) {
  211. tsk_list_foreach(item, message->headers) {
  212. if(!(item->data) || (TSDP_HEADER(item->data)->type != tsdp_htype_M)) {
  213. continue;
  214. }
  215. M = (const tsdp_header_M_t*)(item->data);
  216. /* get rtpmap */
  217. if((rtpmap = tsdp_header_M_get_rtpmap(M, "98"))) {
  218. TSK_DEBUG_INFO("RTPMAP=%s", rtpmap);
  219. TSK_FREE(rtpmap);
  220. }
  221. /* get fmtp */
  222. if((fmtp = tsdp_header_M_get_fmtp(M, "98"))) {
  223. TSK_DEBUG_INFO("FMTP=%s", fmtp);
  224. TSK_FREE(fmtp);
  225. }
  226. }
  227. TSK_OBJECT_SAFE_FREE(message);
  228. }
  229. else {
  230. TSK_DEBUG_ERROR("Failed to parse SDP message.");
  231. }
  232. }
  233. #endif /* _TEST_SDPPARSER_H */