码迷,mamicode.com
首页 > Web开发 > 详细

webrtc自带client的音频引擎创建代码走读

时间:2017-10-14 17:04:20      阅读:980      评论:0      收藏:0      [点我收藏+]

标签:const   decode   ice   ase   options   his   定义   elf   set   

src\webrtc\examples\peerconnection\client\conductor.cc
1、bool Conductor::InitializePeerConnection()
1.1 webrtc::CreatePeerConnectionFactory();

src\talk\app\webrtc\peerconnectionfactory.cc
2、 bool PeerConnectionFactory::Initialize()
2.1.1 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() {

return cricket::WebRtcMediaEngineFactory::Create(default_adm_.get(), video_encoder_factory_.get(),video_decoder_factory_.get());
}

src\talk\media\webrtc\webrtcmediaengine.cc
2.1.2
MediaEngineInterface* WebRtcMediaEngineFactory::Create(
webrtc::AudioDeviceModule* adm,WebRtcVideoEncoderFactory* encoder_factory,WebRtcVideoDecoderFactory* decoder_factory)
{
return CreateWebRtcMediaEngine(adm, encoder_factory, decoder_factory);
}
2.1.3
cricket::MediaEngineInterface* WebRtcMediaEngineFactory::CreateWebRtcMediaEngine(
webrtc::AudioDeviceModule* adm,WebRtcVideoEncoderFactory* encoder_factory,WebRtcVideoDecoderFactory* decoder_factory)
{
return new cricket::WebRtcMediaEngine2(adm, encoder_factory,
decoder_factory);
}

2.1.4
class WebRtcMediaEngine2
: public CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine2>
{

public:

WebRtcMediaEngine2(webrtc::AudioDeviceModule* adm,WebRtcVideoEncoderFactory* encoder_factory,WebRtcVideoDecoderFactory* decoder_factory)
};

2.1.5
\src\talk\media\webrtc\webrtcvoiceengine.cc
WebRtcVoiceEngine::WebRtcVoiceEngine()

: voe_wrapper_(new VoEWrapper())
{
Construct();
}

2.1.6

src\talk\media\webrtc\webrtcvoe.h
class VoEWrapper {

public:

VoEWrapper()
: engine_(webrtc::VoiceEngine::Create())
, processing_(engine_),
base_(engine_), codec_(engine_)
, dtmf_(engine_),
hw_(engine_), network_(engine_)
, rtp_(engine_), volume_(engine_){}
};

2.1.7
src\webrtc\voice_engine\voice_engine_impl.cc
VoiceEngine* VoiceEngine::Create()
{
return GetVoiceEngine(config, true);

}

VoiceEngine* GetVoiceEngine(const Config* config, bool owns_config)
{
VoiceEngineImpl* self = new VoiceEngineImpl(config, owns_config);
}

2.1.9
src\webrtc\voice_engine\voice_engine_impl.h
class VoiceEngineImpl : public VoiceEngine,
public VoEBaseImpl
{
VoEBaseImpl(this);
};

2.1.9
void WebRtcVoiceEngine::Construct() 
{
// Load our audio codec list.
内部调用voe_wrapper_->codec()->NumOfCodecs() 
ConstructCodecs();

//获取是否需要回音消除,降噪,自动调节音量等
options_ = GetDefaultEngineOptions(); 
}

src\talk\session\media\channelmanager.cc
2.2
bool ChannelManager::Init()
{
initialized_ = worker_thread_->Invoke<bool>(Bind(
&ChannelManager::InitMediaEngine_w, this));
}
2.2.1
bool ChannelManager::InitMediaEngine_w()
{

return (media_engine_->Init(worker_thread_));

}

2.2.2
template<class VOICE, class VIDEO>

class CompositeMediaEngine : public MediaEngineInterface
{
public:
virtual bool Init(rtc::Thread* worker_thread)
{

if (!voice_.Init(worker_thread))

return false;

video_.Init();

return true;

}
protected:

VOICE voice_; //默认的WebRtcVoiceEngine或自定义的音频引擎
}

2.2.3
bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread)
{
bool res = InitInternal();
}

2.2.4
bool WebRtcVoiceEngine::InitInternal()
{
if (voe_wrapper_->base()->Init(adm_) == -1)
}

2.2.5
src\webrtc\voice_engine\voe_base_impl.cc
int VoEBaseImpl::Init(AudioDeviceModule* external_adm,AudioProcessing* audioproc)
{
if (external_adm == nullptr)
{
// Create the internal ADM implementation.

shared_->set_audio_device(AudioDeviceModuleImpl::Create(
VoEId(shared_->instance_id(), -1), shared_->audio_device_layer()));
}
else
{
// Use the already existing external ADM implementation.

shared_->set_audio_device(external_adm);
}

// Register the AudioObserver implementation

if (shared_->audio_device()->RegisterEventObserver(this) != 0)

// Register the AudioTransport implementation

if (shared_->audio_device()->RegisterAudioCallback(this) != 0)

// ADM initialization

if (shared_->audio_device()->Init() != 0)

// Initialize the default speaker
if (shared_->audio_device()->SetPlayoutDevice(WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0)
if (shared_->audio_device()->InitSpeaker() != 0)

// Initialize the default microphone

if (shared_->audio_device()->SetRecordingDevice(WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0)
if (shared_->audio_device()->InitMicrophone() != 0)

// Set number of channels

if (shared_->audio_device()->StereoPlayoutIsAvailable(&available) != 0)
if (shared_->audio_device()->SetStereoPlayout(available) != 0)

if (!audioproc) {

audioproc = AudioProcessing::Create();
}
shared_->set_audio_processing(audioproc);
}

webrtc自带client的音频引擎创建代码走读

标签:const   decode   ice   ase   options   his   定义   elf   set   

原文地址:http://www.cnblogs.com/zxpo/p/7667270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!