1
/* $Id: pjsua_app_common.c 4537 2013-06-19 06:47:43Z riza $ */
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
21
#include "pjsua_app_common.h"
23
#define THIS_FILE "pjsua_app_common.c"
25
#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
26
# define SOME_BUF_SIZE (1024 * 10)
28
# define SOME_BUF_SIZE (1024 * 3)
31
static char some_buf[SOME_BUF_SIZE];
33
/** Variable definition **/
34
int stdout_refresh = -1;
35
pj_bool_t stdout_refresh_quit = PJ_FALSE;
36
pjsua_call_id current_call = PJSUA_INVALID_ID;
37
pjsua_app_config app_config;
38
pjsua_call_setting call_opt;
39
pjsua_msg_data msg_data;
41
int my_atoi(const char *cs)
48
return 0 - (int)pj_strtoul(&s);
49
} else if (cs[0] == '+') {
51
return pj_strtoul(&s);
53
return pj_strtoul(&s);
58
* Find next call when current call is disconnected or when user
61
pj_bool_t find_next_call()
65
max = pjsua_call_get_max_count();
66
for (i=current_call+1; i<max; ++i) {
67
if (pjsua_call_is_active(i)) {
73
for (i=0; i<current_call; ++i) {
74
if (pjsua_call_is_active(i)) {
80
current_call = PJSUA_INVALID_ID;
84
pj_bool_t find_prev_call()
88
max = pjsua_call_get_max_count();
89
for (i=current_call-1; i>=0; --i) {
90
if (pjsua_call_is_active(i)) {
96
for (i=max-1; i>current_call; --i) {
97
if (pjsua_call_is_active(i)) {
103
current_call = PJSUA_INVALID_ID;
108
* Send arbitrary request to remote host
110
void send_request(char *cstr_method, const pj_str_t *dst_uri)
114
pjsip_tx_data *tdata;
115
pjsip_endpoint *endpt;
118
endpt = pjsua_get_pjsip_endpt();
120
str_method = pj_str(cstr_method);
121
pjsip_method_init_np(&method, &str_method);
123
status = pjsua_acc_create_request(current_acc, &method, dst_uri, &tdata);
125
status = pjsip_endpt_send_request(endpt, tdata, -1, NULL, NULL);
126
if (status != PJ_SUCCESS) {
127
pjsua_perror(THIS_FILE, "Unable to send request", status);
133
* Print log of call states. Since call states may be too long for logger,
134
* printing it is a bit tricky, it should be printed part by part as long
135
* as the logger can accept.
137
void log_call_dump(int call_id)
139
unsigned call_dump_len;
144
pjsua_call_dump(call_id, PJ_TRUE, some_buf, sizeof(some_buf), " ");
145
call_dump_len = (unsigned)strlen(some_buf);
147
log_decor = pj_log_get_decor();
148
pj_log_set_decor(log_decor & ~(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR));
149
PJ_LOG(3,(THIS_FILE, "\n"));
153
part_len = PJ_LOG_MAX_SIZE-80;
154
while (part_idx < call_dump_len) {
157
p = &some_buf[part_idx];
158
if (part_idx + part_len > call_dump_len)
159
part_len = call_dump_len - part_idx;
160
p_orig = p[part_len];
162
PJ_LOG(3,(THIS_FILE, "%s", p));
163
p[part_len] = p_orig;
164
part_idx += part_len;
166
pj_log_set_decor(log_decor);
169
#ifdef PJSUA_HAS_VIDEO
170
void app_config_init_video(pjsua_acc_config *acc_cfg)
172
acc_cfg->vid_in_auto_show = app_config.vid.in_auto_show;
173
acc_cfg->vid_out_auto_transmit = app_config.vid.out_auto_transmit;
174
/* Note that normally GUI application will prefer a borderless
177
acc_cfg->vid_wnd_flags = PJMEDIA_VID_DEV_WND_BORDER |
178
PJMEDIA_VID_DEV_WND_RESIZABLE;
179
acc_cfg->vid_cap_dev = app_config.vid.vcapture_dev;
180
acc_cfg->vid_rend_dev = app_config.vid.vrender_dev;
182
if (app_config.avi_auto_play &&
183
app_config.avi_def_idx != PJSUA_INVALID_ID &&
184
app_config.avi[app_config.avi_def_idx].dev_id != PJMEDIA_VID_INVALID_DEV)
186
acc_cfg->vid_cap_dev = app_config.avi[app_config.avi_def_idx].dev_id;
190
void app_config_init_video(pjsua_acc_config *acc_cfg)
192
PJ_UNUSED_ARG(acc_cfg);
196
#ifdef HAVE_MULTIPART_TEST
198
* Enable multipart in msg_data and add a dummy body into the
201
void add_multipart(pjsua_msg_data *msg_data)
203
static pjsip_multipart_part *alt_part;
206
pj_str_t type, subtype, content;
208
alt_part = pjsip_multipart_create_part(app_config.pool);
210
type = pj_str("text");
211
subtype = pj_str("plain");
212
content = pj_str("Sample text body of a multipart bodies");
213
alt_part->body = pjsip_msg_body_create(app_config.pool, &type,
217
msg_data->multipart_ctype.type = pj_str("multipart");
218
msg_data->multipart_ctype.subtype = pj_str("mixed");
219
pj_list_push_back(&msg_data->multipart_parts, alt_part);
223
/* arrange windows. arg:
224
* -1: arrange all windows
225
* != -1: arrange only this window id
227
void arrange_window(pjsua_vid_win_id wid)
235
last = (wid == PJSUA_INVALID_ID) ? PJSUA_MAX_VID_WINS : wid;
237
for (i=0; i<last; ++i) {
238
pjsua_vid_win_info wi;
241
status = pjsua_vid_win_get_info(i, &wi);
242
if (status != PJ_SUCCESS)
245
if (wid == PJSUA_INVALID_ID)
246
pjsua_vid_win_set_pos(i, &pos);
252
if (wid != PJSUA_INVALID_ID)
253
pjsua_vid_win_set_pos(wid, &pos);
261
void vid_print_dev(int id, const pjmedia_vid_dev_info *vdi, const char *title)
268
if (vdi->dir == PJMEDIA_DIR_CAPTURE_RENDER) {
269
dirname = "capture, render";
270
} else if (vdi->dir == PJMEDIA_DIR_CAPTURE) {
278
for (i=0; i<sizeof(int)*8 && (1 << i) < PJMEDIA_VID_DEV_CAP_MAX; ++i) {
279
if (vdi->caps & (1 << i)) {
280
const char *capname = pjmedia_vid_dev_cap_name(1 << i, NULL);
283
strcat(capnames, ", ");
284
strncat(capnames, capname,
285
sizeof(capnames)-strlen(capnames)-1);
291
for (i=0; i<vdi->fmt_cnt; ++i) {
292
const pjmedia_video_format_info *vfi =
293
pjmedia_get_video_format_info(NULL, vdi->fmt[i].id);
296
strcat(formats, ", ");
297
strncat(formats, vfi->name, sizeof(formats)-strlen(formats)-1);
301
PJ_LOG(3,(THIS_FILE, "%3d %s [%s][%s] %s", id, vdi->name, vdi->driver,
303
PJ_LOG(3,(THIS_FILE, " Supported capabilities: %s", capnames));
304
PJ_LOG(3,(THIS_FILE, " Supported formats: %s", formats));
310
pjmedia_vid_dev_info vdi;
313
PJ_LOG(3,(THIS_FILE, "Video device list:"));
314
count = pjsua_vid_dev_count();
316
PJ_LOG(3,(THIS_FILE, " - no device detected -"));
319
PJ_LOG(3,(THIS_FILE, "%d device(s) detected:", count));
322
status = pjsua_vid_dev_get_info(PJMEDIA_VID_DEFAULT_RENDER_DEV, &vdi);
323
if (status == PJ_SUCCESS)
324
vid_print_dev(PJMEDIA_VID_DEFAULT_RENDER_DEV, &vdi,
325
"(default renderer device)");
327
status = pjsua_vid_dev_get_info(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, &vdi);
328
if (status == PJ_SUCCESS)
329
vid_print_dev(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, &vdi,
330
"(default capture device)");
332
for (i=0; i<count; ++i) {
333
status = pjsua_vid_dev_get_info(i, &vdi);
334
if (status == PJ_SUCCESS)
335
vid_print_dev(i, &vdi, "");
339
void app_config_show_video(int acc_id, const pjsua_acc_config *acc_cfg)
343
" RX auto show: %d\n"
344
" TX auto transmit: %d\n"
348
acc_cfg->vid_in_auto_show,
349
acc_cfg->vid_out_auto_transmit,
350
acc_cfg->vid_cap_dev,
351
acc_cfg->vid_rend_dev));