FREESWITCH 怎样添加自定义模块

简介: FREESWITCH 怎样添加自定义模块

添加模块的方式尝试了很多种,试过的比较好的,比较方便的,如下

a、Makefile.am文件需要包含build目录下的modmake.rules


1、先写Makefile文件

Makefile 文件的内容是:

#BASE 是freeswitch的源码路径

BASE=/usr/src/freeswitch    
include $(BASE)/build/modmake.rules
复制代码


就是这两句话,当然也可以写成一句。


2、写模块代码 简历模块文件夹和模块的代码文件名一致 例如mod_example/mod_example.c

这里说明一下,如果是.c文件的话,那么代码将会以c的方式编译代码,如果.cpp文件的话,那么将使用c++的方式编译代码。

mod_sample.c的代码如下


/*
 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
 * Copyright (C) 2005/2012, Anthony Minessale II <anthm@freeswitch.org>
 *
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
 *
 * The Initial Developer of the Original Code is
 * Anthony Minessale II <anthm@freeswitch.org>
 * Portions created by the Initial Developer are Copyright (C)
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Anthony Minessale II <anthm@freeswitch.org>
 * Neal Horman <neal at wanlink dot com>
 *
 *
 * mod_example.c -- Framework Demo Module
 *
 */
#include <switch.h>
/*
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_example_shutdown);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_example_runtime);
*/
SWITCH_MODULE_LOAD_FUNCTION(mod_example_load);
SWITCH_MODULE_DEFINITION(mod_example, mod_example_load, NULL, NULL);
SWITCH_MODULE_LOAD_FUNCTION(mod_example_load)
{
  /* connect my internal structure to the blank pointer passed to me */
  *module_interface = switch_loadable_module_create_module_interface(pool, modname);
  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
  /* indicate that the module should continue to be loaded */
  return SWITCH_STATUS_SUCCESS;
}
/*
  Called when the system shuts down
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_example_shutdown);
{
  return SWITCH_STATUS_SUCCESS;
}
*/
/*
  If it exists, this is called in it's own thread when the module-load completes
  If it returns anything but SWITCH_STATUS_TERM it will be called again automaticly
SWITCH_MODULE_RUNTIME_FUNCTION(mod_example_runtime);
{
  while(looping)
  {
    switch_yield(1000);
  }
  return SWITCH_STATUS_TERM;
}
*/
/* For Emacs:
 * Local Variables:
 * mode:c
 * indent-tabs-mode:nil
 * tab-width:4
 * c-basic-offset:4
 * End:
 * For VIM:
 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet expandtab:
 */
复制代码


这段代码是从freeswitch的源码中的src/mod/sdk/autotools/src中复制出来的。本身autotools也是freeswitch提供的范例用于初学者学习创建模块的。下面一个例子就是使用这个模块用来创建自定义模块。


b、使用freeswitch提供的范例进行改写,创建自定义的模块。

就是创建mod_example模块

那么我们复制 autotools 成mod_example 如果名称不一样比如是mod_test,那么我们需要修改的点如下:


1、修改configuer.ac文件

修改mod_example 为 mod_test

修改mod_example.c 为 mod_test.c

当然这里需要说明的是,如果源文件是.cpp文件的话呢这样就需要搜索一下.ac 支持编译c++。我这里添加了如下的宏

AC_PROG_CXX

AC_PROG_CPP

如果不是.cpp文件的话,则不需要添加。


网络异常,图片无法展示
|


2、修改Makefile.am文件 范例提供的Makefile.am文件,需要修改的是在src文件下面的Makefile.am文件。模块名是mod_example的话,不需要这个文件,只需要添加PKG_CONFIG_PATH的环境配置即可。


这里需要说明的是 FREESWITCH_CFLAGS 这样的宏的定义在 freeswitch.pc文件中定义的,在freeswitch编译完成之后会给安装在/usr/local/freeswitch/lib/pkgconfig/freeswitch.pc下,如果提示FREESWITCH_CFLAGS这样的宏没有定义话,就需要在环境变量里添加PKG_CONFIG_PATH的值

或者把freeswitch.pc文件因为是64位的所以复制到/usr/lib64/pkgconfig下


moddir     = @FREESWITCH_MODULES_DIR@
sysconfdir = @FREESWITCH_CONFIG_DIR@
###
# Flags
#
AM_CFLAGS  =
AM_CXXFLAGS=
AM_CPPFLAGS= -I. -I$(includedir)
AM_LDFLAGS = -L. -L$(libdir) -avoid-version -module -no-undefined -shared
###
# GCC (and compatible) specific flags
#
if CC_VENDOR_GNU
AM_CFLAGS += -Wall
endif
###
# SunCC specific flags
#
if CC_VENDOR_SUN
AM_CFLAGS +=
endif
###
# symbol visibility support
#
if CC_HAS_VISIBILITY
AM_CFLAGS   += $(VISIBILITY_CFLAGS)
AM_CXXFLAGS += $(VISIBILITY_CXXFLAGS)
AM_CPPFLAGS += -DSWITCH_API_VISIBILITY=1
endif
###
# add module(s) here, with suffix '.la'
#
mod_LTLIBRARIES = mod_example.la
###
# mod_example
#
mod_example_la_SOURCES = mod_example.c
mod_example_la_CFLAGS  = $(AM_CFLAGS) $(FREESWITCH_CFLAGS)
mod_example_la_CPPFLAGS= $(AM_CPPFLAGS) $(FREESWITCH_CPPFLAGS)
mod_example_la_LDFLAGS = $(AM_LDFLAGS)
mod_example_la_LIBADD  = $(FREESWITCH_LIBS)
# configuration file
#sysconf_DATA = example.conf.xml
#
# install configuration
#
#install-sysconfDATA:
# $(INSTALL) -d $(DESTDIR)/$(sysconfdir)
# for x in $(sysconf_DATA); do \
#   test -e $(DESTDIR)$(sysconfdir)/$$x || $(INSTALL) -m644 $$x $(DESTDIR)$(sysconfdir)/$$x ; \
# done
复制代码


3、修改了configure.ac文件和Makefile.am文件后就是看一下mod_example.c文件了,文件的内容在上面已经写过了,模块的函数也有很多的文件都有介绍了,就不多介绍了。


4、先执行autogen.sh文件,再行configure文件,再 make 最后make install

c、这种创建自定义模块的方法呢和第二种比较类似,freeswitch的中文指南中也有介绍。就是复制模块后做修改。这种一般在修改完模块自己的makefile.am模块后,要修改freeswitch目录下的configure.ac文件,添加对新增模块的路径


src/mod/asr_tts/mod_unimrcp/Makefile
src/mod/asr_tts/mod_test/Makefile #这是自定义的模块
复制代码


这样就能在自定义的模块中生成Makefile文件。

相关文章
|
语音技术
FreeSwitch中音乐功能保持和静音回铃声怎样设置
FreeSwitch中音乐功能保持和静音回铃声怎样设置
|
Java API 语音技术
MRCP(Media Resource Control Protocol)
MRCP(Media Resource Control Protocol)是一种音视频资源控制协议,用于控制语音识别、语音合成和语音交互等场景中的音视频资源。阿里云语音交互服务(ASR、TTS、Chatbot)支持MRCP协议,您可以使用MRCP协议来控制音视频资源,并实现语音交互的功能。
3947 1
|
关系型数据库 MySQL 数据库连接
FreeSWITCH通过mod_mariadb原生连接MySQL
FreeSWITCH通过mod_mariadb原生连接MySQL
1183 0
|
关系型数据库 MySQL 数据库
debian11编译安装freeswitch
debian11编译安装freeswitch
496 0
|
编解码 网络协议 网络性能优化
RTP/RTCP 协议讲解
RTP/RTCP 协议讲解
3337 0
|
Java Linux 应用服务中间件
docker编译部署freeswitch-1.10.10
docker编译部署freeswitch-1.10.10
1476 0
|
网络协议 中间件 机器人
通过顶顶通呼叫中心中间件玩转FreeSWITCH媒体流
怎么获取FreeSWITCH的媒体流是一个老生常谈的问题了,最常见的方法media_bug 很多人需要直接获取原始的声音流,然后自己处理,其实FreeSWITCH也是支持的,只是知道的极少,FreeSWITCH原生支持 unicast 通过udp 把声音流推送到一个UDP端口,和播放网络的声音流。 fs实现的unicast,有一个缺陷如果启动了unicast 就没办法调用playback等放音函数了。
1215 0
|
JSON Linux 语音技术
FreeSWITCH 语音识别 ASR 模块
最近很多人都对FreeSWITCH和ASR对接比较感谢兴趣,(,考虑到大部分人,只是研究一下,并不准确购买商业模块,特意做一个开源项目给大家提供一个参考。
3198 0