blob: 475ef04f443413670784877e1ee1cd3dbda23556 [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/mediamgr.h>
20#include <pjmedia/session.h>
21#include <pj/sock.h>
22#include <pj/pool.h>
23#include <stdio.h>
24#include <pj/string.h>
25
26pj_status_t session_test (pj_pool_factory *pf)
27{
28 pj_med_mgr_t *mm;
29 pj_media_session_t *s1, *s2;
30 pj_pool_t *pool;
31 pjsdp_session_desc *sdp;
32 pj_media_stream_info sd_info;
33 char buf[1024];
34 int len;
35 pj_media_stream_stat tx_stat, rx_stat;
36
37 pool = pj_pool_create(pf, "test", 4096, 1024, NULL);
38
39 // Init media manager.
40 mm = pj_med_mgr_create ( pf );
41
42 // Create caller session.
43 // THIS WILL DEFINITELY CRASH (NULL as argument)!
44 s1 = pj_media_session_create (mm, NULL);
45
46 // Set caller's media to send-only.
Benny Prijono1519e572006-02-08 22:43:39 +000047 sd_info.dir = PJMEDIA_DIR_ENCODING;
48 pj_media_session_modify_stream (s1, 0, PJMEDIA_STREAM_MODIFY_DIR, &sd_info);
Benny Prijono5dcb38d2005-11-21 01:55:47 +000049
50 // Create caller SDP.
51 sdp = pj_media_session_create_sdp (s1, pool, 0);
52 len = pjsdp_print (sdp, buf, sizeof(buf));
53 buf[len] = '\0';
54 printf("Caller's initial SDP:\n<BEGIN>\n%s\n<END>\n", buf);
55
56 // Parse SDP from caller.
57 sdp = pjsdp_parse (buf, len, pool);
58
59 // Create callee session based on caller's SDP.
60 // THIS WILL DEFINITELY CRASH (NULL as argument)!
61 s2 = pj_media_session_create_from_sdp (mm, sdp, NULL);
62
63 // Create callee SDP
64 sdp = pj_media_session_create_sdp (s2, pool, 0);
65 len = pjsdp_print (sdp, buf, sizeof(buf));
66 buf[len] = '\0';
67 printf("Callee's SDP:\n<BEGIN>\n%s\n<END>\n", buf);
68
69 // Parse SDP from callee.
70 sdp = pjsdp_parse (buf, len, pool);
71
72 // Update caller
73 pj_media_session_update (s1, sdp);
74 sdp = pj_media_session_create_sdp (s1, pool, 0);
75 pjsdp_print (sdp, buf, sizeof(buf));
76 printf("Caller's SDP after update:\n<BEGIN>\n%s\n<END>\n", buf);
77
78 // Now start media.
79 pj_media_session_activate (s2);
80 pj_media_session_activate (s1);
81
82 // Wait
83 for (;;) {
84 int has_stat;
85
86 printf("Enter q to exit, 1 or 2 to print statistics.\n");
87 fgets (buf, 10, stdin);
88 has_stat = 0;
89
90 switch (buf[0]) {
91 case 'q':
92 case 'Q':
93 goto done;
94 break;
95 case '1':
96 pj_media_session_get_stat (s1, 0, &tx_stat, &rx_stat);
97 has_stat = 1;
98 break;
99 case '2':
100 pj_media_session_get_stat (s2, 0, &tx_stat, &rx_stat);
101 has_stat = 1;
102 break;
103 }
104
105 if (has_stat) {
106 pj_media_stream_stat *stat[2] = { &tx_stat, &rx_stat };
107 const char *statname[2] = { "TX", "RX" };
108 int i;
109
110 for (i=0; i<2; ++i) {
111 printf("%s statistics:\n", statname[i]);
112 printf(" Pkt TX=%d RX=%d\n", stat[i]->pkt_tx, stat[i]->pkt_rx);
113 printf(" Octets TX=%d RX=%d\n", stat[i]->oct_tx, stat[i]->oct_rx);
114 printf(" Jitter %d ms\n", stat[i]->jitter);
115 printf(" Pkt lost %d\n", stat[i]->pkt_lost);
116 }
117 printf("\n");
118 }
119 }
120
121done:
122
123 // Done.
124 pj_pool_release (pool);
125 pj_media_session_destroy (s2);
126 pj_media_session_destroy (s1);
127 pj_med_mgr_destroy (mm);
128
129 return 0;
130}