WebRtc 音频引擎-linux demo

2024-08-21 18:08
文章标签 音频 linux 引擎 demo webrtc

本文主要是介绍WebRtc 音频引擎-linux demo,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Google收购了著名的音频技术公司GIPS后,基于其强大的音频技术,实现了WebRtc的Voice Engine,即语音处理引擎。本文主要介绍WebRTC 中Voice Engine中音频技术相关的实现,并结合具体实例,介绍如何利用voice engine实现自己的VoIP音频处理引擎。

本文主要介绍如何在linux下搭建一个可以自己调试的基于WebRTC的voiceEngine。

1.VoiceEngine Demo 目录树

下面是一个小的VoiceEngine目录树:

[cpp]  view plain  copy
  1. .  
  2. ├── include  
  3. │   ├── channel_transport.h  
  4. │   ├── common_types.h  
  5. │   ├── typedefs.h  
  6. │   ├── udp_transport.h  
  7. │   ├── voe_audio_processing.h  
  8. │   ├── voe_base.h  
  9. │   ├── voe_call_report.h  
  10. │   ├── voe_codec.h  
  11. │   ├── voe_dtmf.h  
  12. │   ├── voe_encryption.h  
  13. │   ├── voe_errors.h  
  14. │   ├── voe_external_media.h  
  15. │   ├── voe_file.h  
  16. │   ├── voe_hardware.h  
  17. │   ├── voe_neteq_stats.h  
  18. │   ├── voe_network.h  
  19. │   ├── voe_rtp_rtcp.h  
  20. │   ├── voe_video_sync.h  
  21. │   └── voe_volume_control.h  
  22. ├── lib  
  23. │   ├── libaudio_coding_module.a  
  24. │   ├── libaudio_conference_mixer.a  
  25. │   ├── libaudio_device.a  
  26. │   ├── libaudioproc_debug_proto.a  
  27. │   ├── libaudio_processing.a  
  28. │   ├── libaudio_processing_sse2.a  
  29. │   ├── libchannel_transport.a  
  30. │   ├── libCNG.a  
  31. │   ├── libcommon_video.a  
  32. │   ├── libG711.a  
  33. │   ├── libG722.a  
  34. │   ├── libgtest.a  
  35. │   ├── libgtest_main.a  
  36. │   ├── libiLBC.a  
  37. │   ├── libiSAC.a  
  38. │   ├── libiSACFix.a  
  39. │   ├── libmedia_file.a  
  40. │   ├── libNetEq.a  
  41. │   ├── libopus.a  
  42. │   ├── libpaced_sender.a  
  43. │   ├── libPCM16B.a  
  44. │   ├── libprotobuf_lite.a  
  45. │   ├── libresampler.a  
  46. │   ├── librtp_rtcp.a  
  47. │   ├── libsignal_processing.a  
  48. │   ├── libsystem_wrappers.a  
  49. │   ├── libvad.a  
  50. │   ├── libvoice_engine_core.a  
  51. │   ├── libwebrtc_opus.a  
  52. │   └── libwebrtc_utility.a  
  53. ├── Makefile  
  54. ├── out  
  55. │   └── Debug  
  56. │       ├── client_recv  
  57. │       └── client_send  
  58. └── src  
  59.     ├── client_recv.cpp  
  60.     └── client_send.cpp  


 

其中,src目录下的client_send和client_recv是基于WebRTC VoiceEngine实现的两个Demo,一个发送音频数据、一个接收音频数据。

2.工程Makefile

下面是Voiceengine工程编译的Makefile文件

[cpp]  view plain  copy
  1. #WebRTC VoiceEngine Test => Makefile                                                                                                    
  2.   
  3. CC = g++   
  4. CFLAGS= -Wall -g  
  5. VPATH = src:include  
  6. lib= -L lib   
  7.   
  8. obj=out/Debug/client_send  out/Debug/client_recv  
  9.   
  10. depens= -lvoice_engine_core -laudio_device -lresampler \  
  11.         -laudio_conference_mixer\  
  12.         -laudio_processing  \  
  13.         -laudio_coding_module -lrtp_rtcp\  
  14.         -lNetEq -lCNG -lG722 -liLBC \  
  15.         -lG711 -liSAC -lPCM16B \  
  16.         -lsignal_processing \  
  17.         -lvad -laudioproc_debug_proto\  
  18.         -lprotobuf_lite -laudio_processing_sse2\  
  19.         -lwebrtc_opus -lopus  -lpaced_sender\  
  20.         -liSACFix -lmedia_file \  
  21.         -lwebrtc_utility -lchannel_transport -lgtest\  
  22.         -lpthread -lsystem_wrappers -lrt -ldl\  
  23.   
  24. all:${obj}  
  25.   
  26. out/Debug/client_send:client_send.cpp  
  27.         ${CC} ${CFLAGS} -o $@ $< -Iinclude  ${lib} ${depens}  
  28.           
  29. out/Debug/client_recv:client_recv.cpp   
  30.         ${CC} ${CFLAGS} -o $@ $< -Iinclude  ${lib} ${depens}  
  31.   
  32. .PHONY:clean  
  33. clean:  
  34.         rm -rf *.o ${obj}  


 

其中,静态库的链接顺序不能随便修改,由于静态库之间存在依赖关系。具体原因可以看这里

3.client_recv Demo

[cpp]  view plain  copy
  1. /* 
  2. *  WebRTC VoiceEngine Test => client_recv 
  3. *   
  4. *  @date:13.06.2013 
  5. *  @author:hongliang 
  6. *  @mail:lhl_nciae@sina.cn 
  7. */  
  8.   
  9. #include<iostream>  
  10. #include"voe_base.h"  
  11. #include"voe_network.h"  
  12. #include"voe_hardware.h"  
  13. #include"voe_errors.h""  
  14. #include"channel_transport.h"  
  15.   
  16.   
  17. using namespace webrtc;  
  18.   
  19. int main(int argc , char *argv[])  
  20. {  
  21.     //Create VoiceEngine  
  22.     VoiceEngine* voe = VoiceEngine::Create();  
  23.   
  24.     //Init base  
  25.     VoEBase* base = VoEBase::GetInterface(voe);  
  26.     base->Init();  
  27.   
  28.     //hardware  
  29.     VoEHardware* hardware = VoEHardware::GetInterface(voe);  
  30.   
  31.     int nRec = 0;  
  32.     char devName[128] = {0};  
  33.     char guidName[128] = {0};  
  34.     int ret = 0;  
  35.   
  36.     ret = hardware->GetNumOfRecordingDevices(nRec);  
  37.   
  38.     if(ret != 0)  
  39.     {  
  40.         std::cout << "GetNumOfRecordingDevice error:" << base->LastError() << std::endl;  
  41.     }  
  42.   
  43.     for (int idx = 0; idx < nRec; idx++)  
  44.     {  
  45.         hardware->GetRecordingDeviceName(idx , devName , guidName);  
  46.         std::cout << "GetRecordingDeviceName=> " << "name:" << devName << " guidname:" << guidName <<std::endl;  
  47.     }  
  48.   
  49.     //Create Channel  
  50.     int ch = base->CreateChannel();  
  51.     if(ch != -1)  
  52.     {  
  53.         std::cout << "Create channel #" << ch << std::endl;  
  54.     }  
  55.       
  56.     //Create Voice Channel transport  
  57.     VoENetwork* voe_network = VoENetwork::GetInterface(voe);  
  58.       
  59.     test::VoiceChannelTransport voe_vct = test::VoiceChannelTransport(voe_network , ch);  
  60.   
  61.     //recv  
  62.     voe_vct.SetLocalReceiver(12345);  
  63.     base->StartReceive(ch);  
  64.     base->StartPlayout(ch);  
  65.   
  66.     std::cout << "Start Receice from channel:" << ch << std::endl;  
  67.   
  68.     while(1)  
  69.     {  
  70.     }     
  71.       
  72.   
  73.     //Release resource  
  74.     base->DeleteChannel(ch);  
  75.     base->Terminate();  
  76.     base->Release();  
  77.     hardware->Release();  
  78.     VoiceEngine::Delete(voe);  
  79.   
  80.     return 0;  
  81. }  


 

4.client_send Demo

[cpp]  view plain  copy
  1. #include<iostream>  
  2. #include"voe_base.h"  
  3. #include"voe_network.h"  
  4. #include"voe_hardware.h"  
  5. #include"voe_errors.h"  
  6. #include"voe_rtp_rtcp.h"  
  7. #include"channel_transport.h"  
  8.   
  9. using namespace webrtc;  
  10.   
  11. int main(int argc ,char * argv[])  
  12. {  
  13.     int ret;  
  14.     //Create VoiceEngine  
  15.     VoiceEngine *voe = VoiceEngine::Create();  
  16.   
  17.     //Init base  
  18.     VoEBase* base = VoEBase::GetInterface(voe);  
  19.     base->Init();  
  20.   
  21.     //handware  
  22.     int nRec = 0;  
  23.     char devName[128] = {0};  
  24.     char guidName[128] = {0};  
  25.       
  26.     VoEHardware* hardware = VoEHardware::GetInterface(voe);  
  27.     hardware->GetNumOfRecordingDevices(nRec);  
  28.     std::cout << "Get num of recordingdevice:" << nRec << std::endl;    
  29.     for(int idx = 0; idx < nRec; idx++)  
  30.     {  
  31.         hardware->GetRecordingDeviceName(idx , devName , guidName);  
  32.         std::cout << "GetRecordingName(" << idx << ")  " << "name:" << devName << "  guidName:" << guidName << std::endl;  
  33.     }  
  34.   
  35.     //Create Channel  
  36.     int ch = base->CreateChannel();  
  37.     if(ch == -1)  
  38.     {  
  39.         std::cout << "create channel error:" << base->LastError() << std::endl;  
  40.         return -1;  
  41.     }     
  42.   
  43.     std::cout << "create channel#" << ch << std::endl;  
  44.     //Create Voice Channel transport  
  45.     VoENetwork* voe_network = VoENetwork::GetInterface(voe);  
  46.       
  47.     test::VoiceChannelTransport voe_ctp = test::VoiceChannelTransport(voe_network , ch);  
  48.   
  49.     //send  
  50.     voe_ctp.SetSendDestination("192.168.1.1" , 12345);  
  51. //  base->SetSendDestination(ch , "192.168.1.1" , 12345);  
  52.   
  53.     ret = base->StartSend(ch);     
  54.     if(ret == -1)  
  55.     {  
  56.         std::cout << "Start send error:" << base->LastError() << std::endl;  
  57.         return -1;  
  58.     }  
  59.   
  60.     std::cout << "Start send on channel#" << ch << std::endl;  
  61.   
  62.     //Release Resource  
  63.     base->DeleteChannel(ch);  
  64.     base->Terminate();  
  65.     hardware->Release();  
  66.     VoiceEngine::Delete(voe);  
  67.   
  68.     return 0;  
  69. }  


 

 

这篇关于WebRtc 音频引擎-linux demo的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1093896

相关文章

linux ssh如何实现增加访问端口

《linuxssh如何实现增加访问端口》Linux中SSH默认使用22端口,为了增强安全性或满足特定需求,可以通过修改SSH配置来增加或更改SSH访问端口,具体步骤包括修改SSH配置文件、增加或修改... 目录1. 修改 SSH 配置文件2. 增加或修改端口3. 保存并退出编辑器4. 更新防火墙规则使用uf

Linux join命令的使用及说明

《Linuxjoin命令的使用及说明》`join`命令用于在Linux中按字段将两个文件进行连接,类似于SQL的JOIN,它需要两个文件按用于匹配的字段排序,并且第一个文件的换行符必须是LF,`jo... 目录一. 基本语法二. 数据准备三. 指定文件的连接key四.-a输出指定文件的所有行五.-o指定输出

Linux jq命令的使用解读

《Linuxjq命令的使用解读》jq是一个强大的命令行工具,用于处理JSON数据,它可以用来查看、过滤、修改、格式化JSON数据,通过使用各种选项和过滤器,可以实现复杂的JSON处理任务... 目录一. 简介二. 选项2.1.2.2-c2.3-r2.4-R三. 字段提取3.1 普通字段3.2 数组字段四.

Linux kill正在执行的后台任务 kill进程组使用详解

《Linuxkill正在执行的后台任务kill进程组使用详解》文章介绍了两个脚本的功能和区别,以及执行这些脚本时遇到的进程管理问题,通过查看进程树、使用`kill`命令和`lsof`命令,分析了子... 目录零. 用到的命令一. 待执行的脚本二. 执行含子进程的脚本,并kill2.1 进程查看2.2 遇到的

Linux云服务器手动配置DNS的方法步骤

《Linux云服务器手动配置DNS的方法步骤》在Linux云服务器上手动配置DNS(域名系统)是确保服务器能够正常解析域名的重要步骤,以下是详细的配置方法,包括系统文件的修改和常见问题的解决方案,需要... 目录1. 为什么需要手动配置 DNS?2. 手动配置 DNS 的方法方法 1:修改 /etc/res

Linux创建服务使用systemctl管理详解

《Linux创建服务使用systemctl管理详解》文章指导在Linux中创建systemd服务,设置文件权限为所有者读写、其他只读,重新加载配置,启动服务并检查状态,确保服务正常运行,关键步骤包括权... 目录创建服务 /usr/lib/systemd/system/设置服务文件权限:所有者读写js,其他

Linux下利用select实现串口数据读取过程

《Linux下利用select实现串口数据读取过程》文章介绍Linux中使用select、poll或epoll实现串口数据读取,通过I/O多路复用机制在数据到达时触发读取,避免持续轮询,示例代码展示设... 目录示例代码(使用select实现)代码解释总结在 linux 系统里,我们可以借助 select、

Linux挂载linux/Windows共享目录实现方式

《Linux挂载linux/Windows共享目录实现方式》:本文主要介绍Linux挂载linux/Windows共享目录实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录文件共享协议linux环境作为服务端(NFS)在服务器端安装 NFS创建要共享的目录修改 NFS 配

linux系统中java的cacerts的优先级详解

《linux系统中java的cacerts的优先级详解》文章讲解了Java信任库(cacerts)的优先级与管理方式,指出JDK自带的cacerts默认优先级更高,系统级cacerts需手动同步或显式... 目录Java 默认使用哪个?如何检查当前使用的信任库?简要了解Java的信任库总结了解 Java 信

Linux命令rm如何删除名字以“-”开头的文件

《Linux命令rm如何删除名字以“-”开头的文件》Linux中,命令的解析机制非常灵活,它会根据命令的开头字符来判断是否需要执行命令选项,对于文件操作命令(如rm、ls等),系统默认会将命令开头的某... 目录先搞懂:为啥“-”开头的文件删不掉?两种超简单的删除方法(小白也能学会)方法1:用“--”分隔命