当前位置:网站首页>[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 .
边栏推荐
- Mysql8 one master one slave +mycat2 read write separation
- Kotlin variables and constants
- QT note 1
- 请问现在flinkcdc支持sqlserver实例名方式连接吗?
- OA项目之我的会议(会议排座&送审)
- [abstract base class inheritance, DOM, event - learning summary]
- 22-07-14 personal training match 2 competition experience
- OA项目之我的会议(查询)
- [C language] programmer's basic skill method - "creation and destruction of function stack frames"
- Mycat2 sub database and sub table
猜你喜欢

Bee guitar score high octave and low octave

Grid segmentation
![[C language] programmer's basic skill method -](/img/0e/e9111d4b341cc42aa4382b5fbd0001.png)
[C language] programmer's basic skill method - "creation and destruction of function stack frames"

BGP routing principle

基于Raft共识协议的KV数据库

【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件

Mycat2 deploy master-slave MariaDB

Write common API tools swagger and redoc

有限元学习知识点备案

22-07-14 personal training match 2 competition experience
随机推荐
Mycat2 deploy master-slave MariaDB
【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
2022-024arts: Longest valid bracket
If Yi Lijing spits about programmers
Flutter WebView three fingers rush or freeze the screen
1、 Redis data structure
Alphabetic string
Inaccurate problem of flutter fijkplayer seekto
[GUI] swing package (window, pop-up window, label, panel, button, list, text box)
How to safely delete a useless activity in Android studio
Problems caused by slivereappbar
Data validation typeerror: qiao Validate is not a function
利用模m的原根存在性判断以及求解
Oracle 19C OCP 1z0-082 certification examination question bank (24-29)
日常一记(11)--word公式输入任意矩阵
The data read by Flink Oracle CDC is always null. Do you know
A summary of practical websites that won't brighten people's eyes
Summary of common skills
Does flinkcdc now support sqlserver instance name connection?
vscode 实用快捷键