WebRTC VoiceEngine使用简单Demo

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

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