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
- <pre name="code" class="cpp">/****
- WebRTC音頻引擎版本VoE4.1.0
- ***/
- //初始化VoiceEngine以及Sub_APIS
- VoiceEngine* _voiceEngine;
- VoEBase* _veBase;
- VoENetwork* _veNetwork;
- VoECodec* _veCodec;
- VoERTP_RTCP* _veRTCP;
- _voiceEngine = VoiceEngine::Create();
- _veBase = VoEBase::GetInterface(_voiceEngine);
- _veNetwork = VoENetwork::GetInterface(_voiceEngine);
- _veCodec = VoECodec::GetInterface(_voiceEngine);
- _veRTCP = VoERTP_RTCP::GetInterface(_voiceEngine);
- _vieBase->SetVoiceEngine(_voiceEngine);
- //編碼器選擇,編碼的配置參數可以配置CodecInst:
- // Each codec supported can be described by this structure.
- /********
- struct CodecInst
- {
- int pltype;
- char plname[32];
- int plfreq;
- int pacsize;
- int channels;
- int rate;
- };********/
- CodecInst voiceCodec;
- // define iSAC codec parameters
- strcpy(voiceCodec.plname, "ISAC");
- voiceCodec.plfreq = 16000; // iSAC寬帶模式
- voiceCodec.pltype = 103; // 默認動態負載類型
- voiceCodec.pacsize = 480; // 480kbps,即使用30ms的packet size
- voiceCodec.channels = 1; // 單聲道
- voiceCodec.rate = -1; // 信道自適應模式,單位bps
- int numOfVeCodecs = _veCodec->NumOfCodecs();
- for(int i=0; i<numOfVeCodecs;++i)
- {
- if(_veCodec->GetCodec(i,voiceCodec)!=-1)
- {
- if(strncmp(voiceCodec.plname,"ISAC",4)==0)
- break;
- }
- }
- //網絡傳輸應用
- _audioChannel = _veBase->CreateChannel();
- _veRTCP->SetRTCPStatus(_audioChannel, true);
- _veCodec->SetSendCodec(_audioChannel, voiceCodec);
- _veBase->StartPlayout(_audioChannel);
- //音頻和視頻綁定
- _vieBase->ConnectAudioChannel(_channelId,_audioChannel);
- //網絡發送接收配置,遠程端口:remotePort 目的IP:IP
- _veBase->SetSendDestination(_audioChannel, remotePort,IP);
- //本地接收
- int res=_veBase->SetLocalReceiver(_audioChannel,localPort);
- _veBase->StartSend(_audioChannel);
- _veBase->StartReceive(_audioChannel);
- _veBase->StopReceive(_audioChannel);
- _veBase->StopSend(_audioChannel);
- //結束,釋放資源
- if (_voiceEngine)
- {
- _veBase->DeleteChannel(_audioChannel);
- _veBase->Release();
- _veNetwork->Release();
- _veCodec->Release();
- _veRTCP->Release();
- VoiceEngine::Delete(_voiceEngine);
- }
- </pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>