freeswitch 自学杂记

来源:互联网 发布:数据采集卡和plc对比 编辑:程序博客网 时间:2024/06/07 06:50

1、入口: src/switch.c 中的main函数
|_调用src/switch_core.c中的switch_core_init_and_modload()函数,初始化并加载所有的module,
| |_首先调用src/switch_core.c中的switch_core_init,bindsocket,建立sql、任务、事件线程
| |_src/switch_loadable_module.c 调用switch_loadable_module_init
switch_xml_init初始入freeswitch.xml,主要通过函数__switch_xml_open_root调用switch_xml_parse_file,保存于MAIN_XML_ROOT,

2、设置log
switch_core_init设置了读取switch.conf.xml中的,设置runtime.hard_log_level,此处为所有的Log的总出口。后面不同输出还可再过滤。如控制台的。释放 可开启debug(对应控制台命令fsctl loglevel)
mod_console实现控制台log功能, console.conf.xml 为此模块配置文件,默认为info.(console loglevel 7)

sofia log 见
https://freeswitch.org/confluence/display/FREESWITCH/Sofia+SIP+Stack

log控制
logfile.conf.xml

3、认证
修改conf\sip_profiles中的对应配置,如:internal.xml
呼叫无 认证

 <param name="accept-blind-auth" value="true"/>

注册无认证

<param name="accept-blind-reg" value="true"/>

subscrible有认证

<param name="auth-subscriptions" value="true"/>

message有认证

<param name="auth-messages" value="true"/>

4、fs_cli -x 允许执行一条命令后退出,fs_cli连接到其它机器
http://www.360doc.com/content/13/1213/14/12747488_336851982.shtml

5、一些变量赋值
sofia_event_callback调用函数switch_core_session_request 产生session,函数调用switch_channel_init产生channel。

void sofia_handle_sip_i_invite调用函数switch_caller_profile_new,产生一个新的profile,调用switch_channel_set_caller_profile赋值、并替换旧的profile.

6、dailplan分析
当没有配置dpln时,使用conf/sip_profiles/默认的。改成default比较好。如internal.xml

<param name="context" value="public"/>

dpln中的解析,括号前面为函数,后面为参数。函数执行的结果放于stream.data,最后会接在data的后面。data就是最后的返回值。
dpln data中的group对应的函数为mod_commands.c 中的group_call_function。
dpln data中的sofia_contact对应的函数为mod_sofia.c 中的sofia_contact_function。
dpln data中的strftime对应的函数为smod_dptools.c中的trftime_api_function

dpln application中的bridge对应的函数为mod_dptools.c中的audio_bridge_function

switch_core_session_exec函数调用switch_loadable_module_get_application_interface取得dpln中的application参数的值指定的函数,通过switch_channel_expand_variables_check进行data参数解析,如果data中有函数调用,在switch_api_execute调用switch_loadable_module_get_api_interface,取得data中的函数对应的指针进行执行。

switch_loadable_module_get_endpoint_interface 函数取得处理ep 的对象,如sofia开头的指向sofia_endpoint_interface, user 开头的指向user_endpoint_interface

7、rtp IP地址修改Profile
如external.xml

    <param name="rtp-ip" value="$${local_ip_v4}"/>    <param name="sip-ip" value="$${local_ip_v4}"/>    <param name="ext-rtp-ip" value="auto-nat"/>    <param name="ext-sip-ip" value="auto-nat"/>

8、fs呼数限制
switch.conf.xml

 <param name="max-sessions" value="2000"/>    <!--Most channels to create per second -->    <param name="sessions-per-second" value="2000"/>

9、介绍模块
mod_hash、 hash函数
mod_sofia SIP协议栈
mod_sndfile 录音存为{ “r8”, “r16”, “r24”, “r32”, “gsm”, “ul”, “ulaw”, “al”, “alaw”, “adpcm”, “vox”, “oga”, “ogg”, NULL };后缀时
mod_dptools xml中的拔号相关
mod_command group呼时用到
mod_native_file 原生录音
须编译mod_console,控制台才能生效
须编译mod_dialplan_xml,呼叫才能路由xml

10、FS能自动替换RTP的源IP做为目的IP
自动调整的功能默认是开启的,可在Profile中禁用:

<param name="disable-rtp-auto-adjust" value="true"/>

或者仅针对个别的呼叫来禁用自动调整,在呼叫时设置通道变量来禁止。

<action application="set" data="disable_rtp_auto_adjust=true"/>

默认收到10RTP包才调整,修改如下:

<action application="set" data="rtp_auto_adjust_threshold=10"/>

11、sofia 注册相关
mod_sofia_globals.max_msg_queues保存sofia能建几个消息队列,在mod_sofia_load中初始,最大为mod_sofia_globals.max_msg_queues = SOFIA_MAX_MSG_QUEUE
最小为2,一般为CPU数/2+1
每个消息队列存放的消息个数为SOFIA_MSG_QUEUE_SIZE* mod_sofia_globals.max_msg_queues
SOFIA_MAX_MSG_QUEUE定义为64
SOFIA_MSG_QUEUE_SIZE定义为1000
mod_sofia_globals.msg_queue_len保存当前消息使用第几个消息队列
以上即每个线程能处理1000个消息。

sofia_queue_message函数中,mod_sofia_globals.msg_queue超过当前的线程数*SOFIA_MSG_QUEUE_SIZE,就会在sofia_msg_thread_start新建线程。
sofia_msg_thread_start函数中,检查mod_sofia_globals.msg_queue_len>=mod_sofia_globals.max_msg_queues 就不再建线程了。

如果xml中配置了inbound-reg-in-new-thread 注册使用新的线程,线程数不超过xml中指定的max-reg-threads,这个线程不统计在mod_sofia_globals.max_msg_queues.因为这个消息不会放在mod_sofia_globals.msg_queue中。如果这步达到线程保合,就还走旧的方式。

还有一点要注意的是,在上面的入口函数sofia_event_callback中,mod_sofia_globals.msg_queue队列如果>(((SOFIA_MSG_QUEUE_SIZE * mod_sofia_globals.max_msg_queues) * 900) / 1000),系统就会回503.

可修改internal.xml中去掉presence,,manage-presence 同时更换DB,提升注册能力

<parem name="dbname" value="/dev/shm/sofia_internal.db">

12、压力测试配置
https://wiki.freeswitch.org/wiki/Performance_testing_and_configurations

13、FreeSWITCH修改头,指定代理添,加请求头,响应头,自定义头等
http://www.freeswitch.net.cn/57.html

14、建立模块
https://freeswitch.org/confluence/display/FREESWITCH/Creating+New+Modules