| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 25 |
static char *sdp[] = { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 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 |
|
| 55 |
static 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 |
|
| 92 |
static 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<PJ_ARRAY_SIZE(sdp); ++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 |
|
| 111 |
pj_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 |
|