基于webrtc的gips 语音引擎库及测试程序(源代码下载地址:http://download.youkuaiyun.com/detail/dotphoenix/3674515)

GIPS库头文件及函数解析
本文详细解析了GIPS库的头文件及其提供的关键函数,包括初始化、关闭、通道管理、编码设置、播放、发送与接收数据等功能。

测试程序源代码下载地址:http://download.youkuaiyun.com/detail/dotphoenix/3674515

gips库头文件解释:

#pragma once


#ifdef LIBGIPS_WEBRTC_EXPORTS
#define LIB_GIPSVE_API extern "C" __declspec(dllexport)
#else
#define LIB_GIPSVE_API extern "C" __declspec(dllimport)
#endif




/*
所有的函数都应该返回true,否则出错,应该使用GIPSVE_LastError来取得出错的原因。
不需返回true的函数包括:
*/


struct PPCodec
{
int pltype;
char plname[32];
int plfreq;
int pacsize;
int channels;
int rate;
};




//必需先调用这个函数,并且确保返回值是0,否则以后所有的调用都可能引起异常.本函数多次调用不会有异常
LIB_GIPSVE_API bool GIPSVE_Init(char* szAuthtication, int iYear, int iMonth, int iDay);


//如果调用了GIPSVE_Init(),则最后必须调用这个函数,否则会有大量的资源泄露
LIB_GIPSVE_API void GIPSVE_UnInit();


//创建一个Channel,Channel的值必须>= 0 ,否则出错
LIB_GIPSVE_API int GIPSVE_CreateChannel();


//删除一个Channel
LIB_GIPSVE_API bool GIPSVE_DeleteChannel(int channel);




//设置目的地址的ip和port
LIB_GIPSVE_API bool GIPSVE_SetSendDestination(int channel, char* ip, unsigned short port);


//设置本地的port
LIB_GIPSVE_API bool GIPSVE_SetLocalReceiver(int channel, unsigned short port);


//取得当前的codec类型
LIB_GIPSVE_API bool GIPSVE_GetSendCodec(int channel, PPCodec& codec);


//设置codec的类型
LIB_GIPSVE_API bool GIPSVE_SetSendCodec(int channel, const PPCodec& codec);


//开始播放声音
LIB_GIPSVE_API bool GIPSVE_StartPlayout(int channel);


//停止播放声音
LIB_GIPSVE_API bool GIPSVE_StopPlayout(int channel);


//开始发送数据
LIB_GIPSVE_API bool GIPSVE_StartSend(int channel);


//停止发送数据
LIB_GIPSVE_API bool GIPSVE_StopSend(int channel);


//开始接收数据
LIB_GIPSVE_API bool GIPSVE_StartListen(int channel);


//停止接收数据
LIB_GIPSVE_API bool GIPSVE_StopListen(int channel);


//使用自定义的传输方式,Free版不支持
LIB_GIPSVE_API bool GIPSVE_UseExternalTransport(int channel, int use, void* externalTransport = NULL);
//Free版不支持
LIB_GIPSVE_API bool GIPSVE_UseExternalMediaProcessIn(int channel, int use, void* externalMedia = NULL);


//使用自定义媒体处理方式,Free版不支持
LIB_GIPSVE_API bool GIPSVE_UseExternalMediaProcessOut(int channel, int use, void* externalMedia = NULL);
//
LIB_GIPSVE_API bool GIPSVE_UseExternalEncryption(int channel, int use, void* externalEncryption);




//用文件里面的声音代替 microphone, 文件内容必须是 16kHz的PCM
//Free版不支持
LIB_GIPSVE_API bool GIPSVE_PlayFileIn(int channel, char* filepath);
//
LIB_GIPSVE_API bool GIPSVE_StopPlayFileIn(int channel);


//用文件里的内容代替收到的远端数据, 文件内容必须是 16kHz的PCM
//Free版不支持
LIB_GIPSVE_API bool GIPSVE_PlayFileOut(int channel, char* filepath);
//
LIB_GIPSVE_API bool GIPSVE_StopPlayFileOut(int channel);




/*
设置degree of bandwidth reduction
0 lowest reduction
1
2
3 means highest reduction
set = false means not set, true means set.
*/


LIB_GIPSVE_API bool GIPSVE_SetVadMode(int channel, bool set, int mode);
LIB_GIPSVE_API bool GIPSVE_GetVadMode(int channel, bool& enabled, int& mode);
//设置静音
LIB_GIPSVE_API bool GIPSVE_SetMute(int channel, bool mute);


//使用SRTP,Free版不支持
LIB_GIPSVE_API bool GIPSVE_UseSRTPTx(int channel, int useForRTP, int useForRTCP);
//Free版不支持
LIB_GIPSVE_API bool GIPSVE_UseSRTPRx(int channel, int useForRTP, int useForRTCP);




//0 holds  all, 1 holds send, 2 holds play
//Free版不支持,Commercial支持
LIB_GIPSVE_API bool GIPSVE_SetHoldMode(int channel, bool held, int mode);


//
LIB_GIPSVE_API bool GIPSVE_GetHoldMode( int channel, bool& held, int& mode);








/*
设置接收端的Automatic Gain Control(AGC)的类型
0 预设模式
1 平台默认
2 adaptive mode for use when analog volume control exists (e.g. for PC softphone)
3 scaling takes place in the digital domain (e.g. for conference servers and embedded devices)
4 can be used on embedded devices where the the capture signal is level is predictable
*/
LIB_GIPSVE_API bool GIPSVE_SetRxAgcMode(int channel, bool enabled, int mode);


//取得接收端的Automatic Gain Control(AGC)的类型
LIB_GIPSVE_API bool GIPSVE_GetRxAgcMode(int channel, bool& enabled, int mode);


/*
设置接收端的Noise Suppression级别


0  previously set mode
1,         // platform default
2,      // conferencing default
3,  // lowest suppression
4,
5,
6,     // highest suppression
*/
LIB_GIPSVE_API bool GIPSVE_SetRxNsMode(int channel, bool enabled, int mode);


//
LIB_GIPSVE_API bool GIPSVE_GetRxNsMode(int channel, bool& enabled, int& mode);


//Free版不支持
LIB_GIPSVE_API bool GIPSVE_StartRecordingMicrophone(char* filepath); //默认为mono 16kHz pcm


//Free版不支持
LIB_GIPSVE_API bool GIPSVE_StopRecrodingMicrophone();
//当前不支持
LIB_GIPSVE_API bool GIPSVE_StartRecordingPlayout(int channel, char* filepath);
//
LIB_GIPSVE_API bool GIPSVE_StopRecordingPlayout(int channel);






LIB_GIPSVE_API bool GIPSVE_SetAgcMode(bool enabled, int mode);


LIB_GIPSVE_API bool GIPSVE_GetAgcMode(bool& enabled, int& mode);
LIB_GIPSVE_API bool GIPSVE_SetNsMode(bool enabled, int mode);


LIB_GIPSVE_API bool GIPSVE_GetNsMode(bool& enabled, int& mode);
/*
设置发送方的Echo Control (EC)类型
0  previously set mode
1  platform default
2  conferencing default (aggressive AEC)
3  Acoustic Echo Cancellation
4  AEC mobile
*/
LIB_GIPSVE_API bool GIPSVE_SetEcMode(bool enabled, int mode);


LIB_GIPSVE_API bool GIPSVE_GetEcMode(bool& enabled, int& mode);




LIB_GIPSVE_API bool GIPSVE_GetCPULoad(int& loadPercent);


//
LIB_GIPSVE_API bool GIPSVE_GetSystemCPULoad(int& loadPercent);




LIB_GIPSVE_API int GIPSVE_GetNumberOfCodecs();


//取得指定index的Codec
LIB_GIPSVE_API bool GIPSVE_GetCodec(int index, PPCodec& codec);


//取得Playout设备的数目
LIB_GIPSVE_API bool GIPSVE_GetNumberOfPlayoutDevice(int& nb);


//取得指定index的Playout设备的名字
LIB_GIPSVE_API bool GIPSVE_GetPlayoutDeviceName(int index, char name[128], char guid[128]);


//取得Recording设备的数目
LIB_GIPSVE_API bool GIPSVE_GetNumberOfRecordingDevice(int& nb);


//取得指定index的Recording设备的名字
LIB_GIPSVE_API bool GIPSVE_GetRecordingDeviceName(int index, char name[128], char guid[128]);




//设置想要使用的Playout设备的index,index值位于0到GetNumberOfPlayoutDevice()之间
//Free版不支持,Commercial支持
LIB_GIPSVE_API bool GIPSVE_SetPlayoutDevice(int index);


//设置想要使用的Recording设备的index,index值位于0到GetNumberOfRecordingDevice()之间
//Free版不支持,Commercial支持
LIB_GIPSVE_API bool GIPSVE_SetRecordingDevice(int index);




//取得当前speaker的volume,值位于0-255之间
LIB_GIPSVE_API bool GIPSVE_GetMicVolume(unsigned int& volume);


//设置Speaker的音量,volume必须位于0-255之间
LIB_GIPSVE_API bool GIPSVE_SetMicVolume(unsigned int volume);


//取得当前speaker的volume,值位于0-255之间
LIB_GIPSVE_API bool GIPSVE_GIPSVE_GetSpeakerVolume(unsigned int& volume);


//设置Speaker的音量,volume必须位于0-255之间
LIB_GIPSVE_API bool GIPSVE_SetSpeakerVolume(unsigned int volume);


//暂不支持该函数
LIB_GIPSVE_API bool GIPSVE_GetInnerVersionInfo(char version[1024]);


//返回版本(该版本的编译时间)
LIB_GIPSVE_API bool GIPSVE_GetVersionInfo(char version[64]);


//如果任何函数的调用返回了非0值,可以调用这个函数来取得错误的原因
LIB_GIPSVE_API int GIPSVE_LastError();


<think>我们之前提供的代码中,信令服务器是内置在同一个进程中的Web服务器(使用aiohttp框架)。默认情况下,服务器监听在本地所有网络接口(0.0.0.0)的8080端口。因此,默认的信令服务器地址是:`http://<服务器IP地址>:8080`,其中`<服务器IP地址>`是运行该程序的计算机的IP地址。在本地测试时,可以使用`http://localhost:8080`或`http://127.0.0.1:8080`。在代码中,我们设置了一个路由`/offer`来处理WebRTC的offer交换:```pythonapp.router.add_post("/offer", offer) ```客户端需要向这个地址发送POST请求以建立连接。 ###客户端连接说明在客户端HTML示例中,我们使用相对路径`/offer`,这意味着客户端页面必须与信令服务器在同一域名和端口下(或通过跨域配置)。例如,如果客户端页面部署在`http://<服务器IP>:8080/index.html`,那么它发送请求的地址就是`http://<服务器IP>:8080/offer`。###修改服务器地址和端口如果需要修改服务器地址或端口,可以在代码的`main()`函数中修改:```pythonweb.run_app(app,port=8080, ssl_context=ssl_context)``` 将`port=8080`改为其他端口即可。 ###关于引用[1]的说明引用[1]中提到的“拉流”概念在WebRTC中并不完全适用,因为WebRTC是点对点传输,没有传统流媒体服务器的“推流”和“拉流”过程。在我们的实现中,ROS2节点作为媒体源(相当于推流方),浏览器客户端作为接收方(相当于拉流方),但整个传输过程是通过WebRTC点对点连接完成的,不经过服务器中转(信令服务器仅用于建立连接)。 ###注意事项1. **网络配置**:如果服务器有防火墙或NAT,需要开放相应端口(默认8080)并配置STUN/TURN服务器以穿透NAT。 2. **HTTPS**:现代浏览器要求WebRTC必须使用HTTPS(或localhost)。代码中提供了SSL配置选项,需要提供证书和私钥文件。###示例客户端连接步骤1.在浏览器中打开客户端页面(例如:`http://<服务器IP>:8080/index.html`)2.客户端页面将自动创建WebRTCoffer并发送到信令服务器3.信令服务器处理offer并返回answer4.建立点对点连接后,视频流开始传输###引用说明本文中关于拉流的解释仅作为背景知识参考[^1]。§§相关问题§§1.如何为WebRTC信令服务器配置HTTPS加密? 2.在ROS2 WebRTC实现中如何添加STUN/TURN服务器以增强网络穿透能力? 3.如何优化ROS2到WebRTC的视频传输延迟?</think># 基于ROS2的WebRTC视频流推送服务器地址解析 在之前提供的基于ROS2的WebRTC视频流推送实现中,**信令服务器默认地址是`http://localhost:8080`**,具体实现细节如下: ## 服务器地址配置 在代码的`main()`函数中,我们明确设置了服务器监听端口: ```python web.run_app(app, port=8080, ssl_context=ssl_context) ``` 这意味着: 1. **默认地址**:`http://localhost:8080` 2. **默认端口**:8080 3. **访问路径**: - 信令接口:`POST /offer` - 静态文件:`GET /`(指向`static`目录) ## 使用说明 ### 1. 本地访问 ```bash http://localhost:8080 ``` ### 2. 局域网访问 ```bash http://<本机IP地址>:8080 ``` ### 3. HTTPS访问 如果配置了SSL证书,可使用: ```bash https://localhost:8080 ``` ## 修改服务器地址 要修改服务器地址或端口,只需更改`web.run_app()`的参数: ```python # 修改为其他端口 web.run_app(app, port=9000, ssl_context=ssl_context) # 指定特定IP地址(仅监听指定接口) web.run_app(app, host='192.168.1.100', port=8080, ssl_context=ssl_context) ``` ## 客户端连接示例 在客户端HTML中,连接信令服务器的代码如下: ```javascript const response = await fetch('/offer', { method: 'POST', body: JSON.stringify(pc.localDescription), headers: {'Content-Type': 'application/json'} }); ``` 这里的`/offer`是相对路径,会基于当前页面URL自动构建完整地址。如果客户端页面部署在其他服务器上,需要指定完整URL: ```javascript const response = await fetch('http://<ROS2主机IP>:8080/offer', { // ... }); ``` ## 网络注意事项 1. **防火墙配置**:确保8080端口在服务器防火墙中开放 2. **NAT穿透**:对于跨网络访问,需要配置STUN/TURN服务器 3. **域名访问**:可通过反向代理(如Nginx)配置域名访问 > 在物联网应用中,如智能宠物喂食系统[^2],这种轻量级WebRTC实现非常适合用于远程视频监控功能,因为它能提供低延迟的视频流传输。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值