From 03f33709f8be1da10dde6a2c9b2da5fbc3d35099 Mon Sep 17 00:00:00 2001 From: "turaj@webrtc.org" Date: Wed, 13 Nov 2013 00:02:48 +0000 Subject: [PATCH] Inject config when creating channels to override the existing one. BUG= R=xians@webrtc.org Review URL: https://webrtc-codereview.appspot.com/3239004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5116 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/voice_engine/channel_manager.cc | 11 +++++- webrtc/voice_engine/channel_manager.h | 10 ++++- webrtc/voice_engine/include/voe_base.h | 3 ++ webrtc/voice_engine/voe_base_impl.cc | 53 ++++++++++++++++---------- webrtc/voice_engine/voe_base_impl.h | 5 +++ 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/webrtc/voice_engine/channel_manager.cc b/webrtc/voice_engine/channel_manager.cc index b56c54a828..9386257476 100644 --- a/webrtc/voice_engine/channel_manager.cc +++ b/webrtc/voice_engine/channel_manager.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/common.h" #include "webrtc/voice_engine/channel_manager.h" #include "webrtc/voice_engine/channel.h" @@ -51,8 +52,16 @@ ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) config_(config) {} ChannelOwner ChannelManager::CreateChannel() { + return CreateChannelInternal(config_); +} + +ChannelOwner ChannelManager::CreateChannel(const Config& external_config) { + return CreateChannelInternal(external_config); +} + +ChannelOwner ChannelManager::CreateChannelInternal(const Config& config) { Channel* channel; - Channel::CreateChannel(channel, ++last_channel_id_, instance_id_, config_); + Channel::CreateChannel(channel, ++last_channel_id_, instance_id_, config); ChannelOwner channel_owner(channel); CriticalSectionScoped crit(lock_.get()); diff --git a/webrtc/voice_engine/channel_manager.h b/webrtc/voice_engine/channel_manager.h index 85e64fabaf..1da976dc83 100644 --- a/webrtc/voice_engine/channel_manager.h +++ b/webrtc/voice_engine/channel_manager.h @@ -92,8 +92,13 @@ class ChannelManager { DISALLOW_COPY_AND_ASSIGN(Iterator); }; - // CreateChannel will always return a valid ChannelOwner instance. + // CreateChannel will always return a valid ChannelOwner instance. The channel + // is created either based on internal configuration, i.e. |config_|, by + // calling CreateChannel(), or using and external configuration + // |external_config| if the overloaded method + // CreateChannel(const Config& external_config) is called. ChannelOwner CreateChannel(); + ChannelOwner CreateChannel(const Config& external_config); // ChannelOwner.channel() will be NULL if channel_id is invalid or no longer // exists. This should be checked with ChannelOwner::IsValid(). @@ -106,6 +111,9 @@ class ChannelManager { size_t NumOfChannels() const; private: + // Create a channel given a configuration, |config|. + ChannelOwner CreateChannelInternal(const Config& config); + uint32_t instance_id_; Atomic32 last_channel_id_; diff --git a/webrtc/voice_engine/include/voe_base.h b/webrtc/voice_engine/include/voe_base.h index 6859ddbe4e..f54027b8a4 100644 --- a/webrtc/voice_engine/include/voe_base.h +++ b/webrtc/voice_engine/include/voe_base.h @@ -133,7 +133,10 @@ public: virtual int Terminate() = 0; // Creates a new channel and allocates the required resources for it. + // One can use |config| to configure the channel. Currently that is used for + // choosing between ACM1 and ACM2, when creating Audio Coding Module. virtual int CreateChannel() = 0; + virtual int CreateChannel(const Config& config) = 0; // Deletes an existing channel and releases the utilized resources. virtual int DeleteChannel(int channel) = 0; diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc index c76e06deed..402395d4bb 100644 --- a/webrtc/voice_engine/voe_base_impl.cc +++ b/webrtc/voice_engine/voe_base_impl.cc @@ -10,6 +10,7 @@ #include "webrtc/voice_engine/voe_base_impl.h" +#include "webrtc/common.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" #include "webrtc/modules/audio_device/audio_device_impl.h" @@ -520,22 +521,34 @@ int VoEBaseImpl::Terminate() return TerminateInternal(); } -int VoEBaseImpl::CreateChannel() +int VoEBaseImpl::CreateChannel() { + WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), + "CreateChannel()"); + CriticalSectionScoped cs(_shared->crit_sec()); + if (!_shared->statistics().Initialized()) { + _shared->SetLastError(VE_NOT_INITED, kTraceError); + return -1; + } + + voe::ChannelOwner channel_owner = _shared->channel_manager().CreateChannel(); + + return InitializeChannel(&channel_owner); +} + +int VoEBaseImpl::CreateChannel(const Config& config) { + CriticalSectionScoped cs(_shared->crit_sec()); + if (!_shared->statistics().Initialized()) { + _shared->SetLastError(VE_NOT_INITED, kTraceError); + return -1; + } + voe::ChannelOwner channel_owner = _shared->channel_manager().CreateChannel( + config); + return InitializeChannel(&channel_owner); +} + +int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "CreateChannel()"); - CriticalSectionScoped cs(_shared->crit_sec()); - - if (!_shared->statistics().Initialized()) - { - _shared->SetLastError(VE_NOT_INITED, kTraceError); - return -1; - } - - voe::ChannelOwner channel_owner = - _shared->channel_manager().CreateChannel(); - - if (channel_owner.channel()->SetEngineInformation( + if (channel_owner->channel()->SetEngineInformation( _shared->statistics(), *_shared->output_mixer(), *_shared->transmit_mixer(), @@ -549,23 +562,23 @@ int VoEBaseImpl::CreateChannel() "CreateChannel() failed to associate engine and channel." " Destroying channel."); _shared->channel_manager() - .DestroyChannel(channel_owner.channel()->ChannelId()); + .DestroyChannel(channel_owner->channel()->ChannelId()); return -1; - } else if (channel_owner.channel()->Init() != 0) { + } else if (channel_owner->channel()->Init() != 0) { _shared->SetLastError( VE_CHANNEL_NOT_CREATED, kTraceError, "CreateChannel() failed to initialize channel. Destroying" " channel."); _shared->channel_manager() - .DestroyChannel(channel_owner.channel()->ChannelId()); + .DestroyChannel(channel_owner->channel()->ChannelId()); return -1; } WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), - "CreateChannel() => %d", channel_owner.channel()->ChannelId()); - return channel_owner.channel()->ChannelId(); + "CreateChannel() => %d", channel_owner->channel()->ChannelId()); + return channel_owner->channel()->ChannelId(); } int VoEBaseImpl::DeleteChannel(int channel) diff --git a/webrtc/voice_engine/voe_base_impl.h b/webrtc/voice_engine/voe_base_impl.h index 6715c3602e..bee2ea37cf 100644 --- a/webrtc/voice_engine/voe_base_impl.h +++ b/webrtc/voice_engine/voe_base_impl.h @@ -39,6 +39,7 @@ public: virtual int Terminate(); virtual int CreateChannel(); + virtual int CreateChannel(const Config& config); virtual int DeleteChannel(int channel); @@ -133,6 +134,10 @@ private: int32_t AddBuildInfo(char* str) const; int32_t AddVoEVersion(char* str) const; + + // Initialize channel by setting Engine Information then initializing + // channel. + int InitializeChannel(voe::ChannelOwner* channel_owner); #ifdef WEBRTC_EXTERNAL_TRANSPORT int32_t AddExternalTransportBuild(char* str) const; #endif