您的位置:首页 > 其它

WebRTC VoiceEngine使用简单Demo

2013-09-06 12:27 441 查看
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
plaincopy

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

分享到:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: