标签:des blog http io ar color os 使用 sp
一个SIP UA不外乎包括如下几方面:
1 账号管理——包括number,display,authentication name,password,domain,registrar,proxy,outbound-proxy
2 账号注册和注销
3 主叫管理——键盘事件处理、发起呼叫、暂挂(hold)、多路呼叫
4 被叫管理——暂挂、多路呼叫管理、前转、后转
5 语音数据编改码和传输
6 视频数据编改码和传输
只要沿着这几方面仔细去分析,我想分析起代码来比较有思路了。
app_restart是一个pj_bool_t的类型,pj_bool_t在pjlib/include/pj/types.h中定义:
app_restart是一个全局变量,在pjsip-apps/src/pjsua/pjsua_app.c中定义:
PJSUA的main函数中使用了pjsua_app.c中的app_init函数来进行初始化,该函数体如下:
该函数虽然比较长,但只要硬着头皮看下去,相信会掌握pjsua中的大部分主要结构,努力吧。
在app_init函数中,我们看到使用pjsua_create函数来创建pjsua的实例,如下:
接下来,我们来分析该函数。
该函数定义如下:pjsua_core.c
一 init_data函数:pjsua_core.c
该函数主要初始化pjsua_var全局变量,pjsua_var的定义如下:pjsua_core.c
接下来需要好好分析struct pjsua_data这个结构的定义了,因为这个数据结构是pjsua的核心数据结构,定义如下:
init_date函数的最后调用pjsua_config_default函数初始化pjsua_var.ua_cfg,这个成员的类型是struct pjsua_config,定义如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
/** * This structure describes the settings to control the API and * user agent behavior, and can be specified when calling #pjsua_init(). * Before setting the values, application must call #pjsua_config_default() * to initialize this structure with the default values. */ typedef struct pjsua_config { /** * Maximum calls to support (default: 4). The value specified here * must be smaller than the compile time maximum settings * PJSUA_MAX_CALLS, which by default is 32. To increase this * limit, the library must be recompiled with new PJSUA_MAX_CALLS * value. */ unsigned max_calls; /** * Number of worker threads. Normally application will want to have at * least one worker thread, unless when it wants to poll the library * periodically, which in this case the worker thread can be set to * zero. */ unsigned thread_cnt; /** * Number of nameservers. If no name server is configured, the SIP SRV * resolution would be disabled, and domain will be resolved with * standard pj_gethostbyname() function. */ unsigned nameserver_count; /** * Array of nameservers to be used by the SIP resolver subsystem. * The order of the name server specifies the priority (first name * server will be used first, unless it is not reachable). */ pj_str_t nameserver[4]; /** * Force loose-route to be used in all route/proxy URIs (outbound_proxy * and account‘s proxy settings). When this setting is enabled, the * library will check all the route/proxy URIs specified in the settings * and append ";lr" parameter to the URI if the parameter is not present. * * Default: 1 */ pj_bool_t force_lr; /** * Number of outbound proxies in the \a outbound_proxy array. */ unsigned outbound_proxy_cnt; /** * Specify the URL of outbound proxies to visit for all outgoing requests. * The outbound proxies will be used for all accounts, and it will * be used to build the route set for outgoing requests. The final * route set for outgoing requests will consists of the outbound proxies * and the proxy configured in the account. */ pj_str_t outbound_proxy[4]; /** * Warning: deprecated, please use \a stun_srv field instead. To maintain * backward compatibility, if \a stun_srv_cnt is zero then the value of * this field will be copied to \a stun_srv field, if present. * * Specify domain name to be resolved with DNS SRV resolution to get the * address of the STUN server. Alternatively application may specify * \a stun_host instead. * * If DNS SRV resolution failed for this domain, then DNS A resolution * will be performed only if \a stun_host is specified. */ pj_str_t stun_domain; /*指定stun服务器的域名,已过时,这儿是为了兼容才存在。*/ /*最好使用stun_srv*/ /** * Warning: deprecated, please use \a stun_srv field instead. To maintain * backward compatibility, if \a stun_srv_cnt is zero then the value of * this field will be copied to \a stun_srv field, if present. * * Specify STUN server to be used, in "HOST[:PORT]" format. If port is * not specified, default port 3478 will be used. */ pj_str_t stun_host; /*stun服务器的ip地址和端口,也已过时。*/ /** * Number of STUN server entries in \a stun_srv array. */ unsigned stun_srv_cnt; /** * Array of STUN servers to try. The library will try to resolve and * contact each of the STUN server entry until it finds one that is * usable. Each entry may be a domain name, host name, IP address, and * it may contain an optional port number. For example: * - "pjsip.org" (domain name) * - "sip.pjsip.org" (host name) * - "pjsip.org:33478" (domain name and a non-standard port number) * - "10.0.0.1:3478" (IP address and port number) * * When nameserver is configured in the \a pjsua_config.nameserver field, * if entry is not an IP address, it will be resolved with DNS SRV * resolution first, and it will fallback to use DNS A resolution if this * fails. Port number may be specified even if the entry is a domain name, * in case the DNS SRV resolution should fallback to a non-standard port. * * When nameserver is not configured, entries will be resolved with * #pj_gethostbyname() if it‘s not an IP address. Port number may be * specified if the server is not listening in standard STUN port. */ pj_str_t stun_srv[8]; /*stun服务器主要使用的是这个*/ /** * This specifies if the library startup should ignore failure with the * STUN servers. If this is set to PJ_FALSE, the library will refuse to * start if it fails to resolve or contact any of the STUN servers. * * Default: PJ_TRUE */ pj_bool_t stun_ignore_failure; /** * Support for adding and parsing NAT type in the SDP to assist * troubleshooting. The valid values are: * - 0: no information will be added in SDP, and parsing is disabled. * - 1: only the NAT type number is added. * - 2: add both NAT type number and name. * * Default: 1 */ int nat_type_in_sdp; /** * Specify whether support for reliable provisional response (100rel and * PRACK) should be required by default. Note that this setting can be * further customized in account configuration (#pjsua_acc_config). * * Default: PJ_FALSE */ pj_bool_t require_100rel; /** * Specify the usage of Session Timers for all sessions. See the * #pjsua_sip_timer_use for possible values. Note that this setting can be * further customized in account configuration (#pjsua_acc_config). * * Default: PJSUA_SIP_TIMER_OPTIONAL */ pjsua_sip_timer_use use_timer; /** * Handle unsolicited NOTIFY requests containing message waiting * indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests * which are not requested by client with SUBSCRIBE request. * * If this is enabled, the library will respond 200/OK to the NOTIFY * request and forward the request to \a on_mwi_info() callback. * * See also \a mwi_enabled field #on pjsua_acc_config. * * Default: PJ_TRUE * */ pj_bool_t enable_unsolicited_mwi; /** * Specify Session Timer settings, see #pjsip_timer_setting. * Note that this setting can be further customized in account * configuration (#pjsua_acc_config). */ pjsip_timer_setting timer_setting; /** * Number of credentials in the credential array. */ unsigned cred_count; /** * Array of credentials. These credentials will be used by all accounts, * and can be used to authenticate against outbound proxies. If the * credential is specific to the account, then application should set * the credential in the pjsua_acc_config rather than the credential * here. */ pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES]; /** * Application callback to receive various event notifications from * the library. */ pjsua_callback cb; /** * Optional user agent string (default empty). If it‘s empty, no * User-Agent header will be sent with outgoing requests. */ pj_str_t user_agent; #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) /** * Specify default value of secure media transport usage. * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and * PJMEDIA_SRTP_MANDATORY. * * Note that this setting can be further customized in account * configuration (#pjsua_acc_config). * * Default: #PJSUA_DEFAULT_USE_SRTP */ pjmedia_srtp_use use_srtp; /** * Specify whether SRTP requires secure signaling to be used. This option * is only used when \a use_srtp option above is non-zero. * * Valid values are: * 0: SRTP does not require secure signaling * 1: SRTP requires secure transport such as TLS * 2: SRTP requires secure end-to-end transport (SIPS) * * Note that this setting can be further customized in account * configuration (#pjsua_acc_config). * * Default: #PJSUA_DEFAULT_SRTP_SECURE_SIGNALING */ int srtp_secure_signaling; /** * Specify whether SRTP in PJMEDIA_SRTP_OPTIONAL mode should compose * duplicated media in SDP offer, i.e: unsecured and secured version. * Otherwise, the SDP media will be composed as unsecured media but * with SDP "crypto" attribute. * * Default: PJ_FALSE */ pj_bool_t srtp_optional_dup_offer; #endif /** * Disconnect other call legs when more than one 2xx responses for * outgoing INVITE are received due to forking. Currently the library * is not able to handle simultaneous forked media, so disconnecting * the other call legs is necessary. * * With this setting enabled, the library will handle only one of the * connected call leg, and the other connected call legs will be * disconnected. * * Default: PJ_TRUE (only disable this setting for testing purposes). */ pj_bool_t hangup_forked_call; } pjsua_config; |
下面再看pjsua_config_default函数的定义:
该函数最后使用pjsip_timer_setting_default函数配置默认的会话定时器,如下:
1 池工厂
2 池
1 log配置结构
2 默认配置函数
标签:des blog http io ar color os 使用 sp
原文地址:http://www.cnblogs.com/matthew-2013/p/4157270.html