webrtc封装sdk(四)使用swig生成跨平台的api

WebRtc中VoiceEngine的使用方法

webrtc中的VoiceEngine是用来管理语音通道channel的类 提供了控制语音整个过程的接口 VoiceEngine的实现类VoiceEngineImpl通过继承的方式将很多不同类型的接口集成在了一个类对象中。 这些接口一共分为以下几种类型:

以上所有基类提供的接口最终的实现其实都是基于Channel这个类 Channel类提供了以上所有基类的接口的具体实现,所以Channel类非常复杂,代码量也很大 其他类只是通过一个channelId找到要操作的channel对象,然后调用channel的接口来实现

基本的调用流程都是如下形式:

  voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
  voe::Channel* channelPtr = ch.channel();
  if (channelPtr == NULL) {
    _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
                          "SetRTCPStatus() failed to locate channel");
    return -1;
  }
  channelPtr->SetRTCPStatus(enable);

所以在理解voiceEngine时,一定要理解channel的概念,channel可以用来发送本地数据,也可以用来接收远端数据 其实在前一篇博客中提到的AudioSendStream AudioReceiveStream也是变相的操作着channel

创建VoiceEngine

创建VoiceEngine非常简单

VoiceEngine* voe = VoiceEngine::Create();

获取各种接口

VoECodec* codec = VoECodec::GetInterface(VOE.ENGINE);
VoEBase* base = VoEBase::GetInterface(VOE.ENGINE);
VoEVolumeControl* volumeControl = VoEVolumeControl::GetInterface(VOE.ENGINE);
VoEHardware* hardware = VoEHardware::GetInterface(VOE.ENGINE);
VoERTP_RTCP* rtpRtcp = VoERTP_RTCP::GetInterface(VOE.ENGINE);
VoEAudioProcessing* audioProcessing = VoEAudioProcessing::GetInterface(VOE.ENGINE);
VoEExternalMedia* externalMedia = VoEExternalMedia::GetInterface(VOE.ENGINE);

共享资源SharedData

SharedData提供了在使用webrtc语音引擎时,只需要创建一次的资源,主要有以下几种:

关键词:webrtc voice engine api 语音引擎

Table of Contents