Home --> Documentations --> PJSIP Reference
This is a very simple SIP User Agent application that only use PJSIP (without PJSIP-UA). It's able to make and receive call, and play media to the sound device.
59#include <pjlib-util.h>
63#define THIS_FILE "simpleua.c"
69#define AF pj_AF_INET()
80#define MAX_MEDIA_CNT 2
102static pjmedia_stream *g_med_stream;
105#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
106static pjmedia_vid_stream *g_med_vstream;
140 { "mod-simpleua", 12 },
158 PJ_LOG(4,(THIS_FILE, "RX %d bytes %s from %s %s:%d:\n"
183 PJ_LOG(4,(THIS_FILE, "TX %d bytes %s to %s %s:%d:\n"
202 { "mod-msg-log", 13 },
224int main( int argc, char *argv[])
248 const char *endpt_name;
256 endpt_name = hostname-> ptr;
289 app_perror(THIS_FILE, "Unable to start UDP transport", status);
373#if defined(PJMEDIA_HAS_G711_CODEC) && PJMEDIA_HAS_G711_CODEC!=0
379#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
390#if PJMEDIA_HAS_VIDEO && PJMEDIA_HAS_VID_TOOLBOX_CODEC
395# if defined(PJMEDIA_HAS_OPENH264_CODEC) && PJMEDIA_HAS_OPENH264_CODEC != 0
400# if defined(PJMEDIA_HAS_VPX_CODEC) && PJMEDIA_HAS_VPX_CODEC != 0
405# if defined(PJMEDIA_HAS_FFMPEG_VID_CODEC) && PJMEDIA_HAS_FFMPEG_VID_CODEC!=0
425 &g_med_transport[i]);
427 app_perror(THIS_FILE, "Unable to create media transport", status);
439 pj_memcpy(&g_sock_info[i], &g_med_tpinfo[i].sock_info,
457 app_perror(THIS_FILE, "Unable to retrieve local host IP", status);
462 pj_ansi_sprintf(temp, "<sip:simpleuac@%s:%d>",
474 app_perror(THIS_FILE, "Unable to create UAC dialog", status);
561 PJ_LOG(3,(THIS_FILE, "Ready to accept incoming calls..."));
566 for (;!g_complete;) {
572 dump_pool_usage(THIS_FILE, &cp);
581#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
592#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
597# if defined(PJMEDIA_HAS_FFMPEG_VID_CODEC) && PJMEDIA_HAS_FFMPEG_VID_CODEC!=0
600# if defined(PJMEDIA_HAS_OPENH264_CODEC) && PJMEDIA_HAS_OPENH264_CODEC != 0
603# if PJMEDIA_HAS_VIDEO && PJMEDIA_HAS_VID_TOOLBOX_CODEC
606# if defined(PJMEDIA_HAS_VPX_CODEC) && PJMEDIA_HAS_VPX_CODEC != 0
613 for (i = 0; i < MAX_MEDIA_CNT; ++i) {
614 if (g_med_transport[i])
651 PJ_LOG(3,(THIS_FILE, "Call DISCONNECTED [reason=%d (%s)]",
655 PJ_LOG(3,(THIS_FILE, "One call completed, application quitting..."));
660 PJ_LOG(3,(THIS_FILE, "Call state changed to %s",
689 unsigned options = 0;
729 pj_str_t reason = pj_str( "Sorry Simple UA can not handle this INVITE");
741 app_perror(THIS_FILE, "Unable to retrieve local host IP", status);
746 pj_ansi_sprintf(temp, "<sip:simpleuas@%s:%d>",
768 MAX_MEDIA_CNT, g_sock_info, &local_sdp);
851 app_perror(THIS_FILE, "SDP negotiation has failed", status);
870 local_sdp, remote_sdp, 0);
872 app_perror(THIS_FILE, "Unable to create audio stream info",status);
885 g_med_transport[0], NULL, &g_med_stream);
887 app_perror( THIS_FILE, "Unable to create audio stream", status);
894 app_perror( THIS_FILE, "Unable to start audio stream", status);
911 PJMEDIA_AUD_DEFAULT_CAPTURE_DEV,
912 PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV,
921 app_perror( THIS_FILE, "Unable to create sound port", status);
922 PJ_LOG(3,(THIS_FILE, "%d %d %d %d",
938#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
948 local_sdp, remote_sdp, 1);
950 app_perror(THIS_FILE, "Unable to create video stream info",status);
963 g_med_transport[1], NULL,
966 app_perror( THIS_FILE, "Unable to create video stream", status);
973 app_perror( THIS_FILE, "Unable to start video stream", status);
985 app_perror(THIS_FILE, "Unable to get default param of video "
986 "renderer device", status);
1004 app_perror(THIS_FILE, "Unable to create video renderer device",
1013 app_perror(THIS_FILE, "Unable to connect renderer to stream",
1025 app_perror(THIS_FILE, "Unable to get default param of video "
1026 "capture device", status);
1044 app_perror(THIS_FILE, "Unable to create video capture device",
1053 app_perror(THIS_FILE, "Unable to connect capturer to stream",
1060 if (g_vid_renderer) {
1063 app_perror(THIS_FILE, "Unable to start video renderer",
1068 if (g_vid_capturer) {
1071 app_perror(THIS_FILE, "Unable to start video capturer",
pj_status_t pjlib_util_init(void)
pj_status_t pjmedia_endpt_create(pj_pool_factory *pf, pj_ioqueue_t *ioqueue, unsigned worker_cnt, pjmedia_endpt **p_endpt)
pj_status_t pjmedia_endpt_create_sdp(pjmedia_endpt *endpt, pj_pool_t *pool, unsigned stream_cnt, const pjmedia_sock_info sock_info[], pjmedia_sdp_session **p_sdp)
pj_pool_t * pjmedia_endpt_create_pool(pjmedia_endpt *endpt, const char *name, pj_size_t initial, pj_size_t increment)
pj_status_t pjmedia_endpt_destroy(pjmedia_endpt *endpt)
pj_status_t pjmedia_codec_g711_init(pjmedia_endpt *endpt)
pj_status_t pjmedia_snd_port_connect(pjmedia_snd_port *snd_port, pjmedia_port *port)
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)
pj_status_t pjmedia_snd_port_destroy(pjmedia_snd_port *snd_port)
struct pjmedia_snd_port pjmedia_snd_port
pj_status_t pjmedia_stream_create(pjmedia_endpt *endpt, pj_pool_t *pool, const pjmedia_stream_info *info, pjmedia_transport *tp, void *user_data, pjmedia_stream **p_stream)
pj_status_t pjmedia_stream_start(pjmedia_stream *stream)
pj_status_t pjmedia_stream_destroy(pjmedia_stream *stream)
pj_status_t pjmedia_stream_get_port(pjmedia_stream *stream, pjmedia_port **p_port)
pj_status_t pjmedia_vid_stream_info_from_sdp(pjmedia_vid_stream_info *si, pj_pool_t *pool, pjmedia_endpt *endpt, const pjmedia_sdp_session *local, const pjmedia_sdp_session *remote, unsigned stream_idx)
pj_status_t pjmedia_vid_stream_destroy(pjmedia_vid_stream *stream)
pj_status_t pjmedia_vid_stream_get_port(pjmedia_vid_stream *stream, pjmedia_dir dir, pjmedia_port **p_port)
pj_status_t pjmedia_vid_stream_start(pjmedia_vid_stream *stream)
pj_status_t pjmedia_vid_stream_create(pjmedia_endpt *endpt, pj_pool_t *pool, pjmedia_vid_stream_info *info, pjmedia_transport *tp, void *user_data, pjmedia_vid_stream **p_stream)
pj_status_t pjsip_100rel_init_module(pjsip_endpoint *endpt)
void pjsip_dlg_dec_lock(pjsip_dialog *dlg)
pj_status_t pjsip_dlg_create_uac(pjsip_user_agent *ua, const pj_str_t *local_uri, const pj_str_t *local_contact, const pj_str_t *remote_uri, const pj_str_t *target, pjsip_dialog **p_dlg)
pj_status_t pjsip_dlg_create_uas_and_inc_lock(pjsip_user_agent *ua, pjsip_rx_data *rdata, const pj_str_t *contact, pjsip_dialog **p_dlg)
pj_status_t pjsip_endpt_respond_stateless(pjsip_endpoint *endpt, pjsip_rx_data *rdata, int st_code, const pj_str_t *st_text, const pjsip_hdr *hdr_list, const pjsip_msg_body *body)
void pjsip_endpt_destroy(pjsip_endpoint *endpt)
pj_status_t pjsip_endpt_register_module(pjsip_endpoint *endpt, pjsip_module *module)
pj_ioqueue_t * pjsip_endpt_get_ioqueue(pjsip_endpoint *endpt)
pj_status_t pjsip_endpt_handle_events(pjsip_endpoint *endpt, const pj_time_val *max_timeout)
pj_status_t pjsip_endpt_create(pj_pool_factory *pf, const char *name, pjsip_endpoint **endpt)
pj_status_t pjsip_inv_send_msg(pjsip_inv_session *inv, pjsip_tx_data *tdata)
const char * pjsip_inv_state_name(pjsip_inv_state state)
pj_status_t pjsip_inv_create_uas(pjsip_dialog *dlg, pjsip_rx_data *rdata, const pjmedia_sdp_session *local_sdp, unsigned options, pjsip_inv_session **p_inv)
pj_status_t pjsip_inv_create_uac(pjsip_dialog *dlg, const pjmedia_sdp_session *local_sdp, unsigned options, pjsip_inv_session **p_inv)
pj_status_t pjsip_inv_invite(pjsip_inv_session *inv, pjsip_tx_data **p_tdata)
pj_status_t pjsip_inv_initial_answer(pjsip_inv_session *inv, pjsip_rx_data *rdata, int st_code, const pj_str_t *st_text, const pjmedia_sdp_session *sdp, pjsip_tx_data **p_tdata)
pj_status_t pjsip_inv_verify_request(pjsip_rx_data *rdata, unsigned *options, const pjmedia_sdp_session *sdp, pjsip_dialog *dlg, pjsip_endpoint *endpt, pjsip_tx_data **tdata)
pj_status_t pjsip_inv_answer(pjsip_inv_session *inv, int st_code, const pj_str_t *st_text, const pjmedia_sdp_session *local_sdp, pjsip_tx_data **p_tdata)
pj_status_t pjsip_inv_usage_init(pjsip_endpoint *endpt, const pjsip_inv_callback *cb)
@ PJSIP_INV_STATE_DISCONNECTED Definition: sip_inv.h:95
@ PJSIP_MOD_PRIORITY_APPLICATION Definition: sip_module.h:210
@ PJSIP_MOD_PRIORITY_TRANSPORT_LAYER Definition: sip_module.h:190
const pj_str_t * pjsip_get_status_text(int status_code)
@ PJSIP_ACK_METHOD Definition: sip_msg.h:58
@ PJSIP_INVITE_METHOD Definition: sip_msg.h:56
pj_status_t pjsip_tsx_layer_init_module(pjsip_endpoint *endpt)
pj_status_t pjsip_udp_transport_start(pjsip_endpoint *endpt, const pj_sockaddr_in *local, const pjsip_host_port *a_name, unsigned async_cnt, pjsip_transport **p_transport)
pj_status_t pjsip_udp_transport_start6(pjsip_endpoint *endpt, const pj_sockaddr_in6 *local, const pjsip_host_port *a_name, unsigned async_cnt, pjsip_transport **p_transport)
char * pjsip_rx_data_get_info(pjsip_rx_data *rdata)
char * pjsip_tx_data_get_info(pjsip_tx_data *tdata)
struct pjsip_endpoint pjsip_endpoint Definition: sip_types.h:111
pj_status_t pjsip_ua_init_module(pjsip_endpoint *endpt, const pjsip_ua_init_param *prm)
pjsip_user_agent * pjsip_ua_instance(void)
pj_status_t pj_init(void)
unsigned short pj_uint16_t
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
#define PJ_LOG(level, arg)
void pj_log_set_level(int level)
pj_pool_factory_policy pj_pool_factory_default_policy
void pj_pool_release(pj_pool_t *pool)
void * pj_memcpy(void *dst, const void *src, pj_size_t size)
pj_str_t pj_str(char *str)
void pj_bzero(void *dst, pj_size_t size)
pj_status_t pj_sockaddr_init(int af, pj_sockaddr *addr, const pj_str_t *cp, pj_uint16_t port)
char * pj_sockaddr_print(const pj_sockaddr_t *addr, char *buf, int size, unsigned flags)
#define PJ_INET6_ADDRSTRLEN
const pj_str_t * pj_gethostname(void)
pj_status_t pj_gethostip(int af, pj_sockaddr *addr)
#define PJ_ASSERT_RETURN(expr, retval)
#define PJ_UNUSED_ARG(arg)
pj_status_t pjmedia_vid_dev_default_param(pj_pool_t *pool, pjmedia_vid_dev_index id, pjmedia_vid_dev_param *param)
pj_status_t pjmedia_vid_dev_subsys_init(pj_pool_factory *pf)
PJMEDIA_VID_DEFAULT_CAPTURE_DEV
PJMEDIA_VID_DEFAULT_RENDER_DEV
char * start Definition: sip_types.h:207
char * cur Definition: sip_types.h:212
Definition: sip_dialog.h:136
pj_pool_t * pool Definition: sip_dialog.h:142
Definition: sip_event.h:81
Definition: sip_inv.h:115
void(* on_new_session)(pjsip_inv_session *inv, pjsip_event *e) Definition: sip_inv.h:141
void(* on_state_changed)(pjsip_inv_session *inv, pjsip_event *e) Definition: sip_inv.h:127
void(* on_media_update)(pjsip_inv_session *inv_ses, pj_status_t status) Definition: sip_inv.h:243
Definition: sip_inv.h:431
pjsip_status_code cause Definition: sip_inv.h:440
pjsip_dialog * dlg Definition: sip_inv.h:446
pjmedia_sdp_neg * neg Definition: sip_inv.h:449
pjsip_inv_state state Definition: sip_inv.h:436
pj_pool_t * pool Definition: sip_inv.h:433
pjsip_method_e id Definition: sip_msg.h:78
Definition: sip_module.h:54
struct pjsip_request_line req Definition: sip_msg.h:868
union pjsip_msg::@19 line
pjsip_method method Definition: sip_msg.h:434
Definition: sip_transport.h:295
pjsip_transport * transport Definition: sip_transport.h:307
int src_port Definition: sip_transport.h:346
struct pjsip_rx_data::@26 msg_info
char src_name[PJ_INET6_ADDRSTRLEN] Definition: sip_transport.h:343
struct pjsip_rx_data::@25 pkt_info
struct pjsip_rx_data::@24 tp_info
pj_pool_t * pool Definition: sip_transport.h:304
pj_ssize_t len Definition: sip_transport.h:334
pjsip_msg * msg Definition: sip_transport.h:364
char * msg_buf Definition: sip_transport.h:358
char * type_name Definition: sip_transport.h:821
Definition: sip_transport.h:522
char dst_name[PJ_INET6_ADDRSTRLEN] Definition: sip_transport.h:614
pjsip_transport * transport Definition: sip_transport.h:611
int dst_port Definition: sip_transport.h:615
struct pjsip_tx_data::@29 tp_info
pjsip_buffer buf Definition: sip_transport.h:568
PJSIP Open Source, high performance, small footprint, and very very portable SIP stack
Copyright (C) 2006-2008 Teluu Inc.
|