当前位置:网站首页>[freeswitch development practice] user defined module creation and use
[freeswitch development practice] user defined module creation and use
2022-07-26 08:37:00 【Pony driver】
Blog home page : The home page of the pony driver
My column :FreeSwitch Development practices
Column introduction : It mainly introduces the use of bloggers in actual projects FreeSwitch Some experience of developing outbound call projects , Mainly involves FreeSwitch Basic installation and compilation of 、 Basic configuration 、ESL、WSS、 sound recording 、 Custom module 、media bug、 Voice playback 、MRCP And docking AI Robots and so on . The content is constantly updated , If you are interested, you can subscribe to the column ~What you want to say to yourself in the futureIntermittent efforts and muddle through , It's all about clearing the previous efforts

List of articles
Preface
stay FreeSwitch In the framework of , There are many modules or interfaces , stay FreeSwitch called app and api, If the commonly used answer module answer、 Hang up the module hangup、 Sleep module sleep、 Echo module echo etc. , There are a lot of them , these app and api Together FreeSwitch At the heart of . However ,FreeSwitch It also provides the function of custom module , Developers can implement one by themselves according to the standard interface app, Then use , Greatly expand FreeSwitch The ability of , It is also convenient to realize specific functions in actual business .
> Introducing `FreeSwitch` Before customizing the module , First look at a complete ` Custom module ` Example , Then introduce the custom module for the code example :
#include <switch.h>
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_myapp_shutdown);
SWITCH_MODULE_LOAD_FUNCTION(mod_myapp_load);
// Module definition , Module loading 、 Module uninstall
SWITCH_MODULE_DEFINITION(mod_myapp, mod_myapp_load, mod_myapp_shutdown, NULL);
SWITCH_STANDARD_APP(myapp_function);
// Module loading
SWITCH_MODULE_LOAD_FUNCTION(mod_myapp_load)
{
switch_application_interface_t *app_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "myapp mod loaded.\n");
SWITCH_ADD_APP(app_interface, "myapp", "myapp", "myapp", myapp_function, "", SAF_NONE);
return SWITCH_STATUS_SUCCESS;
}
// Module uninstall
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_myapp_shutdown)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "myapp shutdown\n");
return SWITCH_STATUS_SUCCESS;
}
//myapp Execute function
SWITCH_STANDARD_APP(myapp_function)
{
switch_status_t status;
if (session == NULL)
return;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "myapp function start\n");
return;
}
One 、 Custom module loading and unloading
Through the code example of the above custom module , You can see that the custom module should at least be implemented 3 A standard interface :
- Module loading
SWITCH_MODULE_LOAD_FUNCTION(mod_myapp_load) - Module uninstall
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_myapp_shutdown)
The macro is defined as follows :
So the complete definition of module loading and unloading is as follows :
Module loading
switch_status_t mod_myapp_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
Module uninstall
switch_status_t mod_myapp_unload(void)
Two 、 Custom module "app" The creation of
Here's the key , Really usable app This interface implements :
switch_application_interface_t *app_interface;
SWITCH_ADD_APP(app_interface, "myapp", "myapp", "myapp", myapp_function, "", SAF_NONE);
It is the same as the creation and uninstallation of modules ,app Interface is also a macro definition :
Parameter description :
app_int | app Interface handle |
|---|---|
| int_name` | app name |
short_descript | app Short description |
long_descript | app Long description |
funcptr | app Callback function |
syntax_string | app Format string |
app_flags | app sign |
app Callback function
SWITCH_STANDARD_APP(myapp_function)
{
switch_status_t status;
if (session == NULL)
return;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "myapp function start\n");
return;
}
As above, let's first look at the macro definition :
#define SWITCH_STANDARD_APP(name) static void name (switch_core_session_t *session, const char *data)
Parameter description :
session | conversation session |
|---|---|
| data | app Parameters , Every app Can pass parameters |
app Callback functions can realize business specific functions , Such as :
- Start business thread
- add to media bug, Get the call voice stream
- Realize business cycle , For example, start. ASR/TSS
3、 ... and 、 Add a custom module to the dial plan app
Add the following code to FreeSwitch Catalog conf/dialplan/default.xml
<extension name="myapp-diaplan">
<condition field="destination_number" expression="^123$">
<action application="answer"/>
<action application="myapp"/>
<action application="echo" data=""/>
<action application="hangup" data=""/>
</condition>
</extension>
explain :
destination_numberDial plan expression string , Dial now “123” number , You can do it condition Dial up configurationanswerAnswer
-myappThis is the custom module we created earlier app
-echoecho app, because myapp Not blocking function , So want to use echo Program to block calls , Achieve the purpose of uninterrupted call
-hangupHang up
Four 、 Call test
start-up FreeSwitch, Use Yate register 1000 number , First look at the custom module myapp Load output :
Dial command :
originate user/1000 123
123It's the front Dial plan Configure the expression string
Output :
Last
That's what we have today , In detail FreeSwitch Create and use custom modules . If you feel some help or think the article is good , please Focus on What about bloggers , Your attention is the driving force of my continuous writing . in addition , If there are any questions , Leave a comment in the comments section , Or private bloggers , Bloggers will reply as soon as they see it .
边栏推荐
- Mycat2 deploy master-slave MariaDB
- [GUI] swing package (window, pop-up window, label, panel, button, list, text box)
- Add in the registry right click to open in vscode
- Shell programming
- OA项目之我的会议(会议排座&送审)
- Prefix infix suffix expression (written conversion)
- Guitar staff link Jasmine
- Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
- Day 3 homework
- MySQL 8.0 OCP 1z0-908 certification examination question bank 1
猜你喜欢

Write common API tools swagger and redoc

NLP (natural language processing) natural language processing learning

基于C语言设计的换乘指南打印系统

Matplotlib learning notes

Memory management - dynamic partition allocation simulation
![[GUI] swing package (window, pop-up window, label, panel, button, list, text box)](/img/05/8e7483768a4ad2036497cac136b77d.png)
[GUI] swing package (window, pop-up window, label, panel, button, list, text box)

2022-7-9 personal qualifying 6 competition experience

MySQL 8.0 OCP (1z0-908) has a Chinese exam

Mycat2 sub database and sub table

Apple's tough new rule: third-party payment also requires a percentage, and developers lose a lot!
随机推荐
Kotlin program control
Oracle 19C OCP certification examination software list
Mysql8 dual master and dual slave +mycat2 read / write separation
Oracle 19C OCP 1z0-082 certification examination question bank (24-29)
Data validation typeerror: qiao Validate is not a function
Analysis on the query method and efficiency of Oracle about date type
Excel find duplicate lines
QT note 2
监控用户积分变化的两种方式
Fluent uses protobuf
基于C语言的哈夫曼转化软件
基于C语言设计的换乘指南打印系统
Mysql database connection / query index and other common syntax
Sed job
BGP routing principle
2022-024arts: Longest valid bracket
Run file command
Status management bloc provider geTx
The data read by Flink Oracle CDC is always null. Do you know
Two ways to monitor the change of user points