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. }  


 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值