WebRTC VoiceEngine使用简单Demo

http://blog.csdn.net/temotemo/article/details/7449525


WebRTC VoiceEngine使用简单Demo

WebRTC技术交流群:234795279


Google收购的GIPS公司的音频处理技术是很牛的,现在开源了,这么好的技术应该拿来用的,这里就简单的介绍一下怎样使用VoiceEngine,欢迎大家拍砖指导。

WebRTC相关的VideoEngine和VoiceEngine的API详细说明文档:http://www.webrtc.org/system/app/pages/subPages?path=/reference/webrtc-internals

WebRTC的VideoEngine和VoiceEngine源码在:http://code.google.com/p/webrtc/source/browse/#svn%2Fbranches


iSAC(Internet Speech Audio Codec 互联网语音音频编解码器)相关编码的参数

取样频率16kHz、24kHz或32kHz,自适应速率为10kbit/s至52kbit/s,自适应包大小为30至60ms,由于算法复杂度和自适应可变速率,相比于G.722.2每帧延时3ms左右。


关于如何配置iSAC的参数,可以参看这里文章的介绍


当前的版本VideoEngine是:ViE3.1.0

        VoiceEngine是:VoE4.1.0

[cpp]  view plain copy
  1. <pre name="code" class="cpp">/**** 
  2.     WebRTC音频引擎版本VoE4.1.0 
  3. ***/  
  4. //初始化VoiceEngine以及Sub_APIS      
  5. VoiceEngine*         _voiceEngine;  
  6. VoEBase*             _veBase;  
  7. VoENetwork*          _veNetwork;  
  8. VoECodec*            _veCodec;  
  9. VoERTP_RTCP*         _veRTCP;  
  10.   
  11. _voiceEngine  = VoiceEngine::Create();  
  12.   
  13. _veBase     = VoEBase::GetInterface(_voiceEngine);  
  14. _veNetwork  = VoENetwork::GetInterface(_voiceEngine);  
  15. _veCodec    = VoECodec::GetInterface(_voiceEngine);  
  16. _veRTCP     = VoERTP_RTCP::GetInterface(_voiceEngine);  
  17. _vieBase->SetVoiceEngine(_voiceEngine);  
  18.   
  19. //编码器选择,编码的配置参数可以配置CodecInst:  
  20. // Each codec supported can be described by this structure.  
  21. /******** 
  22. struct CodecInst 
  23. { 
  24.     int pltype; 
  25.     char plname[32]; 
  26.     int plfreq; 
  27.     int pacsize; 
  28.     int channels; 
  29.     int rate; 
  30. };********/  
  31.   
  32. CodecInst voiceCodec;  
  33. // define iSAC codec parameters  
  34. strcpy(voiceCodec.plname, "ISAC");  
  35. voiceCodec.plfreq   = 16000;    // iSAC宽带模式  
  36. voiceCodec.pltype   = 103;      // 默认动态负载类型  
  37. voiceCodec.pacsize  = 480;      // 480kbps,即使用30ms的packet size  
  38. voiceCodec.channels     = 1;        // 单声道  
  39. voiceCodec.rate     = -1;       // 信道自适应模式,单位bps  
  40.   
  41.     int numOfVeCodecs = _veCodec->NumOfCodecs();  
  42.     for(int i=0; i<numOfVeCodecs;++i)  
  43.     {  
  44.         if(_veCodec->GetCodec(i,voiceCodec)!=-1)  
  45.         {  
  46.             if(strncmp(voiceCodec.plname,"ISAC",4)==0)  
  47.             break;  
  48.         }  
  49.     }  
  50.   
  51.     //网络传输应用  
  52.     _audioChannel = _veBase->CreateChannel();  
  53.     _veRTCP->SetRTCPStatus(_audioChannel, true);  
  54.     _veCodec->SetSendCodec(_audioChannel, voiceCodec);  
  55.     _veBase->StartPlayout(_audioChannel);  
  56.   
  57. //音频和视频绑定  
  58. _vieBase->ConnectAudioChannel(_channelId,_audioChannel);  
  59.   
  60. //网络发送接收配置,远程端口:remotePort 目的IP:IP  
  61. _veBase->SetSendDestination(_audioChannel, remotePort,IP);  
  62. //本地接收  
  63. int res=_veBase->SetLocalReceiver(_audioChannel,localPort);  
  64.   
  65. _veBase->StartSend(_audioChannel);  
  66. _veBase->StartReceive(_audioChannel);  
  67.   
  68. _veBase->StopReceive(_audioChannel);  
  69. _veBase->StopSend(_audioChannel);  
  70.   
  71. //结束,释放资源  
  72.     if (_voiceEngine)  
  73.     {  
  74.         _veBase->DeleteChannel(_audioChannel);  
  75.         _veBase->Release();  
  76.         _veNetwork->Release();  
  77.         _veCodec->Release();  
  78.         _veRTCP->Release();   
  79.         
  80.          VoiceEngine::Delete(_voiceEngine);  
  81.         }  
  82.   
  83. </pre>  
  84. <pre></pre>  
  85. <pre></pre>  
  86. <pre></pre>  
  87. <pre></pre>  
  88. <pre></pre>  
  89. <pre></pre>  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值