当前位置:网站首页>[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 .
边栏推荐
- Run file command
- 内存管理-动态分区分配方式模拟
- Poor English, Oracle OCP or MySQL OCP exam can also get a high score of 80 points
- Oracle 19C OCP 1z0-082 certification examination question bank 1
- If Yi Lijing spits about programmers
- 监控用户积分变化的两种方式
- Kotlin data type
- Xshell batch send command to multiple sessions
- Analysis on the query method and efficiency of Oracle about date type
- Leetcode and query question summary
猜你喜欢

Super nice navigation page (static page)

Memory management based on C language - Simulation of dynamic partition allocation

Daily Note (11) -- word formula input arbitrary matrix

为什么要在时钟输出上预留电容的工位?

Take out brother is the biggest support in this society

22-07-14 personal training match 2 competition experience

Foundry教程:使用多种方式编写可升级的智能合约(上)

23.6 23.7 web environment web environment variable reading

Matplotlib learning notes

Maximum common substring & regularity problem
随机推荐
Logic of data warehouse zipper table
Kotlin variables and constants
Shell programming
Automation and disconnection monitoring of video addition
Dear teachers, how can sqlserver get DDL in flinkcdc?
Oracle 19C OCP 1z0-082 certification examination question bank (30-35)
NLP (natural language processing) natural language processing learning
Data validation typeerror: qiao Validate is not a function
Lesson 3: gcc compiler
Number of briquettes & Birthday Candles & building blocks
Guitar staff link Jasmine
6、 Pinda general permission system__ pd-tools-log
Beauty naked chat for a while, naked chat over the crematorium!
Status management bloc provider geTx
Memory management based on C language - Simulation of dynamic partition allocation
Excel delete blank lines
BGP -- Border Gateway Protocol
Kotlin中room数据库的使用
File management file system based on C #
Using the primitive root of module m to judge and solve