WebRTC VoiceEngine使用簡單Demo


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


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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章