1
/* $Id: session_test.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#include <pjmedia/mediamgr.h>
21
#include <pjmedia/session.h>
25
#include <pj/string.h>
27
pj_status_t session_test (pj_pool_factory *pf)
30
pj_media_session_t *s1, *s2;
32
pjsdp_session_desc *sdp;
33
pj_media_stream_info sd_info;
36
pj_media_stream_stat tx_stat, rx_stat;
38
pool = pj_pool_create(pf, "test", 4096, 1024, NULL);
40
// Init media manager.
41
mm = pj_med_mgr_create ( pf );
43
// Create caller session.
44
// THIS WILL DEFINITELY CRASH (NULL as argument)!
45
s1 = pj_media_session_create (mm, NULL);
47
// Set caller's media to send-only.
48
sd_info.dir = PJMEDIA_DIR_ENCODING;
49
pj_media_session_modify_stream (s1, 0, PJMEDIA_STREAM_MODIFY_DIR, &sd_info);
52
sdp = pj_media_session_create_sdp (s1, pool, 0);
53
len = pjsdp_print (sdp, buf, sizeof(buf));
55
printf("Caller's initial SDP:\n<BEGIN>\n%s\n<END>\n", buf);
57
// Parse SDP from caller.
58
sdp = pjsdp_parse (buf, len, pool);
60
// Create callee session based on caller's SDP.
61
// THIS WILL DEFINITELY CRASH (NULL as argument)!
62
s2 = pj_media_session_create_from_sdp (mm, sdp, NULL);
65
sdp = pj_media_session_create_sdp (s2, pool, 0);
66
len = pjsdp_print (sdp, buf, sizeof(buf));
68
printf("Callee's SDP:\n<BEGIN>\n%s\n<END>\n", buf);
70
// Parse SDP from callee.
71
sdp = pjsdp_parse (buf, len, pool);
74
pj_media_session_update (s1, sdp);
75
sdp = pj_media_session_create_sdp (s1, pool, 0);
76
pjsdp_print (sdp, buf, sizeof(buf));
77
printf("Caller's SDP after update:\n<BEGIN>\n%s\n<END>\n", buf);
80
pj_media_session_activate (s2);
81
pj_media_session_activate (s1);
87
printf("Enter q to exit, 1 or 2 to print statistics.\n");
88
fgets (buf, 10, stdin);
97
pj_media_session_get_stat (s1, 0, &tx_stat, &rx_stat);
101
pj_media_session_get_stat (s2, 0, &tx_stat, &rx_stat);
107
pj_media_stream_stat *stat[2] = { &tx_stat, &rx_stat };
108
const char *statname[2] = { "TX", "RX" };
111
for (i=0; i<2; ++i) {
112
printf("%s statistics:\n", statname[i]);
113
printf(" Pkt TX=%d RX=%d\n", stat[i]->pkt_tx, stat[i]->pkt_rx);
114
printf(" Octets TX=%d RX=%d\n", stat[i]->oct_tx, stat[i]->oct_rx);
115
printf(" Jitter %d ms\n", stat[i]->jitter);
116
printf(" Pkt lost %d\n", stat[i]->pkt_lost);
125
pj_pool_release (pool);
126
pj_media_session_destroy (s2);
127
pj_media_session_destroy (s1);
128
pj_med_mgr_destroy (mm);