blob: 9a2e2ffe6d93b81f7ae8ba67f0f40dbb5a12c44f [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include <pjmedia/sdp.h>
21#include <pj/os.h>
22#include <pj/pool.h>
23#include <stdio.h>
24#include <string.h>
25
26static char *sdp[] = {
27 /*
28 "v=0\r\n"
29 "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\r\n"
30 "s=SDP Seminar\r\n"
31 "i=A Seminar on the session description protocol\r\n"
32 "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\r\n"
33 "e=mjh@isi.edu (Mark Handley)\r\n"
34 "c=IN IP4 224.2.17.12/127\r\n"
35 "t=2873397496 2873404696\r\n"
36 "a=recvonly\r\n"
37 "m=audio 49170 RTP/AVP 0\r\n"
38 "m=video 51372 RTP/AVP 31\r\n"
39 "m=application 32416 udp wb\r\n"
40 "a=orient:portrait\r\n"
41 "m=audio 49230 RTP/AVP 96 97 98\r\n"
42 "a=rtpmap:96 L8/8000\r\n"
43 "a=rtpmap:97 L16/8000\r\n"
44 "a=rtpmap:98 L16/11025/2\r\n",
45 */
46 "v=0\r\n"
47 "o=usera 2890844526 2890844527 IN IP4 alice.example.com\r\n"
48 "s=\r\n"
49 "c=IN IP4 alice.example.com\r\n"
50 "t=0 0\r\n"
51 "m=message 7394 msrp/tcp *\r\n"
52 "a=accept-types: message/cpim text/plain text/html\r\n"
53 "a=path:msrp://alice.example.com:7394/2s93i9;tcp\r\n"
54};
55
56static int sdp_perform_test(pj_pool_factory *pf)
57{
58 pj_pool_t *pool;
59 int inputlen, len;
60 pjsdp_session_desc *ses;
61 char buf[1500];
62 enum { LOOP=1000000 };
63 int i;
64 pj_time_val start, end;
65
66 printf("Parsing and printing %d SDP messages..\n", LOOP);
67
68 pool = pj_pool_create(pf, "", 4096, 0, NULL);
69 inputlen = strlen(sdp[0]);
70 pj_gettimeofday(&start);
71 for (i=0; i<LOOP; ++i) {
72 ses = pjsdp_parse(sdp[0], inputlen, pool);
73 len = pjsdp_print(ses, buf, sizeof(buf));
74 buf[len] = '\0';
75 pj_pool_reset(pool);
76 }
77 pj_gettimeofday(&end);
78
79 printf("Original:\n%s\n", sdp[0]);
80 printf("Parsed:\n%s\n", buf);
81
82 PJ_TIME_VAL_SUB(end, start);
83 printf("Time: %ld:%03lds\n", end.sec, end.msec);
84
85 if (end.msec==0 && end.sec==0) end.msec=1;
86 printf("Performance: %ld msg/sec\n", LOOP*1000/PJ_TIME_VAL_MSEC(end));
87 puts("");
88
89 pj_pool_release(pool);
90 return 0;
91}
92
93static int sdp_conform_test(pj_pool_factory *pf)
94{
95 pj_pool_t *pool;
96 pjsdp_session_desc *ses;
97 int i, len;
98 char buf[1500];
99
100 for (i=0; i<sizeof(sdp)/sizeof(sdp[0]); ++i) {
101 pool = pj_pool_create(pf, "sdp", 4096, 0, NULL);
102 ses = pjsdp_parse(sdp[i], strlen(sdp[i]), pool);
103 len = pjsdp_print(ses, buf, sizeof(buf));
104 buf[len] = '\0';
105 printf("%s\n", buf);
106 pj_pool_release(pool);
107 }
108
109 return 0;
110}
111
112pj_status_t sdp_test(pj_pool_factory *pf)
113{
114 if (sdp_conform_test(pf) != 0)
115 return -2;
116
117 if (sdp_perform_test(pf) != 0)
118 return -3;
119
120 return 0;
121}
122