Location>code7788 >text

pjsip compilation, description and vs2022 usage examples

Popularity:153 ℃/2024-11-12 21:12:33

Document Address:/en/latest/

1. Download pjsip source code

Download Address:/

It can also be downloaded directly from the github address given on the pjsip website:
/pjsip/pjproject/archive/refs/tags/2.14.

2. Compiling with VS2022

double-click
To prevent compilation errors, first enter this directory:
pjproject-2.14.1\pjlib\include\pj
Copy the file config_site_sample.h config_site.h

Compile:

II. Description of the data structure

Here is a list of data structures commonly used by pjsua.
1)pjsua_config
Mainly used to configure UA callback functions.
2)pjsua_logging_config
Used to configure logging properties
3)pjsua_transport_config
Used to configure the socket properties of the local binding, such as listening port.
4)pjsua_acc_config
Used to configure sip account information, such as username, password, registered address, etc.

III. Description of interfaces

Here is a list of common interfaces to pjsua.
 
1)pjsua_create

functionality

Creates an instance of pjsua, which needs to be called before any other function can be called;
The pjsua_destroy function needs to be called when use is complete (when PJ_SUCCESS is returned).
The full statement is below:
pj_status_t pjsua_create(void)

parameters

not have

return value

PJ_SUCCESS , Success
Other values, Fail
 
2)pjsua_config_default

functionality

Used to initialize the pjsua configuration.
The full statement is below:
void pjsua_config_default(pjsua_config *cfg)

parameters

cfg : initializedpjsuaConfiguration pointer

return value

not have
 
3)pjsua_logging_config_default

functionality

Used to initialize pjsua's logging configuration.
The full statement is below:
void pjsua_logging_config_default(pjsua_logging_config *cfg)

parameters

cfg : initializedpjsuaLog Configuration Pointer

return value

not have
4)pjsua_init

functionality

Initializes pjsua with the specified configuration. All configuration parameters are optional, and the default configuration is used if no relevant configuration is specified.
The full statement is below:
pj_status_t pjsua_init(const pjsua_config *ua_cfg, const pjsua_logging_config *log_cfg, const pjsua_media_config *media_cfg)

parameters

ua_cfg : user agent configuration
log_cfg : log configuration
media_cfg : media configuration

return value

PJ_SUCCESS : Success
Other values: Failure
5)pjsua_transport_config_default

functionality

Initialize udp configuration information.
The full statement is below:
void pjsua_transport_config_default(pjsua_transport_config *cfg)

parameters

cfg : initializedudpConfiguration pointer

return value

not have
 
6)pjsua_transport_create

functionality

Create and start sip transport based on the incoming configuration information (it will bind the local sip port and do socket listening).
The full statement is below:
pj_status_t pjsua_transport_create(pjsip_transport_type_e type, const pjsua_transport_config *cfg, pjsua_transport_id *p_id)

parameters

type : transport type, optional parameters are PJSIP_TRANSPORT_UDP, PJSIP_TRANSPORT_TCP, PJSIP_TRANSPORT_TLS and so on.
cfg : udp configuration to be used.
p_id : Optional parameter, used to receive the transport ID.

return value

PJ_SUCCESS : Success
Other values: Failure
 7)pjsua_start

functionality

Start the pjsua instance.
The full statement is below:
pj_status_t pjsua_start(void)

parameters

not have

return value

PJ_SUCCESS : Success
Other values: Failure
8)pjsua_acc_config_default

functionality

Initialize pjsua's account information.
The full statement is below:
void pjsua_acc_config_default(pjsua_acc_config *cfg)

parameters

cfg : initializedpjsuaAccount Configuration

return value

not have
 
9)pjsua_acc_add
functionality
Add a pjsua account and register.
The full statement is below:
pj_status_t pjsua_acc_add(const pjsua_acc_config *acc_cfg, pj_bool_t is_default, pjsua_acc_id *p_acc_id)

parameters

acc_cfg : account configuration information, such as sip account id, password, registered address, etc.
is_default : whether it is the default account
p_acc_id : Used to receive account id data.

return value

PJ_SUCCESS : Success
Other values: Failure
 
10)pjsua_call_make_call

functionality

The sip uri format is required for outbound calls using the specified account.
The full statement is below:
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)

parameters

acc_id : account id
dst_uri : the sip uri of the outgoing call, for example sip:1000@192.168.137.100:5060
opt : Call setup
user_data : User data to be attached.
msg_data : Extended header in INVITE request, not set if NULL.
p_call_id : Pointer to receive call id.

return value

PJ_SUCCESS : Success
Other values: Failure
 
11)pjsua_msg_data_init
functionality
Initialize data of type pjsua_msg_data.
The full statement is below:
void pjsua_msg_data_init(pjsua_msg_data *msg_data)

parameters

msg_data : Variables to be initialized

return value

not have
 
12)pjsua_call_hangup

functionality

Hang up operation to hang up the specified call.
The full statement is below:
pj_status_t pjsua_call_hangup(pjsua_call_id call_id, unsigned code, const pj_str_t *reason, const pjsua_msg_data *msg_data)

parameters

call_id : call id of the call that needs to be hung up
code : hangup sip status code, such as200603 etc.
reason : reason for hanging up
msg_data : message header to be added

return value

PJ_SUCCESS : Success
Other values: Failure

IV. MFC-based examples

Here based on MFC to realize a simple soft phone, to achieve the registration, call, hang up and other basic functions.

Project Name: pjPhone

Project Catalog:

1. Add dependent libraries

Put the compiled lib library files in the depends directory:

2、Configure project properties

1) Configure the include directory;

The full content is available from the following sources:
Get it by replying to 20241112 after following WeChat (chatting about blogging, you can scan the code at the end of the article).
2) Configure the lib library directory;

The full content is available from the following sources:

Get it by replying to 20241112 after following WeChat (chatting about blogging, you can scan the code at the end of the article).
3) Configure the link lib library;

The full content is available from the following sources:

Get it by replying to 20241112 after following WeChat (chatting about blogging, you can scan the code at the end of the article).

3. Compilation and use

Static chain linking is used here and no additional dll files are required after compilation.
The compiled binary can be run directly.
1) Registration effect

2) Call effect

 3) Answering effect

The runnable binary () and the packaged project file (pjsipTest2-vs2022.7z) are available from the sources provided at the end of the article.

V. Access to resources

The resources covered in this article are available from the following sources:
Get it by replying to 20241112 after following WeChat (chatting about blogging, you can scan the code at the end of the article).