WebRTC VoiceEngine使用簡單Demo

Google收購的GIPS公司的音頻處理技術是很牛的,如今開源了,這麼好的技術應該拿來用的,這裏就簡單的介紹一下怎樣使用VoiceEngine,歡迎你們拍磚指導。web

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 互聯網語音音頻編解碼器)相關編碼的參數app

取樣頻率16kHz、24kHz或32kHz,自適應速率爲10kbit/s至52kbit/s,自適應包大小爲30至60ms,因爲算法複雜度和自適應可變速率,相比於G.722.2每幀延時3ms左右。
ide

 

關於如何配置iSAC的參數,能夠參看這裏文章的介紹svn

 

當前的版本VideoEngine是:ViE3.1.0oop

        VoiceEngine是:VoE4.1.0this

 

[cpp]  view plain copy
    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.         }  
相關文章
相關標籤/搜索