当前位置:网站首页>[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_number
Dial plan expression string , Dial now “123” number , You can do it condition Dial up configurationanswer
Answer
-myapp
This is the custom module we created earlier app
-echo
echo app, because myapp Not blocking function , So want to use echo Program to block calls , Achieve the purpose of uninterrupted call
-hangup
Hang 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
123
It'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 .
边栏推荐
- NLP (natural language processing) natural language processing learning
- QSS add resource file of QT
- 监控用户积分变化的两种方式
- 【搜索专题】看完必会的搜索问题之洪水覆盖
- How to safely delete a useless activity in Android studio
- Grid segmentation
- Use of room database in kotlin
- Apple's tough new rule: third-party payment also requires a percentage, and developers lose a lot!
- I am 35 years old.
- The full name of flitter IDFA is identity for advertisers, that is, advertising identifiers. It is used to mark users. At present, it is most widely used for advertising, personalized recommendation,
猜你喜欢
Grid segmentation
Kotlin function
Using the primitive root of module m to judge and solve
Nodejs2day (modularization of nodejs, NPM download package, module loading mechanism)
Xshell batch send command to multiple sessions
Daily Note (11) -- word formula input arbitrary matrix
基于C#实现的文件管理文件系统
Maximum common substring & regularity problem
OA项目之我的会议(查询)
2022-7-9 personal qualifying 6 competition experience
随机推荐
Storage of drawings (refined version)
23.5 event listeners of application events and listeners
【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
JS tool function Encyclopedia
How to safely delete a useless activity in Android studio
Spark SQL common date functions
OSPF summary
【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件
Write common API tools swagger and redoc
[C language] programmer's basic skill method - "creation and destruction of function stack frames"
Mysql/mariadb (Galera multi master mode) cluster construction
Super nice navigation page (static page)
Mysql8 one master one slave +mycat2 read write separation
Flutter text is left aligned with no blank space in the middle
Oracle 19C OCP 1z0-083 question bank (1-6)
Kotlin program control
Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
2022/7/18 exam summary
Data validation typeerror: qiao Validate is not a function
Flutter WebView jitter