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