BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJSIP Reference

PJSUA

This is the reference implementation for PJSIP and PJMEDIA. PJSUA is a console based application, designed to be simple enough to be readble, but powerful enough to demonstrate all features available in PJSIP and PJMEDIA.

This file is pjsip-apps/src/pjsua/pjsua_app.c

Screenshot on WinXP:

pjsua.jpg
pjsua on WinXP
1 /* $Id: pjsua_app.c 5677 2017-10-27 06:30:50Z ming $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
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.
10  *
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.
15  *
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
19  */
20 #include "pjsua_app.h"
21 
22 #define THIS_FILE "pjsua_app.c"
23 
24 //#define STEREO_DEMO
25 //#define TRANSPORT_ADAPTER_SAMPLE
26 //#define HAVE_MULTIPART_TEST
27 
28 /* Ringtones US UK */
29 #define RINGBACK_FREQ1 440 /* 400 */
30 #define RINGBACK_FREQ2 480 /* 450 */
31 #define RINGBACK_ON 2000 /* 400 */
32 #define RINGBACK_OFF 4000 /* 200 */
33 #define RINGBACK_CNT 1 /* 2 */
34 #define RINGBACK_INTERVAL 4000 /* 2000 */
35 
36 #define RING_FREQ1 800
37 #define RING_FREQ2 640
38 #define RING_ON 200
39 #define RING_OFF 100
40 #define RING_CNT 3
41 #define RING_INTERVAL 3000
42 
43 #define current_acc pjsua_acc_get_default()
44 
45 #ifdef STEREO_DEMO
46 static void stereo_demo();
47 #endif
48 
49 #ifdef USE_GUI
50 pj_bool_t showNotification(pjsua_call_id call_id);
51 #endif
52 
53 static void ringback_start(pjsua_call_id call_id);
54 static void ring_start(pjsua_call_id call_id);
55 static void ring_stop(pjsua_call_id call_id);
56 static pj_status_t app_init();
57 static pj_status_t app_destroy();
58 
59 static pjsua_app_cfg_t app_cfg;
60 pj_str_t uri_arg;
61 pj_bool_t app_running = PJ_FALSE;
62 
63 /*****************************************************************************
64  * Configuration manipulation
65  */
66 
67 /*****************************************************************************
68  * Callback
69  */
70 static void ringback_start(pjsua_call_id call_id)
71 {
72  if (app_config.no_tones)
73  return;
74 
75  if (app_config.call_data[call_id].ringback_on)
76  return;
77 
78  app_config.call_data[call_id].ringback_on = PJ_TRUE;
79 
80  if (++app_config.ringback_cnt==1 &&
81  app_config.ringback_slot!=PJSUA_INVALID_ID)
82  {
83  pjsua_conf_connect(app_config.ringback_slot, 0);
84  }
85 }
86 
87 static void ring_stop(pjsua_call_id call_id)
88 {
89  if (app_config.no_tones)
90  return;
91 
92  if (app_config.call_data[call_id].ringback_on) {
93  app_config.call_data[call_id].ringback_on = PJ_FALSE;
94 
95  pj_assert(app_config.ringback_cnt>0);
96  if (--app_config.ringback_cnt == 0 &&
97  app_config.ringback_slot!=PJSUA_INVALID_ID)
98  {
99  pjsua_conf_disconnect(app_config.ringback_slot, 0);
100  pjmedia_tonegen_rewind(app_config.ringback_port);
101  }
102  }
103 
104  if (app_config.call_data[call_id].ring_on) {
105  app_config.call_data[call_id].ring_on = PJ_FALSE;
106 
107  pj_assert(app_config.ring_cnt>0);
108  if (--app_config.ring_cnt == 0 &&
109  app_config.ring_slot!=PJSUA_INVALID_ID)
110  {
111  pjsua_conf_disconnect(app_config.ring_slot, 0);
112  pjmedia_tonegen_rewind(app_config.ring_port);
113  }
114  }
115 }
116 
117 static void ring_start(pjsua_call_id call_id)
118 {
119  if (app_config.no_tones)
120  return;
121 
122  if (app_config.call_data[call_id].ring_on)
123  return;
124 
125  app_config.call_data[call_id].ring_on = PJ_TRUE;
126 
127  if (++app_config.ring_cnt==1 &&
128  app_config.ring_slot!=PJSUA_INVALID_ID)
129  {
130  pjsua_conf_connect(app_config.ring_slot, 0);
131  }
132 }
133 
134 /* Callback from timer when the maximum call duration has been
135  * exceeded.
136  */
137 static void call_timeout_callback(pj_timer_heap_t *timer_heap,
138  struct pj_timer_entry *entry)
139 {
140  pjsua_call_id call_id = entry->id;
141  pjsua_msg_data msg_data_;
143  pj_str_t hname = pj_str("Warning");
144  pj_str_t hvalue = pj_str("399 pjsua \"Call duration exceeded\"");
145 
146  PJ_UNUSED_ARG(timer_heap);
147 
148  if (call_id == PJSUA_INVALID_ID) {
149  PJ_LOG(1,(THIS_FILE, "Invalid call ID in timer callback"));
150  return;
151  }
152 
153  /* Add warning header */
154  pjsua_msg_data_init(&msg_data_);
155  pjsip_generic_string_hdr_init2(&warn, &hname, &hvalue);
156  pj_list_push_back(&msg_data_.hdr_list, &warn);
157 
158  /* Call duration has been exceeded; disconnect the call */
159  PJ_LOG(3,(THIS_FILE, "Duration (%d seconds) has been exceeded "
160  "for call %d, disconnecting the call",
161  app_config.duration, call_id));
162  entry->id = PJSUA_INVALID_ID;
163  pjsua_call_hangup(call_id, 200, NULL, &msg_data_);
164 }
165 
166 /*
167  * Handler when invite state has changed.
168  */
169 static void on_call_state(pjsua_call_id call_id, pjsip_event *e)
170 {
171  pjsua_call_info call_info;
172 
173  PJ_UNUSED_ARG(e);
174 
175  pjsua_call_get_info(call_id, &call_info);
176 
177  if (call_info.state == PJSIP_INV_STATE_DISCONNECTED) {
178 
179  /* Stop all ringback for this call */
180  ring_stop(call_id);
181 
182  /* Cancel duration timer, if any */
183  if (app_config.call_data[call_id].timer.id != PJSUA_INVALID_ID) {
184  app_call_data *cd = &app_config.call_data[call_id];
186 
187  cd->timer.id = PJSUA_INVALID_ID;
188  pjsip_endpt_cancel_timer(endpt, &cd->timer);
189  }
190 
191  /* Rewind play file when hangup automatically,
192  * since file is not looped
193  */
194  if (app_config.auto_play_hangup)
195  pjsua_player_set_pos(app_config.wav_id, 0);
196 
197 
198  PJ_LOG(3,(THIS_FILE, "Call %d is DISCONNECTED [reason=%d (%s)]",
199  call_id,
200  call_info.last_status,
201  call_info.last_status_text.ptr));
202 
203  if (call_id == current_call) {
204  find_next_call();
205  }
206 
207  /* Dump media state upon disconnected */
208  if (1) {
209  PJ_LOG(5,(THIS_FILE,
210  "Call %d disconnected, dumping media stats..",
211  call_id));
212  log_call_dump(call_id);
213  }
214 
215  } else {
216 
217  if (app_config.duration != PJSUA_APP_NO_LIMIT_DURATION &&
218  call_info.state == PJSIP_INV_STATE_CONFIRMED)
219  {
220  /* Schedule timer to hangup call after the specified duration */
221  app_call_data *cd = &app_config.call_data[call_id];
223  pj_time_val delay;
224 
225  cd->timer.id = call_id;
226  delay.sec = app_config.duration;
227  delay.msec = 0;
228  pjsip_endpt_schedule_timer(endpt, &cd->timer, &delay);
229  }
230 
231  if (call_info.state == PJSIP_INV_STATE_EARLY) {
232  int code;
233  pj_str_t reason;
234  pjsip_msg *msg;
235 
236  /* This can only occur because of TX or RX message */
238 
239  if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) {
240  msg = e->body.tsx_state.src.rdata->msg_info.msg;
241  } else {
242  msg = e->body.tsx_state.src.tdata->msg;
243  }
244 
245  code = msg->line.status.code;
246  reason = msg->line.status.reason;
247 
248  /* Start ringback for 180 for UAC unless there's SDP in 180 */
249  if (call_info.role==PJSIP_ROLE_UAC && code==180 &&
250  msg->body == NULL &&
252  {
253  ringback_start(call_id);
254  }
255 
256  PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s (%d %.*s)",
257  call_id, call_info.state_text.ptr,
258  code, (int)reason.slen, reason.ptr));
259  } else {
260  PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s",
261  call_id,
262  call_info.state_text.ptr));
263  }
264 
265  if (current_call==PJSUA_INVALID_ID)
266  current_call = call_id;
267 
268  }
269 }
270 
274 static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
275  pjsip_rx_data *rdata)
276 {
277  pjsua_call_info call_info;
278 
279  PJ_UNUSED_ARG(acc_id);
280  PJ_UNUSED_ARG(rdata);
281 
282  pjsua_call_get_info(call_id, &call_info);
283 
284  if (current_call==PJSUA_INVALID_ID)
285  current_call = call_id;
286 
287 #ifdef USE_GUI
288  if (!showNotification(call_id))
289  return;
290 #endif
291 
292  /* Start ringback */
293  ring_start(call_id);
294 
295  if (app_config.auto_answer > 0) {
296  pjsua_call_setting opt;
297 
299  opt.aud_cnt = app_config.aud_cnt;
300  opt.vid_cnt = app_config.vid.vid_cnt;
301 
302  pjsua_call_answer2(call_id, &opt, app_config.auto_answer, NULL,
303  NULL);
304  }
305 
306  if (app_config.auto_answer < 200) {
307  char notif_st[80] = {0};
308 
309 #if PJSUA_HAS_VIDEO
310  if (call_info.rem_offerer && call_info.rem_vid_cnt) {
311  snprintf(notif_st, sizeof(notif_st),
312  "To %s the video, type \"vid %s\" first, "
313  "before answering the call!\n",
314  (app_config.vid.vid_cnt? "reject":"accept"),
315  (app_config.vid.vid_cnt? "disable":"enable"));
316  }
317 #endif
318 
319  PJ_LOG(3,(THIS_FILE,
320  "Incoming call for account %d!\n"
321  "Media count: %d audio & %d video\n"
322  "%s"
323  "From: %s\n"
324  "To: %s\n"
325  "Press %s to answer or %s to reject call",
326  acc_id,
327  call_info.rem_aud_cnt,
328  call_info.rem_vid_cnt,
329  notif_st,
330  call_info.remote_info.ptr,
331  call_info.local_info.ptr,
332  (app_config.use_cli?"ca a":"a"),
333  (app_config.use_cli?"g":"h")));
334  }
335 }
336 
337 /*
338  * Handler when a transaction within a call has changed state.
339  */
340 static void on_call_tsx_state(pjsua_call_id call_id,
341  pjsip_transaction *tsx,
342  pjsip_event *e)
343 {
344  const pjsip_method info_method =
345  {
347  { "INFO", 4 }
348  };
349 
350  if (pjsip_method_cmp(&tsx->method, &info_method)==0) {
351  /*
352  * Handle INFO method.
353  */
354  const pj_str_t STR_APPLICATION = { "application", 11};
355  const pj_str_t STR_DTMF_RELAY = { "dtmf-relay", 10 };
356  pjsip_msg_body *body = NULL;
357  pj_bool_t dtmf_info = PJ_FALSE;
358 
359  if (tsx->role == PJSIP_ROLE_UAC) {
360  if (e->body.tsx_state.type == PJSIP_EVENT_TX_MSG)
361  body = e->body.tsx_state.src.tdata->msg->body;
362  else
363  body = e->body.tsx_state.tsx->last_tx->msg->body;
364  } else {
365  if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG)
366  body = e->body.tsx_state.src.rdata->msg_info.msg->body;
367  }
368 
369  /* Check DTMF content in the INFO message */
370  if (body && body->len &&
371  pj_stricmp(&body->content_type.type, &STR_APPLICATION)==0 &&
372  pj_stricmp(&body->content_type.subtype, &STR_DTMF_RELAY)==0)
373  {
374  dtmf_info = PJ_TRUE;
375  }
376 
377  if (dtmf_info && tsx->role == PJSIP_ROLE_UAC &&
378  (tsx->state == PJSIP_TSX_STATE_COMPLETED ||
380  e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED)))
381  {
382  /* Status of outgoing INFO request */
383  if (tsx->status_code >= 200 && tsx->status_code < 300) {
384  PJ_LOG(4,(THIS_FILE,
385  "Call %d: DTMF sent successfully with INFO",
386  call_id));
387  } else if (tsx->status_code >= 300) {
388  PJ_LOG(4,(THIS_FILE,
389  "Call %d: Failed to send DTMF with INFO: %d/%.*s",
390  call_id,
391  tsx->status_code,
392  (int)tsx->status_text.slen,
393  tsx->status_text.ptr));
394  }
395  } else if (dtmf_info && tsx->role == PJSIP_ROLE_UAS &&
397  {
398  /* Answer incoming INFO with 200/OK */
399  pjsip_rx_data *rdata;
400  pjsip_tx_data *tdata;
401  pj_status_t status;
402 
403  rdata = e->body.tsx_state.src.rdata;
404 
405  if (rdata->msg_info.msg->body) {
406  status = pjsip_endpt_create_response(tsx->endpt, rdata,
407  200, NULL, &tdata);
408  if (status == PJ_SUCCESS)
409  status = pjsip_tsx_send_msg(tsx, tdata);
410 
411  PJ_LOG(3,(THIS_FILE, "Call %d: incoming INFO:\n%.*s",
412  call_id,
413  (int)rdata->msg_info.msg->body->len,
414  rdata->msg_info.msg->body->data));
415  } else {
416  status = pjsip_endpt_create_response(tsx->endpt, rdata,
417  400, NULL, &tdata);
418  if (status == PJ_SUCCESS)
419  status = pjsip_tsx_send_msg(tsx, tdata);
420  }
421  }
422  }
423 }
424 
425 /* General processing for media state. "mi" is the media index */
426 static void on_call_generic_media_state(pjsua_call_info *ci, unsigned mi,
427  pj_bool_t *has_error)
428 {
429  const char *status_name[] = {
430  "None",
431  "Active",
432  "Local hold",
433  "Remote hold",
434  "Error"
435  };
436 
437  PJ_UNUSED_ARG(has_error);
438 
439  pj_assert(ci->media[mi].status <= PJ_ARRAY_SIZE(status_name));
441 
442  PJ_LOG(4,(THIS_FILE, "Call %d media %d [type=%s], status is %s",
443  ci->id, mi, pjmedia_type_name(ci->media[mi].type),
444  status_name[ci->media[mi].status]));
445 }
446 
447 /* Process audio media state. "mi" is the media index. */
448 static void on_call_audio_state(pjsua_call_info *ci, unsigned mi,
449  pj_bool_t *has_error)
450 {
451  PJ_UNUSED_ARG(has_error);
452 
453  /* Stop ringback */
454  ring_stop(ci->id);
455 
456  /* Connect ports appropriately when media status is ACTIVE or REMOTE HOLD,
457  * otherwise we should NOT connect the ports.
458  */
459  if (ci->media[mi].status == PJSUA_CALL_MEDIA_ACTIVE ||
461  {
462  pj_bool_t connect_sound = PJ_TRUE;
463  pj_bool_t disconnect_mic = PJ_FALSE;
464  pjsua_conf_port_id call_conf_slot;
465 
466  call_conf_slot = ci->media[mi].stream.aud.conf_slot;
467 
468  /* Loopback sound, if desired */
469  if (app_config.auto_loop) {
470  pjsua_conf_connect(call_conf_slot, call_conf_slot);
471  connect_sound = PJ_FALSE;
472  }
473 
474  /* Automatically record conversation, if desired */
475  if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) {
476  pjsua_conf_connect(call_conf_slot, app_config.rec_port);
477  }
478 
479  /* Stream a file, if desired */
480  if ((app_config.auto_play || app_config.auto_play_hangup) &&
481  app_config.wav_port != PJSUA_INVALID_ID)
482  {
483  pjsua_conf_connect(app_config.wav_port, call_conf_slot);
484  connect_sound = PJ_FALSE;
485  }
486 
487  /* Stream AVI, if desired */
488  if (app_config.avi_auto_play &&
489  app_config.avi_def_idx != PJSUA_INVALID_ID &&
490  app_config.avi[app_config.avi_def_idx].slot != PJSUA_INVALID_ID)
491  {
492  pjsua_conf_connect(app_config.avi[app_config.avi_def_idx].slot,
493  call_conf_slot);
494  disconnect_mic = PJ_TRUE;
495  }
496 
497  /* Put call in conference with other calls, if desired */
498  if (app_config.auto_conf) {
499  pjsua_call_id call_ids[PJSUA_MAX_CALLS];
500  unsigned call_cnt=PJ_ARRAY_SIZE(call_ids);
501  unsigned i;
502 
503  /* Get all calls, and establish media connection between
504  * this call and other calls.
505  */
506  pjsua_enum_calls(call_ids, &call_cnt);
507 
508  for (i=0; i<call_cnt; ++i) {
509  if (call_ids[i] == ci->id)
510  continue;
511 
512  if (!pjsua_call_has_media(call_ids[i]))
513  continue;
514 
515  pjsua_conf_connect(call_conf_slot,
516  pjsua_call_get_conf_port(call_ids[i]));
518  call_conf_slot);
519 
520  /* Automatically record conversation, if desired */
521  if (app_config.auto_rec && app_config.rec_port !=
522  PJSUA_INVALID_ID)
523  {
525  app_config.rec_port);
526  }
527 
528  }
529 
530  /* Also connect call to local sound device */
531  connect_sound = PJ_TRUE;
532  }
533 
534  /* Otherwise connect to sound device */
535  if (connect_sound) {
536  pjsua_conf_connect(call_conf_slot, 0);
537  if (!disconnect_mic)
538  pjsua_conf_connect(0, call_conf_slot);
539 
540  /* Automatically record conversation, if desired */
541  if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID)
542  {
543  pjsua_conf_connect(call_conf_slot, app_config.rec_port);
544  pjsua_conf_connect(0, app_config.rec_port);
545  }
546  }
547  }
548 }
549 
550 /* Process video media state. "mi" is the media index. */
551 static void on_call_video_state(pjsua_call_info *ci, unsigned mi,
552  pj_bool_t *has_error)
553 {
555  return;
556 
557  arrange_window(ci->media[mi].stream.vid.win_in);
558 
559  PJ_UNUSED_ARG(has_error);
560 }
561 
562 /*
563  * Callback on media state changed event.
564  * The action may connect the call to sound device, to file, or
565  * to loop the call.
566  */
567 static void on_call_media_state(pjsua_call_id call_id)
568 {
569  pjsua_call_info call_info;
570  unsigned mi;
571  pj_bool_t has_error = PJ_FALSE;
572 
573  pjsua_call_get_info(call_id, &call_info);
574 
575  for (mi=0; mi<call_info.media_cnt; ++mi) {
576  on_call_generic_media_state(&call_info, mi, &has_error);
577 
578  switch (call_info.media[mi].type) {
579  case PJMEDIA_TYPE_AUDIO:
580  on_call_audio_state(&call_info, mi, &has_error);
581  break;
582  case PJMEDIA_TYPE_VIDEO:
583  on_call_video_state(&call_info, mi, &has_error);
584  break;
585  default:
586  /* Make gcc happy about enum not handled by switch/case */
587  break;
588  }
589  }
590 
591  if (has_error) {
592  pj_str_t reason = pj_str("Media failed");
593  pjsua_call_hangup(call_id, 500, &reason, NULL);
594  }
595 
596 #if PJSUA_HAS_VIDEO
597  /* Check if remote has just tried to enable video */
598  if (call_info.rem_offerer && call_info.rem_vid_cnt)
599  {
600  int vid_idx;
601 
602  /* Check if there is active video */
603  vid_idx = pjsua_call_get_vid_stream_idx(call_id);
604  if (vid_idx == -1 || call_info.media[vid_idx].dir == PJMEDIA_DIR_NONE) {
605  PJ_LOG(3,(THIS_FILE,
606  "Just rejected incoming video offer on call %d, "
607  "use \"vid call enable %d\" or \"vid call add\" to "
608  "enable video!", call_id, vid_idx));
609  }
610  }
611 #endif
612 }
613 
614 /*
615  * DTMF callback.
616  */
617 static void call_on_dtmf_callback(pjsua_call_id call_id, int dtmf)
618 {
619  PJ_LOG(3,(THIS_FILE, "Incoming DTMF on call %d: %c", call_id, dtmf));
620 }
621 
622 /*
623  * Redirection handler.
624  */
625 static pjsip_redirect_op call_on_redirected(pjsua_call_id call_id,
626  const pjsip_uri *target,
627  const pjsip_event *e)
628 {
629  PJ_UNUSED_ARG(e);
630 
631  if (app_config.redir_op == PJSIP_REDIRECT_PENDING) {
632  char uristr[PJSIP_MAX_URL_SIZE];
633  int len;
634 
635  len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, target, uristr,
636  sizeof(uristr));
637  if (len < 1) {
638  pj_ansi_strcpy(uristr, "--URI too long--");
639  }
640 
641  PJ_LOG(3,(THIS_FILE, "Call %d is being redirected to %.*s. "
642  "Press 'Ra' to accept+replace To header, 'RA' to accept, "
643  "'Rr' to reject, or 'Rd' to disconnect.",
644  call_id, len, uristr));
645  }
646 
647  return app_config.redir_op;
648 }
649 
650 /*
651  * Handler registration status has changed.
652  */
653 static void on_reg_state(pjsua_acc_id acc_id)
654 {
655  PJ_UNUSED_ARG(acc_id);
656 
657  // Log already written.
658 }
659 
660 /*
661  * Handler for incoming presence subscription request
662  */
663 static void on_incoming_subscribe(pjsua_acc_id acc_id,
664  pjsua_srv_pres *srv_pres,
665  pjsua_buddy_id buddy_id,
666  const pj_str_t *from,
667  pjsip_rx_data *rdata,
668  pjsip_status_code *code,
669  pj_str_t *reason,
670  pjsua_msg_data *msg_data_)
671 {
672  /* Just accept the request (the default behavior) */
673  PJ_UNUSED_ARG(acc_id);
674  PJ_UNUSED_ARG(srv_pres);
675  PJ_UNUSED_ARG(buddy_id);
676  PJ_UNUSED_ARG(from);
677  PJ_UNUSED_ARG(rdata);
678  PJ_UNUSED_ARG(code);
679  PJ_UNUSED_ARG(reason);
680  PJ_UNUSED_ARG(msg_data_);
681 }
682 
683 
684 /*
685  * Handler on buddy state changed.
686  */
687 static void on_buddy_state(pjsua_buddy_id buddy_id)
688 {
690  pjsua_buddy_get_info(buddy_id, &info);
691 
692  PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s, subscription state is %s "
693  "(last termination reason code=%d %.*s)",
694  (int)info.uri.slen,
695  info.uri.ptr,
696  (int)info.status_text.slen,
697  info.status_text.ptr,
698  info.sub_state_name,
699  info.sub_term_code,
700  (int)info.sub_term_reason.slen,
701  info.sub_term_reason.ptr));
702 }
703 
704 
705 /*
706  * Subscription state has changed.
707  */
708 static void on_buddy_evsub_state(pjsua_buddy_id buddy_id,
709  pjsip_evsub *sub,
710  pjsip_event *event)
711 {
712  char event_info[80];
713 
714  PJ_UNUSED_ARG(sub);
715 
716  event_info[0] = '\0';
717 
718  if (event->type == PJSIP_EVENT_TSX_STATE &&
719  event->body.tsx_state.type == PJSIP_EVENT_RX_MSG)
720  {
721  pjsip_rx_data *rdata = event->body.tsx_state.src.rdata;
722  snprintf(event_info, sizeof(event_info),
723  " (RX %s)",
724  pjsip_rx_data_get_info(rdata));
725  }
726 
727  PJ_LOG(4,(THIS_FILE,
728  "Buddy %d: subscription state: %s (event: %s%s)",
729  buddy_id, pjsip_evsub_get_state_name(sub),
730  pjsip_event_str(event->type),
731  event_info));
732 
733 }
734 
735 
739 static void on_pager(pjsua_call_id call_id, const pj_str_t *from,
740  const pj_str_t *to, const pj_str_t *contact,
741  const pj_str_t *mime_type, const pj_str_t *text)
742 {
743  /* Note: call index may be -1 */
744  PJ_UNUSED_ARG(call_id);
745  PJ_UNUSED_ARG(to);
746  PJ_UNUSED_ARG(contact);
747  PJ_UNUSED_ARG(mime_type);
748 
749  PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s (%.*s)",
750  (int)from->slen, from->ptr,
751  (int)text->slen, text->ptr,
752  (int)mime_type->slen, mime_type->ptr));
753 }
754 
755 
759 static void on_typing(pjsua_call_id call_id, const pj_str_t *from,
760  const pj_str_t *to, const pj_str_t *contact,
761  pj_bool_t is_typing)
762 {
763  PJ_UNUSED_ARG(call_id);
764  PJ_UNUSED_ARG(to);
765  PJ_UNUSED_ARG(contact);
766 
767  PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s",
768  (int)from->slen, from->ptr,
769  (is_typing?"is typing..":"has stopped typing")));
770 }
771 
772 
776 static void on_call_transfer_status(pjsua_call_id call_id,
777  int status_code,
778  const pj_str_t *status_text,
779  pj_bool_t final,
780  pj_bool_t *p_cont)
781 {
782  PJ_LOG(3,(THIS_FILE, "Call %d: transfer status=%d (%.*s) %s",
783  call_id, status_code,
784  (int)status_text->slen, status_text->ptr,
785  (final ? "[final]" : "")));
786 
787  if (status_code/100 == 2) {
788  PJ_LOG(3,(THIS_FILE,
789  "Call %d: call transferred successfully, disconnecting call",
790  call_id));
791  pjsua_call_hangup(call_id, PJSIP_SC_GONE, NULL, NULL);
792  *p_cont = PJ_FALSE;
793  }
794 }
795 
796 
797 /*
798  * Notification that call is being replaced.
799  */
800 static void on_call_replaced(pjsua_call_id old_call_id,
801  pjsua_call_id new_call_id)
802 {
803  pjsua_call_info old_ci, new_ci;
804 
805  pjsua_call_get_info(old_call_id, &old_ci);
806  pjsua_call_get_info(new_call_id, &new_ci);
807 
808  PJ_LOG(3,(THIS_FILE, "Call %d with %.*s is being replaced by "
809  "call %d with %.*s",
810  old_call_id,
811  (int)old_ci.remote_info.slen, old_ci.remote_info.ptr,
812  new_call_id,
813  (int)new_ci.remote_info.slen, new_ci.remote_info.ptr));
814 }
815 
816 
817 /*
818  * NAT type detection callback.
819  */
820 static void on_nat_detect(const pj_stun_nat_detect_result *res)
821 {
822  if (res->status != PJ_SUCCESS) {
823  pjsua_perror(THIS_FILE, "NAT detection failed", res->status);
824  } else {
825  PJ_LOG(3, (THIS_FILE, "NAT detected as %s", res->nat_type_name));
826  }
827 }
828 
829 
830 /*
831  * MWI indication
832  */
833 static void on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info)
834 {
835  pj_str_t body;
836 
837  PJ_LOG(3,(THIS_FILE, "Received MWI for acc %d:", acc_id));
838 
839  if (mwi_info->rdata->msg_info.ctype) {
840  const pjsip_ctype_hdr *ctype = mwi_info->rdata->msg_info.ctype;
841 
842  PJ_LOG(3,(THIS_FILE, " Content-Type: %.*s/%.*s",
843  (int)ctype->media.type.slen,
844  ctype->media.type.ptr,
845  (int)ctype->media.subtype.slen,
846  ctype->media.subtype.ptr));
847  }
848 
849  if (!mwi_info->rdata->msg_info.msg->body) {
850  PJ_LOG(3,(THIS_FILE, " no message body"));
851  return;
852  }
853 
854  body.ptr = (char *)mwi_info->rdata->msg_info.msg->body->data;
855  body.slen = mwi_info->rdata->msg_info.msg->body->len;
856 
857  PJ_LOG(3,(THIS_FILE, " Body:\n%.*s", (int)body.slen, body.ptr));
858 }
859 
860 
861 /*
862  * Transport status notification
863  */
864 static void on_transport_state(pjsip_transport *tp,
865  pjsip_transport_state state,
866  const pjsip_transport_state_info *info)
867 {
868  char host_port[128];
869 
870  pj_ansi_snprintf(host_port, sizeof(host_port), "[%.*s:%d]",
871  (int)tp->remote_name.host.slen,
872  tp->remote_name.host.ptr,
873  tp->remote_name.port);
874 
875  switch (state) {
877  {
878  PJ_LOG(3,(THIS_FILE, "SIP %s transport is connected to %s",
879  tp->type_name, host_port));
880  }
881  break;
882 
884  {
885  char buf[100];
886 
887  snprintf(buf, sizeof(buf), "SIP %s transport is disconnected "
888  "from %s", tp->type_name, host_port);
889  pjsua_perror(THIS_FILE, buf, info->status);
890  }
891  break;
892 
893  default:
894  break;
895  }
896 
897 #if defined(PJSIP_HAS_TLS_TRANSPORT) && PJSIP_HAS_TLS_TRANSPORT!=0
898 
899  if (!pj_ansi_stricmp(tp->type_name, "tls") && info->ext_info &&
900  (state == PJSIP_TP_STATE_CONNECTED ||
901  ((pjsip_tls_state_info*)info->ext_info)->
902  ssl_sock_info->verify_status != PJ_SUCCESS))
903  {
905  pj_ssl_sock_info *ssl_sock_info = tls_info->ssl_sock_info;
906  char buf[2048];
907  const char *verif_msgs[32];
908  unsigned verif_msg_cnt;
909 
910  /* Dump server TLS cipher */
911  PJ_LOG(4,(THIS_FILE, "TLS cipher used: 0x%06X/%s",
912  ssl_sock_info->cipher,
913  pj_ssl_cipher_name(ssl_sock_info->cipher) ));
914 
915  /* Dump server TLS certificate */
916  pj_ssl_cert_info_dump(ssl_sock_info->remote_cert_info, " ",
917  buf, sizeof(buf));
918  PJ_LOG(4,(THIS_FILE, "TLS cert info of %s:\n%s", host_port, buf));
919 
920  /* Dump server TLS certificate verification result */
921  verif_msg_cnt = PJ_ARRAY_SIZE(verif_msgs);
922  pj_ssl_cert_get_verify_status_strings(ssl_sock_info->verify_status,
923  verif_msgs, &verif_msg_cnt);
924  PJ_LOG(3,(THIS_FILE, "TLS cert verification result of %s : %s",
925  host_port,
926  (verif_msg_cnt == 1? verif_msgs[0]:"")));
927  if (verif_msg_cnt > 1) {
928  unsigned i;
929  for (i = 0; i < verif_msg_cnt; ++i)
930  PJ_LOG(3,(THIS_FILE, "- %s", verif_msgs[i]));
931  }
932 
933  if (ssl_sock_info->verify_status &&
934  !app_config.udp_cfg.tls_setting.verify_server)
935  {
936  PJ_LOG(3,(THIS_FILE, "PJSUA is configured to ignore TLS cert "
937  "verification errors"));
938  }
939  }
940 
941 #endif
942 
943 }
944 
945 /*
946  * Notification on ICE error.
947  */
948 static void on_ice_transport_error(int index, pj_ice_strans_op op,
949  pj_status_t status, void *param)
950 {
951  PJ_UNUSED_ARG(op);
952  PJ_UNUSED_ARG(param);
953  PJ_PERROR(1,(THIS_FILE, status,
954  "ICE keep alive failure for transport %d", index));
955 }
956 
957 /*
958  * Notification on sound device operation.
959  */
960 static pj_status_t on_snd_dev_operation(int operation)
961 {
962  int cap_dev, play_dev;
963 
964  pjsua_get_snd_dev(&cap_dev, &play_dev);
965  PJ_LOG(3,(THIS_FILE, "Turning sound device %d %d %s", cap_dev, play_dev,
966  (operation? "ON":"OFF")));
967  return PJ_SUCCESS;
968 }
969 
970 /* Callback on media events */
971 static void on_call_media_event(pjsua_call_id call_id,
972  unsigned med_idx,
973  pjmedia_event *event)
974 {
975  char event_name[5];
976 
977  PJ_LOG(5,(THIS_FILE, "Event %s",
978  pjmedia_fourcc_name(event->type, event_name)));
979 
980 #if PJSUA_HAS_VIDEO
981  if (event->type == PJMEDIA_EVENT_FMT_CHANGED) {
982  /* Adjust renderer window size to original video size */
983  pjsua_call_info ci;
984 
985  pjsua_call_get_info(call_id, &ci);
986 
987  if ((ci.media[med_idx].type == PJMEDIA_TYPE_VIDEO) &&
988  (ci.media[med_idx].dir & PJMEDIA_DIR_DECODING))
989  {
990  pjsua_vid_win_id wid;
991  pjmedia_rect_size size;
992  pjsua_vid_win_info win_info;
993 
994  wid = ci.media[med_idx].stream.vid.win_in;
995  pjsua_vid_win_get_info(wid, &win_info);
996 
997  size = event->data.fmt_changed.new_fmt.det.vid.size;
998  if (size.w != win_info.size.w || size.h != win_info.size.h) {
999  pjsua_vid_win_set_size(wid, &size);
1000 
1001  /* Re-arrange video windows */
1002  arrange_window(PJSUA_INVALID_ID);
1003  }
1004  }
1005  }
1006 #else
1007  PJ_UNUSED_ARG(call_id);
1008  PJ_UNUSED_ARG(med_idx);
1009  PJ_UNUSED_ARG(event);
1010 #endif
1011 }
1012 
1013 #ifdef TRANSPORT_ADAPTER_SAMPLE
1014 /*
1015  * This callback is called when media transport needs to be created.
1016  */
1017 static pjmedia_transport* on_create_media_transport(pjsua_call_id call_id,
1018  unsigned media_idx,
1019  pjmedia_transport *base_tp,
1020  unsigned flags)
1021 {
1022  pjmedia_transport *adapter;
1023  pj_status_t status;
1024 
1025  /* Create the adapter */
1027  NULL, base_tp,
1028  (flags & PJSUA_MED_TP_CLOSE_MEMBER),
1029  &adapter);
1030  if (status != PJ_SUCCESS) {
1031  PJ_PERROR(1,(THIS_FILE, status, "Error creating adapter"));
1032  return NULL;
1033  }
1034 
1035  PJ_LOG(3,(THIS_FILE, "Media transport is created for call %d media %d",
1036  call_id, media_idx));
1037 
1038  return adapter;
1039 }
1040 #endif
1041 
1042 /* Playfile done notification, set timer to hangup calls */
1043 pj_status_t on_playfile_done(pjmedia_port *port, void *usr_data)
1044 {
1045  pj_time_val delay;
1046 
1047  PJ_UNUSED_ARG(port);
1048  PJ_UNUSED_ARG(usr_data);
1049 
1050  /* Just rewind WAV when it is played outside of call */
1051  if (pjsua_call_get_count() == 0) {
1052  pjsua_player_set_pos(app_config.wav_id, 0);
1053  return PJ_SUCCESS;
1054  }
1055 
1056  /* Timer is already active */
1057  if (app_config.auto_hangup_timer.id == 1)
1058  return PJ_SUCCESS;
1059 
1060  app_config.auto_hangup_timer.id = 1;
1061  delay.sec = 0;
1062  delay.msec = 200; /* Give 200 ms before hangup */
1064  &app_config.auto_hangup_timer,
1065  &delay);
1066 
1067  return PJ_SUCCESS;
1068 }
1069 
1070 /* Auto hangup timer callback */
1071 static void hangup_timeout_callback(pj_timer_heap_t *timer_heap,
1072  struct pj_timer_entry *entry)
1073 {
1074  PJ_UNUSED_ARG(timer_heap);
1075  PJ_UNUSED_ARG(entry);
1076 
1077  app_config.auto_hangup_timer.id = 0;
1079 }
1080 
1081 /*
1082  * A simple registrar, invoked by default_mod_on_rx_request()
1083  */
1084 static void simple_registrar(pjsip_rx_data *rdata)
1085 {
1086  pjsip_tx_data *tdata;
1087  const pjsip_expires_hdr *exp;
1088  const pjsip_hdr *h;
1089  unsigned cnt = 0;
1091  pj_status_t status;
1092 
1094  rdata, 200, NULL, &tdata);
1095  if (status != PJ_SUCCESS)
1096  return;
1097 
1099  PJSIP_H_EXPIRES, NULL);
1100 
1101  h = rdata->msg_info.msg->hdr.next;
1102  while (h != &rdata->msg_info.msg->hdr) {
1103  if (h->type == PJSIP_H_CONTACT) {
1104  const pjsip_contact_hdr *c = (const pjsip_contact_hdr*)h;
1105  int e = c->expires;
1106 
1107  if (e < 0) {
1108  if (exp)
1109  e = exp->ivalue;
1110  else
1111  e = 3600;
1112  }
1113 
1114  if (e > 0) {
1116  tdata->pool, h);
1117  nc->expires = e;
1118  pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)nc);
1119  ++cnt;
1120  }
1121  }
1122  h = h->next;
1123  }
1124 
1125  srv = pjsip_generic_string_hdr_create(tdata->pool, NULL, NULL);
1126  srv->name = pj_str("Server");
1127  srv->hvalue = pj_str("pjsua simple registrar");
1128  pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)srv);
1129 
1131  rdata, tdata, NULL, NULL);
1132 }
1133 
1134 /*****************************************************************************
1135  * A simple module to handle otherwise unhandled request. We will register
1136  * this with the lowest priority.
1137  */
1138 
1139 /* Notification on incoming request */
1140 static pj_bool_t default_mod_on_rx_request(pjsip_rx_data *rdata)
1141 {
1142  pjsip_tx_data *tdata;
1143  pjsip_status_code status_code;
1144  pj_status_t status;
1145 
1146  /* Don't respond to ACK! */
1147  if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,
1148  &pjsip_ack_method) == 0)
1149  return PJ_TRUE;
1150 
1151  /* Simple registrar */
1152  if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,
1153  &pjsip_register_method) == 0)
1154  {
1155  simple_registrar(rdata);
1156  return PJ_TRUE;
1157  }
1158 
1159  /* Create basic response. */
1160  if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,
1161  &pjsip_notify_method) == 0)
1162  {
1163  /* Unsolicited NOTIFY's, send with Bad Request */
1164  status_code = PJSIP_SC_BAD_REQUEST;
1165  } else {
1166  /* Probably unknown method */
1167  status_code = PJSIP_SC_METHOD_NOT_ALLOWED;
1168  }
1170  rdata, status_code,
1171  NULL, &tdata);
1172  if (status != PJ_SUCCESS) {
1173  pjsua_perror(THIS_FILE, "Unable to create response", status);
1174  return PJ_TRUE;
1175  }
1176 
1177  /* Add Allow if we're responding with 405 */
1178  if (status_code == PJSIP_SC_METHOD_NOT_ALLOWED) {
1179  const pjsip_hdr *cap_hdr;
1181  PJSIP_H_ALLOW, NULL);
1182  if (cap_hdr) {
1184  tdata->pool, cap_hdr));
1185  }
1186  }
1187 
1188  /* Add User-Agent header */
1189  {
1190  pj_str_t user_agent;
1191  char tmp[80];
1192  const pj_str_t USER_AGENT = { "User-Agent", 10};
1193  pjsip_hdr *h;
1194 
1195  pj_ansi_snprintf(tmp, sizeof(tmp), "PJSUA v%s/%s",
1196  pj_get_version(), PJ_OS_NAME);
1197  pj_strdup2_with_null(tdata->pool, &user_agent, tmp);
1198 
1200  &USER_AGENT,
1201  &user_agent);
1202  pjsip_msg_add_hdr(tdata->msg, h);
1203  }
1204 
1206  NULL, NULL);
1207 
1208  return PJ_TRUE;
1209 }
1210 
1211 /* The module instance. */
1212 static pjsip_module mod_default_handler =
1213 {
1214  NULL, NULL, /* prev, next. */
1215  { "mod-default-handler", 19 }, /* Name. */
1216  -1, /* Id */
1217  PJSIP_MOD_PRIORITY_APPLICATION+99, /* Priority */
1218  NULL, /* load() */
1219  NULL, /* start() */
1220  NULL, /* stop() */
1221  NULL, /* unload() */
1222  &default_mod_on_rx_request, /* on_rx_request() */
1223  NULL, /* on_rx_response() */
1224  NULL, /* on_tx_request. */
1225  NULL, /* on_tx_response() */
1226  NULL, /* on_tsx_state() */
1227 
1228 };
1229 
1232 /* Called on CLI (re)started, e.g: initial start, after iOS bg */
1233 void cli_on_started(pj_status_t status)
1234 {
1235  /* Notify app */
1236  if (app_cfg.on_started) {
1237  if (status == PJ_SUCCESS) {
1238  char info[128];
1239  cli_get_info(info, sizeof(info));
1240  if (app_cfg.on_started) {
1241  (*app_cfg.on_started)(status, info);
1242  }
1243  } else {
1244  if (app_cfg.on_started) {
1245  (*app_cfg.on_started)(status, NULL);
1246  }
1247  }
1248  }
1249 }
1250 
1251 /* Called on CLI quit */
1252 void cli_on_stopped(pj_bool_t restart, int argc, char* argv[])
1253 {
1254  /* Notify app */
1255  if (app_cfg.on_stopped)
1256  (*app_cfg.on_stopped)(restart, argc, argv);
1257 }
1258 
1259 
1260 /* Called on pjsua legacy quit */
1261 void legacy_on_stopped(pj_bool_t restart)
1262 {
1263  /* Notify app */
1264  if (app_cfg.on_stopped)
1265  (*app_cfg.on_stopped)(restart, 1, NULL);
1266 }
1267 
1268 /*****************************************************************************
1269  * Public API
1270  */
1271 
1272 int stdout_refresh_proc(void *arg)
1273 {
1274  extern char *stdout_refresh_text;
1275 
1276  PJ_UNUSED_ARG(arg);
1277 
1278  /* Set thread to lowest priority so that it doesn't clobber
1279  * stdout output
1280  */
1283 
1284  while (!stdout_refresh_quit) {
1285  pj_thread_sleep(stdout_refresh * 1000);
1286  puts(stdout_refresh_text);
1287  fflush(stdout);
1288  }
1289 
1290  return 0;
1291 }
1292 
1293 static pj_status_t app_init()
1294 {
1295  pjsua_transport_id transport_id = -1;
1296  pjsua_transport_config tcp_cfg;
1297  unsigned i;
1298  pj_pool_t *tmp_pool;
1299  pj_status_t status;
1300 
1302  status = pjsua_create();
1303  if (status != PJ_SUCCESS)
1304  return status;
1305 
1306  /* Create pool for application */
1307  app_config.pool = pjsua_pool_create("pjsua-app", 1000, 1000);
1308  tmp_pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);;
1309 
1310  /* Init CLI & its FE settings */
1311  if (!app_running) {
1312  pj_cli_cfg_default(&app_config.cli_cfg.cfg);
1313  pj_cli_telnet_cfg_default(&app_config.cli_cfg.telnet_cfg);
1314  pj_cli_console_cfg_default(&app_config.cli_cfg.console_cfg);
1315  app_config.cli_cfg.telnet_cfg.on_started = cli_on_started;
1316  }
1317 
1319  status = load_config(app_cfg.argc, app_cfg.argv, &uri_arg);
1320  if (status != PJ_SUCCESS) {
1321  pj_pool_release(tmp_pool);
1322  return status;
1323  }
1324 
1325  /* Initialize application callbacks */
1326  app_config.cfg.cb.on_call_state = &on_call_state;
1327  app_config.cfg.cb.on_call_media_state = &on_call_media_state;
1328  app_config.cfg.cb.on_incoming_call = &on_incoming_call;
1329  app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state;
1330  app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback;
1331  app_config.cfg.cb.on_call_redirected = &call_on_redirected;
1332  app_config.cfg.cb.on_reg_state = &on_reg_state;
1333  app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe;
1334  app_config.cfg.cb.on_buddy_state = &on_buddy_state;
1335  app_config.cfg.cb.on_buddy_evsub_state = &on_buddy_evsub_state;
1336  app_config.cfg.cb.on_pager = &on_pager;
1337  app_config.cfg.cb.on_typing = &on_typing;
1338  app_config.cfg.cb.on_call_transfer_status = &on_call_transfer_status;
1339  app_config.cfg.cb.on_call_replaced = &on_call_replaced;
1340  app_config.cfg.cb.on_nat_detect = &on_nat_detect;
1341  app_config.cfg.cb.on_mwi_info = &on_mwi_info;
1342  app_config.cfg.cb.on_transport_state = &on_transport_state;
1343  app_config.cfg.cb.on_ice_transport_error = &on_ice_transport_error;
1344  app_config.cfg.cb.on_snd_dev_operation = &on_snd_dev_operation;
1345  app_config.cfg.cb.on_call_media_event = &on_call_media_event;
1346 #ifdef TRANSPORT_ADAPTER_SAMPLE
1347  app_config.cfg.cb.on_create_media_transport = &on_create_media_transport;
1348 #endif
1349 
1350  /* Set sound device latency */
1351  if (app_config.capture_lat > 0)
1352  app_config.media_cfg.snd_rec_latency = app_config.capture_lat;
1353  if (app_config.playback_lat)
1354  app_config.media_cfg.snd_play_latency = app_config.playback_lat;
1355 
1356  if (app_cfg.on_config_init)
1357  (*app_cfg.on_config_init)(&app_config);
1358 
1359  /* Initialize pjsua */
1360  status = pjsua_init(&app_config.cfg, &app_config.log_cfg,
1361  &app_config.media_cfg);
1362  if (status != PJ_SUCCESS) {
1363  pj_pool_release(tmp_pool);
1364  return status;
1365  }
1366 
1367  /* Initialize our module to handle otherwise unhandled request */
1369  &mod_default_handler);
1370  if (status != PJ_SUCCESS)
1371  return status;
1372 
1373 #ifdef STEREO_DEMO
1374  stereo_demo();
1375 #endif
1376 
1377  /* Initialize calls data */
1378  for (i=0; i<PJ_ARRAY_SIZE(app_config.call_data); ++i) {
1379  app_config.call_data[i].timer.id = PJSUA_INVALID_ID;
1380  app_config.call_data[i].timer.cb = &call_timeout_callback;
1381  }
1382 
1383  /* Optionally registers WAV file */
1384  for (i=0; i<app_config.wav_count; ++i) {
1385  pjsua_player_id wav_id;
1386  unsigned play_options = 0;
1387 
1388  if (app_config.auto_play_hangup)
1389  play_options |= PJMEDIA_FILE_NO_LOOP;
1390 
1391  status = pjsua_player_create(&app_config.wav_files[i], play_options,
1392  &wav_id);
1393  if (status != PJ_SUCCESS)
1394  goto on_error;
1395 
1396  if (app_config.wav_id == PJSUA_INVALID_ID) {
1397  app_config.wav_id = wav_id;
1398  app_config.wav_port = pjsua_player_get_conf_port(app_config.wav_id);
1399  if (app_config.auto_play_hangup) {
1400  pjmedia_port *port;
1401 
1402  pjsua_player_get_port(app_config.wav_id, &port);
1403  status = pjmedia_wav_player_set_eof_cb(port, NULL,
1404  &on_playfile_done);
1405  if (status != PJ_SUCCESS)
1406  goto on_error;
1407 
1408  pj_timer_entry_init(&app_config.auto_hangup_timer, 0, NULL,
1409  &hangup_timeout_callback);
1410  }
1411  }
1412  }
1413 
1414  /* Optionally registers tone players */
1415  for (i=0; i<app_config.tone_count; ++i) {
1416  pjmedia_port *tport;
1417  char name[80];
1418  pj_str_t label;
1419  pj_status_t status2;
1420 
1421  pj_ansi_snprintf(name, sizeof(name), "tone-%d,%d",
1422  app_config.tones[i].freq1,
1423  app_config.tones[i].freq2);
1424  label = pj_str(name);
1425  status2 = pjmedia_tonegen_create2(app_config.pool, &label,
1426  8000, 1, 160, 16,
1427  PJMEDIA_TONEGEN_LOOP, &tport);
1428  if (status2 != PJ_SUCCESS) {
1429  pjsua_perror(THIS_FILE, "Unable to create tone generator", status);
1430  goto on_error;
1431  }
1432 
1433  status2 = pjsua_conf_add_port(app_config.pool, tport,
1434  &app_config.tone_slots[i]);
1435  pj_assert(status2 == PJ_SUCCESS);
1436 
1437  status2 = pjmedia_tonegen_play(tport, 1, &app_config.tones[i], 0);
1438  pj_assert(status2 == PJ_SUCCESS);
1439  }
1440 
1441  /* Optionally create recorder file, if any. */
1442  if (app_config.rec_file.slen) {
1443  status = pjsua_recorder_create(&app_config.rec_file, 0, NULL, 0, 0,
1444  &app_config.rec_id);
1445  if (status != PJ_SUCCESS)
1446  goto on_error;
1447 
1448  app_config.rec_port = pjsua_recorder_get_conf_port(app_config.rec_id);
1449  }
1450 
1451  pj_memcpy(&tcp_cfg, &app_config.udp_cfg, sizeof(tcp_cfg));
1452 
1453  /* Create ringback tones */
1454  if (app_config.no_tones == PJ_FALSE) {
1455  unsigned samples_per_frame;
1456  pjmedia_tone_desc tone[RING_CNT+RINGBACK_CNT];
1457  pj_str_t name;
1458 
1459  samples_per_frame = app_config.media_cfg.audio_frame_ptime *
1460  app_config.media_cfg.clock_rate *
1461  app_config.media_cfg.channel_count / 1000;
1462 
1463  /* Ringback tone (call is ringing) */
1464  name = pj_str("ringback");
1465  status = pjmedia_tonegen_create2(app_config.pool, &name,
1466  app_config.media_cfg.clock_rate,
1467  app_config.media_cfg.channel_count,
1468  samples_per_frame,
1469  16, PJMEDIA_TONEGEN_LOOP,
1470  &app_config.ringback_port);
1471  if (status != PJ_SUCCESS)
1472  goto on_error;
1473 
1474  pj_bzero(&tone, sizeof(tone));
1475  for (i=0; i<RINGBACK_CNT; ++i) {
1476  tone[i].freq1 = RINGBACK_FREQ1;
1477  tone[i].freq2 = RINGBACK_FREQ2;
1478  tone[i].on_msec = RINGBACK_ON;
1479  tone[i].off_msec = RINGBACK_OFF;
1480  }
1481  tone[RINGBACK_CNT-1].off_msec = RINGBACK_INTERVAL;
1482 
1483  pjmedia_tonegen_play(app_config.ringback_port, RINGBACK_CNT, tone,
1485 
1486 
1487  status = pjsua_conf_add_port(app_config.pool, app_config.ringback_port,
1488  &app_config.ringback_slot);
1489  if (status != PJ_SUCCESS)
1490  goto on_error;
1491 
1492  /* Ring (to alert incoming call) */
1493  name = pj_str("ring");
1494  status = pjmedia_tonegen_create2(app_config.pool, &name,
1495  app_config.media_cfg.clock_rate,
1496  app_config.media_cfg.channel_count,
1497  samples_per_frame,
1498  16, PJMEDIA_TONEGEN_LOOP,
1499  &app_config.ring_port);
1500  if (status != PJ_SUCCESS)
1501  goto on_error;
1502 
1503  for (i=0; i<RING_CNT; ++i) {
1504  tone[i].freq1 = RING_FREQ1;
1505  tone[i].freq2 = RING_FREQ2;
1506  tone[i].on_msec = RING_ON;
1507  tone[i].off_msec = RING_OFF;
1508  }
1509  tone[RING_CNT-1].off_msec = RING_INTERVAL;
1510 
1511  pjmedia_tonegen_play(app_config.ring_port, RING_CNT,
1512  tone, PJMEDIA_TONEGEN_LOOP);
1513 
1514  status = pjsua_conf_add_port(app_config.pool, app_config.ring_port,
1515  &app_config.ring_slot);
1516  if (status != PJ_SUCCESS)
1517  goto on_error;
1518 
1519  }
1520 
1521  /* Create AVI player virtual devices */
1522  if (app_config.avi_cnt) {
1523 #if PJMEDIA_HAS_VIDEO && PJMEDIA_VIDEO_DEV_HAS_AVI
1524  pjmedia_vid_dev_factory *avi_factory;
1525 
1527  app_config.avi_cnt,
1528  &avi_factory);
1529  if (status != PJ_SUCCESS) {
1530  PJ_PERROR(1,(THIS_FILE, status, "Error creating AVI factory"));
1531  goto on_error;
1532  }
1533 
1534  for (i=0; i<app_config.avi_cnt; ++i) {
1535  pjmedia_avi_dev_param avdp;
1536  pjmedia_vid_dev_index avid;
1537  unsigned strm_idx, strm_cnt;
1538 
1539  app_config.avi[i].dev_id = PJMEDIA_VID_INVALID_DEV;
1540  app_config.avi[i].slot = PJSUA_INVALID_ID;
1541 
1543  avdp.path = app_config.avi[i].path;
1544 
1545  status = pjmedia_avi_dev_alloc(avi_factory, &avdp, &avid);
1546  if (status != PJ_SUCCESS) {
1547  PJ_PERROR(1,(THIS_FILE, status,
1548  "Error creating AVI player for %.*s",
1549  (int)avdp.path.slen, avdp.path.ptr));
1550  goto on_error;
1551  }
1552 
1553  PJ_LOG(4,(THIS_FILE, "AVI player %.*s created, dev_id=%d",
1554  (int)avdp.title.slen, avdp.title.ptr, avid));
1555 
1556  app_config.avi[i].dev_id = avid;
1557  if (app_config.avi_def_idx == PJSUA_INVALID_ID)
1558  app_config.avi_def_idx = i;
1559 
1561  for (strm_idx=0; strm_idx<strm_cnt; ++strm_idx) {
1562  pjmedia_port *aud;
1563  pjmedia_format *fmt;
1564  pjsua_conf_port_id slot;
1565  char fmt_name[5];
1566 
1568  strm_idx);
1569  fmt = &aud->info.fmt;
1570 
1571  pjmedia_fourcc_name(fmt->id, fmt_name);
1572 
1573  if (fmt->id == PJMEDIA_FORMAT_PCM) {
1574  status = pjsua_conf_add_port(app_config.pool, aud,
1575  &slot);
1576  if (status == PJ_SUCCESS) {
1577  PJ_LOG(4,(THIS_FILE,
1578  "AVI %.*s: audio added to slot %d",
1579  (int)avdp.title.slen, avdp.title.ptr,
1580  slot));
1581  app_config.avi[i].slot = slot;
1582  }
1583  } else {
1584  PJ_LOG(4,(THIS_FILE,
1585  "AVI %.*s: audio ignored, format=%s",
1586  (int)avdp.title.slen, avdp.title.ptr,
1587  fmt_name));
1588  }
1589  }
1590  }
1591 #else
1592  PJ_LOG(2,(THIS_FILE,
1593  "Warning: --play-avi is ignored because AVI is disabled"));
1594 #endif /* PJMEDIA_VIDEO_DEV_HAS_AVI */
1595  }
1596 
1597  /* Add UDP transport unless it's disabled. */
1598  if (!app_config.no_udp) {
1599  pjsua_acc_id aid;
1601 
1602  status = pjsua_transport_create(type,
1603  &app_config.udp_cfg,
1604  &transport_id);
1605  if (status != PJ_SUCCESS)
1606  goto on_error;
1607 
1608  /* Add local account */
1609  pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
1610 
1611  /* Adjust local account config based on pjsua app config */
1612  {
1613  pjsua_acc_config acc_cfg;
1614  pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
1615 
1616  app_config_init_video(&acc_cfg);
1617  acc_cfg.rtp_cfg = app_config.rtp_cfg;
1618  pjsua_acc_modify(aid, &acc_cfg);
1619  }
1620 
1621  //pjsua_acc_set_transport(aid, transport_id);
1622  pjsua_acc_set_online_status(current_acc, PJ_TRUE);
1623 
1624  if (app_config.udp_cfg.port == 0) {
1626  pj_sockaddr_in *a;
1627 
1628  pjsua_transport_get_info(transport_id, &ti);
1629  a = (pj_sockaddr_in*)&ti.local_addr;
1630 
1631  tcp_cfg.port = pj_ntohs(a->sin_port);
1632  }
1633  }
1634 
1635  /* Add UDP IPv6 transport unless it's disabled. */
1636  if (!app_config.no_udp && app_config.ipv6) {
1637  pjsua_acc_id aid;
1639  pjsua_transport_config udp_cfg;
1640 
1641  udp_cfg = app_config.udp_cfg;
1642  if (udp_cfg.port == 0)
1643  udp_cfg.port = 5060;
1644  else
1645  udp_cfg.port += 10;
1646  status = pjsua_transport_create(type,
1647  &udp_cfg,
1648  &transport_id);
1649  if (status != PJ_SUCCESS)
1650  goto on_error;
1651 
1652  /* Add local account */
1653  pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
1654 
1655  /* Adjust local account config based on pjsua app config */
1656  {
1657  pjsua_acc_config acc_cfg;
1658  pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
1659 
1660  app_config_init_video(&acc_cfg);
1661  acc_cfg.rtp_cfg = app_config.rtp_cfg;
1663  pjsua_acc_modify(aid, &acc_cfg);
1664  }
1665 
1666  //pjsua_acc_set_transport(aid, transport_id);
1667  pjsua_acc_set_online_status(current_acc, PJ_TRUE);
1668 
1669  if (app_config.udp_cfg.port == 0) {
1671 
1672  pjsua_transport_get_info(transport_id, &ti);
1673  tcp_cfg.port = pj_sockaddr_get_port(&ti.local_addr);
1674  }
1675  }
1676 
1677  /* Add TCP transport unless it's disabled */
1678  if (!app_config.no_tcp) {
1679  pjsua_acc_id aid;
1680 
1682  &tcp_cfg,
1683  &transport_id);
1684  if (status != PJ_SUCCESS)
1685  goto on_error;
1686 
1687  /* Add local account */
1688  pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
1689 
1690  /* Adjust local account config based on pjsua app config */
1691  {
1692  pjsua_acc_config acc_cfg;
1693  pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
1694 
1695  app_config_init_video(&acc_cfg);
1696  acc_cfg.rtp_cfg = app_config.rtp_cfg;
1697  pjsua_acc_modify(aid, &acc_cfg);
1698  }
1699 
1700  pjsua_acc_set_online_status(current_acc, PJ_TRUE);
1701 
1702  }
1703 
1704  /* Add TCP IPv6 transport unless it's disabled. */
1705  if (!app_config.no_tcp && app_config.ipv6) {
1706  pjsua_acc_id aid;
1708 
1709  tcp_cfg.port += 10;
1710 
1711  status = pjsua_transport_create(type,
1712  &tcp_cfg,
1713  &transport_id);
1714  if (status != PJ_SUCCESS)
1715  goto on_error;
1716 
1717  /* Add local account */
1718  pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
1719 
1720  /* Adjust local account config based on pjsua app config */
1721  {
1722  pjsua_acc_config acc_cfg;
1723  pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
1724 
1725  app_config_init_video(&acc_cfg);
1726  acc_cfg.rtp_cfg = app_config.rtp_cfg;
1728  pjsua_acc_modify(aid, &acc_cfg);
1729  }
1730 
1731  //pjsua_acc_set_transport(aid, transport_id);
1732  pjsua_acc_set_online_status(current_acc, PJ_TRUE);
1733  }
1734 
1735 
1736 #if defined(PJSIP_HAS_TLS_TRANSPORT) && PJSIP_HAS_TLS_TRANSPORT!=0
1737  /* Add TLS transport when application wants one */
1738  if (app_config.use_tls) {
1739 
1740  pjsua_acc_id acc_id;
1741 
1742  /* Copy the QoS settings */
1743  tcp_cfg.tls_setting.qos_type = tcp_cfg.qos_type;
1744  pj_memcpy(&tcp_cfg.tls_setting.qos_params, &tcp_cfg.qos_params,
1745  sizeof(tcp_cfg.qos_params));
1746 
1747  /* Set TLS port as TCP port+1 */
1748  tcp_cfg.port++;
1750  &tcp_cfg,
1751  &transport_id);
1752  tcp_cfg.port--;
1753  if (status != PJ_SUCCESS)
1754  goto on_error;
1755 
1756  /* Add local account */
1757  pjsua_acc_add_local(transport_id, PJ_FALSE, &acc_id);
1758 
1759  /* Adjust local account config based on pjsua app config */
1760  {
1761  pjsua_acc_config acc_cfg;
1762  pjsua_acc_get_config(acc_id, tmp_pool, &acc_cfg);
1763 
1764  app_config_init_video(&acc_cfg);
1765  acc_cfg.rtp_cfg = app_config.rtp_cfg;
1766  pjsua_acc_modify(acc_id, &acc_cfg);
1767  }
1768 
1770  }
1771 
1772  /* Add TLS IPv6 transport unless it's disabled. */
1773  if (app_config.use_tls && app_config.ipv6) {
1774  pjsua_acc_id aid;
1776 
1777  tcp_cfg.port += 10;
1778 
1779  status = pjsua_transport_create(type,
1780  &tcp_cfg,
1781  &transport_id);
1782  if (status != PJ_SUCCESS)
1783  goto on_error;
1784 
1785  /* Add local account */
1786  pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
1787 
1788  /* Adjust local account config based on pjsua app config */
1789  {
1790  pjsua_acc_config acc_cfg;
1791  pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
1792 
1793  app_config_init_video(&acc_cfg);
1794  acc_cfg.rtp_cfg = app_config.rtp_cfg;
1796  pjsua_acc_modify(aid, &acc_cfg);
1797  }
1798 
1799  //pjsua_acc_set_transport(aid, transport_id);
1800  pjsua_acc_set_online_status(current_acc, PJ_TRUE);
1801  }
1802 
1803 #endif
1804 
1805  if (transport_id == -1) {
1806  PJ_LOG(1,(THIS_FILE, "Error: no transport is configured"));
1807  status = -1;
1808  goto on_error;
1809  }
1810 
1811 
1812  /* Add accounts */
1813  for (i=0; i<app_config.acc_cnt; ++i) {
1814  app_config.acc_cfg[i].rtp_cfg = app_config.rtp_cfg;
1815  app_config.acc_cfg[i].reg_retry_interval = 300;
1816  app_config.acc_cfg[i].reg_first_retry_interval = 60;
1817 
1818  app_config_init_video(&app_config.acc_cfg[i]);
1819 
1820  status = pjsua_acc_add(&app_config.acc_cfg[i], PJ_TRUE, NULL);
1821  if (status != PJ_SUCCESS)
1822  goto on_error;
1823  pjsua_acc_set_online_status(current_acc, PJ_TRUE);
1824  }
1825 
1826  /* Add buddies */
1827  for (i=0; i<app_config.buddy_cnt; ++i) {
1828  status = pjsua_buddy_add(&app_config.buddy_cfg[i], NULL);
1829  if (status != PJ_SUCCESS) {
1830  PJ_PERROR(1,(THIS_FILE, status, "Error adding buddy"));
1831  goto on_error;
1832  }
1833  }
1834 
1835  /* Optionally disable some codec */
1836  for (i=0; i<app_config.codec_dis_cnt; ++i) {
1837  pjsua_codec_set_priority(&app_config.codec_dis[i],
1839 #if PJSUA_HAS_VIDEO
1840  pjsua_vid_codec_set_priority(&app_config.codec_dis[i],
1842 #endif
1843  }
1844 
1845  /* Optionally set codec orders */
1846  for (i=0; i<app_config.codec_cnt; ++i) {
1847  pjsua_codec_set_priority(&app_config.codec_arg[i],
1849 #if PJSUA_HAS_VIDEO
1850  pjsua_vid_codec_set_priority(&app_config.codec_arg[i],
1852 #endif
1853  }
1854 
1855  /* Use null sound device? */
1856 #ifndef STEREO_DEMO
1857  if (app_config.null_audio) {
1858  status = pjsua_set_null_snd_dev();
1859  if (status != PJ_SUCCESS)
1860  return status;
1861  }
1862 #endif
1863 
1864  if (app_config.capture_dev != PJSUA_INVALID_ID ||
1865  app_config.playback_dev != PJSUA_INVALID_ID)
1866  {
1867  status = pjsua_set_snd_dev(app_config.capture_dev,
1868  app_config.playback_dev);
1869  if (status != PJ_SUCCESS)
1870  goto on_error;
1871  }
1872 
1873  /* Init call setting */
1874  pjsua_call_setting_default(&call_opt);
1875  call_opt.aud_cnt = app_config.aud_cnt;
1876  call_opt.vid_cnt = app_config.vid.vid_cnt;
1877 
1878  pj_pool_release(tmp_pool);
1879  return PJ_SUCCESS;
1880 
1881 on_error:
1882  pj_pool_release(tmp_pool);
1883  app_destroy();
1884  return status;
1885 }
1886 
1887 pj_status_t pjsua_app_init(const pjsua_app_cfg_t *cfg)
1888 {
1889  pj_status_t status;
1890  pj_memcpy(&app_cfg, cfg, sizeof(app_cfg));
1891 
1892  status = app_init();
1893  if (status != PJ_SUCCESS)
1894  return status;
1895 
1896  /* Init CLI if configured */
1897  if (app_config.use_cli) {
1898  status = cli_init();
1899  }
1900  return status;
1901 }
1902 
1903 pj_status_t pjsua_app_run(pj_bool_t wait_telnet_cli)
1904 {
1905  pj_thread_t *stdout_refresh_thread = NULL;
1906  pj_status_t status;
1907 
1908  /* Start console refresh thread */
1909  if (stdout_refresh > 0) {
1910  pj_thread_create(app_config.pool, "stdout", &stdout_refresh_proc,
1911  NULL, 0, 0, &stdout_refresh_thread);
1912  }
1913 
1914  status = pjsua_start();
1915  if (status != PJ_SUCCESS)
1916  goto on_return;
1917 
1918  if (app_config.use_cli && (app_config.cli_cfg.cli_fe & CLI_FE_TELNET)) {
1919  char info[128];
1920  cli_get_info(info, sizeof(info));
1921  if (app_cfg.on_started) {
1922  (*app_cfg.on_started)(status, info);
1923  }
1924  } else {
1925  if (app_cfg.on_started) {
1926  (*app_cfg.on_started)(status, "Ready");
1927  }
1928  }
1929 
1930  /* If user specifies URI to call, then call the URI */
1931  if (uri_arg.slen) {
1932  pjsua_call_setting_default(&call_opt);
1933  call_opt.aud_cnt = app_config.aud_cnt;
1934  call_opt.vid_cnt = app_config.vid.vid_cnt;
1935 
1936  pjsua_call_make_call(current_acc, &uri_arg, &call_opt, NULL,
1937  NULL, NULL);
1938  }
1939 
1940  app_running = PJ_TRUE;
1941 
1942  if (app_config.use_cli)
1943  cli_main(wait_telnet_cli);
1944  else
1945  legacy_main();
1946 
1947  status = PJ_SUCCESS;
1948 
1949 on_return:
1950  if (stdout_refresh_thread) {
1951  stdout_refresh_quit = PJ_TRUE;
1952  pj_thread_join(stdout_refresh_thread);
1953  pj_thread_destroy(stdout_refresh_thread);
1954  stdout_refresh_quit = PJ_FALSE;
1955  }
1956  return status;
1957 }
1958 
1959 static pj_status_t app_destroy()
1960 {
1961  pj_status_t status = PJ_SUCCESS;
1962  unsigned i;
1963  pj_bool_t use_cli = PJ_FALSE;
1964  int cli_fe = 0;
1965  pj_uint16_t cli_telnet_port = 0;
1966 
1967 #ifdef STEREO_DEMO
1968  if (app_config.snd) {
1969  pjmedia_snd_port_destroy(app_config.snd);
1970  app_config.snd = NULL;
1971  }
1972  if (app_config.sc_ch1) {
1973  pjsua_conf_remove_port(app_config.sc_ch1_slot);
1974  app_config.sc_ch1_slot = PJSUA_INVALID_ID;
1975  pjmedia_port_destroy(app_config.sc_ch1);
1976  app_config.sc_ch1 = NULL;
1977  }
1978  if (app_config.sc) {
1979  pjmedia_port_destroy(app_config.sc);
1980  app_config.sc = NULL;
1981  }
1982 #endif
1983 
1984  /* Close avi devs and ports */
1985  for (i=0; i<app_config.avi_cnt; ++i) {
1986  if (app_config.avi[i].slot != PJSUA_INVALID_ID)
1987  pjsua_conf_remove_port(app_config.avi[i].slot);
1988 #if PJMEDIA_HAS_VIDEO && PJMEDIA_VIDEO_DEV_HAS_AVI
1989  if (app_config.avi[i].dev_id != PJMEDIA_VID_INVALID_DEV)
1990  pjmedia_avi_dev_free(app_config.avi[i].dev_id);
1991 #endif
1992  }
1993 
1994  /* Close ringback port */
1995  if (app_config.ringback_port &&
1996  app_config.ringback_slot != PJSUA_INVALID_ID)
1997  {
1998  pjsua_conf_remove_port(app_config.ringback_slot);
1999  app_config.ringback_slot = PJSUA_INVALID_ID;
2000  pjmedia_port_destroy(app_config.ringback_port);
2001  app_config.ringback_port = NULL;
2002  }
2003 
2004  /* Close ring port */
2005  if (app_config.ring_port && app_config.ring_slot != PJSUA_INVALID_ID) {
2006  pjsua_conf_remove_port(app_config.ring_slot);
2007  app_config.ring_slot = PJSUA_INVALID_ID;
2008  pjmedia_port_destroy(app_config.ring_port);
2009  app_config.ring_port = NULL;
2010  }
2011 
2012  /* Close tone generators */
2013  for (i=0; i<app_config.tone_count; ++i) {
2014  pjsua_conf_remove_port(app_config.tone_slots[i]);
2015  }
2016 
2017  pj_pool_safe_release(&app_config.pool);
2018 
2019  status = pjsua_destroy();
2020 
2021  if (app_config.use_cli) {
2022  use_cli = app_config.use_cli;
2023  cli_fe = app_config.cli_cfg.cli_fe;
2024  cli_telnet_port = app_config.cli_cfg.telnet_cfg.port;
2025  }
2026 
2027  /* Reset config */
2028  pj_bzero(&app_config, sizeof(app_config));
2029 
2030  if (use_cli) {
2031  app_config.use_cli = use_cli;
2032  app_config.cli_cfg.cli_fe = cli_fe;
2033  app_config.cli_cfg.telnet_cfg.port = cli_telnet_port;
2034  }
2035 
2036  return status;
2037 }
2038 
2039 pj_status_t pjsua_app_destroy()
2040 {
2041  pj_status_t status;
2042 
2043  status = app_destroy();
2044 
2045  if (app_config.use_cli) {
2046  cli_destroy();
2047  }
2048 
2049  return status;
2050 }
2051 
2054 #ifdef STEREO_DEMO
2055 /*
2056  * In this stereo demo, we open the sound device in stereo mode and
2057  * arrange the attachment to the PJSUA-LIB conference bridge as such
2058  * so that channel0/left channel of the sound device corresponds to
2059  * slot 0 in the bridge, and channel1/right channel of the sound
2060  * device corresponds to slot 1 in the bridge. Then user can independently
2061  * feed different media to/from the speakers/microphones channels, by
2062  * connecting them to slot 0 or 1 respectively.
2063  *
2064  * Here's how the connection looks like:
2065  *
2066  +-----------+ stereo +-----------------+ 2x mono +-----------+
2067  | AUDIO DEV |<------>| SPLITCOMB left|<------->|#0 BRIDGE |
2068  +-----------+ | right|<------->|#1 |
2069  +-----------------+ +-----------+
2070  */
2071 static void stereo_demo()
2072 {
2073  pjmedia_port *conf;
2074  pj_status_t status;
2075 
2076  /* Disable existing sound device */
2077  conf = pjsua_set_no_snd_dev();
2078 
2079  /* Create stereo-mono splitter/combiner */
2080  status = pjmedia_splitcomb_create(app_config.pool,
2081  PJMEDIA_PIA_SRATE(&conf->info) /* clock rate */,
2082  2 /* stereo */,
2083  2 * PJMEDIA_PIA_SPF(&conf->info),
2084  PJMEDIA_PIA_BITS(&conf->info),
2085  0 /* options */,
2086  &app_config.sc);
2087  pj_assert(status == PJ_SUCCESS);
2088 
2089  /* Connect channel0 (left channel?) to conference port slot0 */
2090  status = pjmedia_splitcomb_set_channel(app_config.sc, 0 /* ch0 */,
2091  0 /*options*/,
2092  conf);
2093  pj_assert(status == PJ_SUCCESS);
2094 
2095  /* Create reverse channel for channel1 (right channel?)... */
2096  status = pjmedia_splitcomb_create_rev_channel(app_config.pool,
2097  app_config.sc,
2098  1 /* ch1 */,
2099  0 /* options */,
2100  &app_config.sc_ch1);
2101  pj_assert(status == PJ_SUCCESS);
2102 
2103  /* .. and register it to conference bridge (it would be slot1
2104  * if there's no other devices connected to the bridge)
2105  */
2106  status = pjsua_conf_add_port(app_config.pool, app_config.sc_ch1,
2107  &app_config.sc_ch1_slot);
2108  pj_assert(status == PJ_SUCCESS);
2109 
2110  /* Create sound device */
2111  status = pjmedia_snd_port_create(app_config.pool, -1, -1,
2112  PJMEDIA_PIA_SRATE(&conf->info),
2113  2 /* stereo */,
2114  2 * PJMEDIA_PIA_SPF(&conf->info),
2115  PJMEDIA_PIA_BITS(&conf->info),
2116  0, &app_config.snd);
2117 
2118  pj_assert(status == PJ_SUCCESS);
2119 
2120 
2121  /* Connect the splitter to the sound device */
2122  status = pjmedia_snd_port_connect(app_config.snd, app_config.sc);
2123  pj_assert(status == PJ_SUCCESS);
2124 }
2125 #endif
pj_status_t pjsip_endpt_create_response(pjsip_endpoint *endpt, const pjsip_rx_data *rdata, int st_code, const pj_str_t *st_text, pjsip_tx_data **p_tdata)
pj_bool_t rem_offerer
Definition: pjsua-lib/pjsua.h:4527
int pjsip_uri_print(pjsip_uri_context_e context, const void *uri, char *buf, pj_size_t size)
Definition: sip_uri.h:299
PJ_BEGIN_DECL pj_status_t pjmedia_splitcomb_create(pj_pool_t *pool, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, unsigned options, pjmedia_port **p_splitcomb)
pjsip_host_port remote_name
Definition: sip_transport.h:797
void pjsip_endpt_cancel_timer(pjsip_endpoint *endpt, pj_timer_entry *entry)
struct pjsip_request_line req
Definition: sip_msg.h:792
int pj_stricmp(const pj_str_t *str1, const pj_str_t *str2)
struct pj_timer_heap_t pj_timer_heap_t
pjsip_hdr hdr
Definition: sip_msg.h:799
pj_ssize_t slen
pj_uint16_t pj_ntohs(pj_uint16_t netshort)
Definition: sip_transport.h:508
pjsip_rx_data * rdata
Definition: pjsua-lib/pjsua.h:472
pj_status_t pjsua_vid_win_set_size(pjsua_vid_win_id wid, const pjmedia_rect_size *size)
char * ptr
pjmedia_port_info info
pj_str_t subtype
Definition: sip_msg.h:517
void pj_pool_release(pj_pool_t *pool)
unsigned vid_cnt
Definition: pjsua-lib/pjsua.h:773
Definition: sip_types.h:74
pjmedia_format fmt
void pjsua_msg_data_init(pjsua_msg_data *msg_data)
Definition: sip_types.h:98
pj_status_t pjsua_vid_win_get_info(pjsua_vid_win_id wid, pjsua_vid_win_info *wi)
int pj_bool_t
Definition: pjsua-lib/pjsua.h:1967
pjsip_method method
Definition: sip_transaction.h:99
struct pj_thread_t pj_thread_t
const pjsip_method pjsip_ack_method
Definition: sip_msg.h:95
void pj_list_push_back(pj_list_type *list, pj_list_type *node)
pj_qos_params qos_params
Definition: pjsua-lib/pjsua.h:2646
pj_thread_t * pj_thread_this(void)
pj_status_t pj_thread_set_prio(pj_thread_t *thread, int prio)
void * pj_memcpy(void *dst, const void *src, pj_size_t size)
pj_uint16_t sin_port
Definition: sip_transport_tls.h:297
Definition: pjsua-lib/pjsua.h:4453
pj_status_t pjsua_recorder_create(const pj_str_t *filename, unsigned enc_type, void *enc_param, pj_ssize_t max_size, unsigned options, pjsua_recorder_id *p_id)
pj_status_t pjsua_set_snd_dev(int capture_dev, int playback_dev)
Definition: sip_msg.h:77
Definition: sip_msg.h:64
pj_status_t pjmedia_port_destroy(pjmedia_port *port)
pj_sockaddr local_addr
Definition: pjsua-lib/pjsua.h:2718
pj_status_t pjsua_conf_disconnect(pjsua_conf_port_id source, pjsua_conf_port_id sink)
pj_pool_t * pool
Definition: sip_transport.h:514
pjmedia_rect_size size
Definition: pjsua-lib/pjsua.h:7378
pj_status_t pjsua_acc_get_config(pjsua_acc_id acc_id, pj_pool_t *pool, pjsua_acc_config *acc_cfg)
pjsip_role_e role
Definition: sip_transaction.h:98
pjsip_status_code last_status
Definition: pjsua-lib/pjsua.h:4489
const pjsip_method pjsip_notify_method
Definition: evsub.h:208
int pjsua_transport_id
Definition: pjsua-lib/pjsua.h:2571
pj_status_t pjsua_player_create(const pj_str_t *filename, unsigned options, pjsua_player_id *p_id)
Definition: sip_uri.h:222
pjsip_tsx_state_e state
Definition: sip_transaction.h:110
pj_str_t local_info
Definition: pjsua-lib/pjsua.h:4465
PJMEDIA_TONEGEN_LOOP
int pjsua_acc_id
Definition: pjsua-lib/pjsua.h:266
pj_status_t pjmedia_snd_port_destroy(pjmedia_snd_port *snd_port)
pj_str_t reason
Definition: sip_msg.h:393
PJMEDIA_TYPE_AUDIO
Definition: pjsua-lib/pjsua.h:7345
pjsip_hdr hdr_list
Definition: pjsua-lib/pjsua.h:1982
Definition: pjsua-lib/pjsua.h:3201
void pjmedia_avi_dev_param_default(pjmedia_avi_dev_param *p)
struct pjsip_event::@9::@11 tsx_state
Definition: sip_msg.h:1356
Definition: sip_msg.h:606
pjmedia_port * pjsua_set_no_snd_dev(void)
pj_status_t pjsua_conf_add_port(pj_pool_t *pool, pjmedia_port *port, pjsua_conf_port_id *p_id)
pjmedia_event_type type
unsigned len
Definition: sip_msg.h:643
PJMEDIA_FORMAT_PCM
#define PJ_PERROR(level, arg)
void pjsua_call_setting_default(pjsua_call_setting *opt)
pj_status_t pjsua_transport_get_info(pjsua_transport_id id, pjsua_transport_info *info)
Definition: sip_transport.h:1434
#define PJSIP_MAX_URL_SIZE
Definition: sip_config.h:320
pjsip_inv_state state
Definition: pjsua-lib/pjsua.h:4483
void pjsip_msg_add_hdr(pjsip_msg *msg, pjsip_hdr *hdr)
Definition: sip_msg.h:904
pj_str_t hvalue
Definition: sip_msg.h:998
#define PJ_LOG(level, arg)
pjsip_event_id_e type
Definition: sip_event.h:88
void pjsua_perror(const char *sender, const char *title, pj_status_t status)
pj_pool_t * pjsua_pool_create(const char *name, pj_size_t init_size, pj_size_t increment)
int code
Definition: sip_msg.h:392
pj_status_t pjmedia_wav_player_set_eof_cb(pjmedia_port *port, void *user_data, pj_status_t(*cb)(pjmedia_port *port, void *usr_data))
PJ_BEGIN_DECL pj_status_t pjmedia_tp_adapter_create(pjmedia_endpt *endpt, const char *name, pjmedia_transport *base_tp, pj_bool_t del_base, pjmedia_transport **p_tp)
pj_status_t pjsua_acc_add_local(pjsua_transport_id tid, pj_bool_t is_default, pjsua_acc_id *p_acc_id)
pj_status_t pjmedia_tonegen_play(pjmedia_port *tonegen, unsigned count, const pjmedia_tone_desc tones[], unsigned options)
int pj_status_t
Definition: sip_transport.h:1414
pj_str_t status_text
Definition: pjsua-lib/pjsua.h:5527
char * type_name
Definition: sip_transport.h:790
PJMEDIA_EVENT_FMT_CHANGED
pj_int32_t expires
Definition: sip_msg.h:1362
pj_status_t pj_thread_create(pj_pool_t *pool, const char *thread_name, pj_thread_proc *proc, void *arg, pj_size_t stack_size, unsigned flags, pj_thread_t **thread)
Definition: pjsua-lib/pjsua.h:4359
pjsip_transport_type_e
Definition: sip_types.h:62
Definition: pjsua-lib/pjsua.h:3175
pj_status_t pj_ssl_cert_get_verify_status_strings(pj_uint32_t verify_status, const char *error_strings[], unsigned *count)
unsigned aud_cnt
Definition: pjsua-lib/pjsua.h:765
pj_status_t pjsua_start(void)
pj_status_t pjmedia_avi_dev_free(pjmedia_vid_dev_index id)
pj_status_t status
Definition: sip_transport.h:1438
pjsip_endpoint * endpt
Definition: sip_transaction.h:87
Definition: pjsua-lib/pjsua.h:4364
int pjsua_call_id
Definition: pjsua-lib/pjsua.h:263
PJMEDIA_DIR_DECODING
pj_status_t pjsua_init(const pjsua_config *ua_cfg, const pjsua_logging_config *log_cfg, const pjsua_media_config *media_cfg)
pjsip_tls_setting tls_setting
Definition: pjsua-lib/pjsua.h:2628
pj_int32_t pjmedia_vid_dev_index
pj_status_t pjsip_tsx_send_msg(pjsip_transaction *tsx, pjsip_tx_data *tdata)
pj_qos_type qos_type
Definition: pjsua-lib/pjsua.h:2637
pjsua_transport_config rtp_cfg
Definition: pjsua-lib/pjsua.h:3631
pj_str_t uri
Definition: pjsua-lib/pjsua.h:5511
pj_status_t pjsua_vid_codec_set_priority(const pj_str_t *codec_id, pj_uint8_t priority)
Definition: sip_event.h:81
pjmedia_avi_streams * avi_streams
pj_status_t pjmedia_splitcomb_create_rev_channel(pj_pool_t *pool, pjmedia_port *splitcomb, unsigned ch_num, unsigned options, pjmedia_port **p_chport)
int pj_thread_get_prio_min(pj_thread_t *thread)
typedefPJ_BEGIN_DECL struct pjsip_evsub pjsip_evsub
Definition: evsub.h:51
int port
Definition: sip_types.h:221
pj_str_t info
pj_qos_params qos_params
Definition: sip_transport_tls.h:262
Definition: sip_transport.h:776
const char * pj_get_version(void)
Definition: sip_types.h:95
pj_status_t pjmedia_avi_dev_alloc(pjmedia_vid_dev_factory *f, pjmedia_avi_dev_param *param, pjmedia_vid_dev_index *p_id)
void pj_pool_safe_release(pj_pool_t **ppool)
pj_str_t last_status_text
Definition: pjsua-lib/pjsua.h:4492
const pjsip_method pjsip_register_method
Definition: sip_msg.h:101
pjsip_hdr_e type
Definition: sip_msg.h:326
pjmedia_avi_stream * pjmedia_avi_streams_get_stream(pjmedia_avi_streams *streams, unsigned idx)
Definition: sip_transaction.h:66
pjsip_media_type media
Definition: sip_msg.h:1400
Definition: sip_transport.h:281
pjsua_conf_port_id pjsua_recorder_get_conf_port(pjsua_recorder_id id)
Definition: sip_types.h:186
pj_status_t pjsip_endpt_register_module(pjsip_endpoint *endpt, pjsip_module *module)
pj_status_t pjsua_call_hangup(pjsua_call_id call_id, unsigned code, const pj_str_t *reason, const pjsua_msg_data *msg_data)
pjsua_call_media_info media[PJMEDIA_MAX_SDP_MEDIA]
Definition: pjsua-lib/pjsua.h:4507
PJMEDIA_DIR_NONE
void pj_cli_console_cfg_default(pj_cli_console_cfg *param)
pjsip_msg * msg
Definition: sip_transport.h:542
pjsua_conf_port_id pjsua_call_get_conf_port(pjsua_call_id call_id)
pj_ssl_sock_info * ssl_sock_info
Definition: sip_transport_tls.h:302
Definition: sip_inv.h:96
pj_status_t pjmedia_snd_port_create(pj_pool_t *pool, int rec_id, int play_id, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, unsigned options, pjmedia_snd_port **p_port)
pjsip_msg_body * body
Definition: sip_msg.h:804
pj_pool_factory * pjsua_get_pool_factory(void)
unsigned media_cnt
Definition: pjsua-lib/pjsua.h:4504
PJ_TRUE
pjsua_conf_port_id pjsua_player_get_conf_port(pjsua_player_id id)
struct pjsip_rx_data::@24 msg_info
pj_str_t host
Definition: sip_types.h:220
pj_status_t pjsip_endpt_send_response2(pjsip_endpoint *endpt, pjsip_rx_data *rdata, pjsip_tx_data *tdata, void *token, pjsip_send_callback cb)
pj_str_t state_text
Definition: pjsua-lib/pjsua.h:4486
pj_status_t pjsua_conf_remove_port(pjsua_conf_port_id port_id)
Definition: sip_transport.h:1411
pj_status_t pjsua_get_snd_dev(int *capture_dev, int *playback_dev)
pj_str_t type
Definition: sip_msg.h:516
int pjsua_player_id
Definition: pjsua-lib/pjsua.h:272
pj_int32_t ivalue
Definition: sip_msg.h:1071
pj_status_t pjsua_create(void)
Definition: pjsua-lib/pjsua.h:619
Definition: sip_inv.h:95
Definition: sip_event.h:55
pjsip_status_code
Definition: sip_msg.h:403
pjsip_media_type content_type
Definition: sip_msg.h:620
pj_uint32_t flags
Definition: pjsua-lib/pjsua.h:4379
union pjsip_event::@9 body
int pjsip_method_cmp(const pjsip_method *m1, const pjsip_method *m2)
union pjsua_call_media_info::@36 stream
pj_status_t pjsua_transport_create(pjsip_transport_type_e type, const pjsua_transport_config *cfg, pjsua_transport_id *p_id)
unsigned pjsua_call_get_count(void)
pj_str_t pj_str(char *str)
const char * sub_state_name
Definition: pjsua-lib/pjsua.h:5548
Definition: sip_types.h:92
pjsip_msg * msg
Definition: sip_transport.h:351
Definition: sip_uri.h:156
pj_status_t pjsua_codec_set_priority(const pj_str_t *codec_id, pj_uint8_t priority)
const char * pjmedia_fourcc_name(pj_uint32_t sig, char buf[])
pjmedia_dir dir
Definition: pjsua-lib/pjsua.h:4418
pj_bool_t pjsua_call_has_media(pjsua_call_id call_id)
Definition: sip_types.h:71
pj_ssize_t pj_ssl_cert_info_dump(const pj_ssl_cert_info *ci, const char *indent, char *buf, pj_size_t buf_size)
pj_status_t pjmedia_avi_dev_create_factory(pj_pool_factory *pf, unsigned max_dev, pjmedia_vid_dev_factory **p_ret)
pjsua_call_media_status status
Definition: pjsua-lib/pjsua.h:4421
PJMEDIA_CODEC_PRIO_NORMAL
pj_status_t pjsip_endpt_schedule_timer(pjsip_endpoint *endpt, pj_timer_entry *entry, const pj_time_val *delay)
pjsua_ipv6_use ipv6_media_use
Definition: pjsua-lib/pjsua.h:3643
void pj_bzero(void *dst, pj_size_t size)
void * data
Definition: sip_msg.h:633
Definition: pjsua-lib/pjsua.h:468
pj_status_t pjsua_set_null_snd_dev(void)
unsigned port
Definition: pjsua-lib/pjsua.h:2588
pj_str_t status_text
Definition: sip_transaction.h:109
Definition: sip_event.h:52
unsigned char pj_uint8_t
int pjsua_buddy_id
Definition: pjsua-lib/pjsua.h:269
struct pjsip_endpoint pjsip_endpoint
Definition: sip_types.h:106
Definition: sip_transaction.h:70
#define pj_assert(expr)
pj_ice_strans_op
pj_status_t pjsua_buddy_get_info(pjsua_buddy_id buddy_id, pjsua_buddy_info *info)
Definition: sip_msg.h:780
struct pjsip_status_line status
Definition: sip_msg.h:795
pj_str_t sub_term_reason
Definition: pjsua-lib/pjsua.h:5563
PJMEDIA_FILE_NO_LOOP
char * pjsip_rx_data_get_info(pjsip_rx_data *rdata)
pjsip_transport_state
Definition: sip_transport.h:1409
#define PJSUA_MAX_CALLS
Definition: pjsua-lib/pjsua.h:4334
pj_status_t pjsua_acc_set_online_status(pjsua_acc_id acc_id, pj_bool_t is_online)
#define PJ_ARRAY_SIZE(a)
Definition: sip_msg.h:1066
pj_uint16_t pj_sockaddr_get_port(const pj_sockaddr_t *addr)
pj_status_t pjsua_acc_modify(pjsua_acc_id acc_id, const pjsua_acc_config *acc_cfg)
pj_str_t remote_info
Definition: pjsua-lib/pjsua.h:4471
void * pjsip_msg_find_hdr(const pjsip_msg *msg, pjsip_hdr_e type, const void *start)
pj_status_t pjsua_call_make_call(pjsua_acc_id acc_id, const pj_str_t *dst_uri, const pjsua_call_setting *opt, void *user_data, const pjsua_msg_data *msg_data, pjsua_call_id *p_call_id)
union pjsip_msg::@17 line
PJMEDIA_VID_INVALID_DEV
const char * pjsip_evsub_get_state_name(pjsip_evsub *sub)
const char * pjmedia_type_name(pjmedia_type t)
pj_timer_entry * pj_timer_entry_init(pj_timer_entry *entry, int id, void *user_data, pj_timer_heap_callback *cb)
unsigned PJMEDIA_PIA_SPF(const pjmedia_port_info *pia)
Definition: sip_types.h:68
Definition: pjsua-lib/pjsua.h:2683
pj_status_t pjmedia_snd_port_connect(pjmedia_snd_port *snd_port, pjmedia_port *port)
pj_status_t pjmedia_tonegen_rewind(pjmedia_port *tonegen)
pjsip_role_e role
Definition: pjsua-lib/pjsua.h:4459
Definition: sip_msg.h:993
void pjsua_call_hangup_all(void)
int pjsua_conf_port_id
Definition: pjsua-lib/pjsua.h:278
pjsip_ctype_hdr * ctype
Definition: sip_transport.h:383
Definition: sip_util.h:105
pj_uint32_t id
Definition: pjsua-lib/pjsua.h:4374
pj_status_t pjsua_buddy_add(const pjsua_buddy_config *buddy_cfg, pjsua_buddy_id *p_buddy_id)
pj_str_t * pj_strdup2_with_null(pj_pool_t *pool, pj_str_t *dst, const char *src)
int id
pj_status_t pj_thread_join(pj_thread_t *thread)
unsigned PJMEDIA_PIA_SRATE(const pjmedia_port_info *pia)
const pjsip_hdr * pjsip_endpt_get_capability(pjsip_endpoint *endpt, int htype, const pj_str_t *hname)
unsigned sub_term_code
Definition: pjsua-lib/pjsua.h:5557
Definition: sip_msg.h:1397
pj_status_t pj_thread_destroy(pj_thread_t *thread)
pj_status_t pjsua_destroy(void)
PJMEDIA_CODEC_PRIO_DISABLED
Definition: sip_msg.h:324
unsigned PJMEDIA_PIA_BITS(const pjmedia_port_info *pia)
pjmedia_type type
Definition: pjsua-lib/pjsua.h:4415
unsigned pjmedia_avi_streams_get_num_streams(pjmedia_avi_streams *streams)
void * pjsip_hdr_clone(pj_pool_t *pool, const void *hdr)
Definition: sip_module.h:54
void * ext_info
Definition: sip_transport.h:1443
int pjsua_vid_win_id
Definition: pjsua-lib/pjsua.h:4347
pj_status_t pjmedia_tonegen_create2(pj_pool_t *pool, const pj_str_t *name, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, unsigned options, pjmedia_port **p_port)
pj_status_t pjmedia_splitcomb_set_channel(pjmedia_port *splitcomb, unsigned ch_num, unsigned options, pjmedia_port *port)
pj_status_t pj_thread_sleep(unsigned msec)
PJMEDIA_TYPE_VIDEO
pjsip_generic_string_hdr * pjsip_generic_string_hdr_create(pj_pool_t *pool, const pj_str_t *hname, const pj_str_t *hvalue)
struct pjsua_call_media_info::@36::@37 aud
pjsip_endpoint * pjsua_get_pjsip_endpt(void)
unsigned rem_vid_cnt
Definition: pjsua-lib/pjsua.h:4533
const char * pjsip_event_str(pjsip_event_id_e e)
pj_qos_type qos_type
Definition: sip_transport_tls.h:253
Definition: sip_transaction.h:68
pjmedia_endpt * pjsua_get_pjmedia_endpt(void)
Definition: pjsua-lib/pjsua.h:742
pjsua_call_id id
Definition: pjsua-lib/pjsua.h:4456
PJ_SUCCESS
const char * pj_ssl_cipher_name(pj_ssl_cipher cipher)
struct pjsua_call_media_info::@36::@38 vid
void pj_cli_telnet_cfg_default(pj_cli_telnet_cfg *param)
pj_status_t pjsua_enum_calls(pjsua_call_id ids[], unsigned *count)
pjsip_redirect_op
Definition: sip_util.h:80
pjsua_call_media_status media_status
Definition: pjsua-lib/pjsua.h:4495
pj_str_t name
Definition: sip_msg.h:996
Definition: sip_types.h:185
unsigned short pj_uint16_t
void pj_cli_cfg_default(pj_cli_cfg *param)
pj_status_t pjsua_player_get_port(pjsua_player_id id, pjmedia_port **p_port)
Definition: pjsua-lib/pjsua.h:2580
pj_status_t pjsua_call_get_info(pjsua_call_id call_id, pjsua_call_info *info)
int pjsua_call_get_vid_stream_idx(pjsua_call_id call_id)
void pjsip_generic_string_hdr_init2(pjsip_generic_string_hdr *h, pj_str_t *hname, pj_str_t *hvalue)
Definition: pjsua-lib/pjsua.h:5501
pjsip_method method
Definition: sip_msg.h:382
PJ_FALSE
Definition: sip_inv.h:93
pj_status_t pjsua_player_set_pos(pjsua_player_id id, pj_uint32_t samples)
pj_status_t pjsua_acc_add(const pjsua_acc_config *acc_cfg, pj_bool_t is_default, pjsua_acc_id *p_acc_id)
#define PJ_UNUSED_ARG(arg)
pj_status_t pjsua_call_answer2(pjsua_call_id call_id, const pjsua_call_setting *opt, unsigned code, const pj_str_t *reason, const pjsua_msg_data *msg_data)
Definition: sip_transaction.h:80
Definition: sip_event.h:61
unsigned rem_aud_cnt
Definition: pjsua-lib/pjsua.h:4530
Definition: pjsua_internal.h:208
pj_status_t pjsua_conf_connect(pjsua_conf_port_id source, pjsua_conf_port_id sink)
int status_code
Definition: sip_transaction.h:108
Definition: sip_module.h:211

 


PJSIP Open Source, high performance, small footprint, and very very portable SIP stack
Copyright (C) 2006-2008 Teluu Inc.