diff options
author | turaj@webrtc.org <turaj@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-11-13 00:02:48 +0000 |
---|---|---|
committer | turaj@webrtc.org <turaj@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-11-13 00:02:48 +0000 |
commit | b43ac9f2c5d33f5613ad2757e1e62a0aa3c2d34f (patch) | |
tree | 5e7a8f53fbbf644e1efeb4155f630289a8dc4c44 | |
parent | 591be3b50428e3c1ea6c29093d1d97e6b3743273 (diff) | |
download | webrtc-b43ac9f2c5d33f5613ad2757e1e62a0aa3c2d34f.tar.gz |
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/webrtc@5116 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r-- | voice_engine/channel_manager.cc | 11 | ||||
-rw-r--r-- | voice_engine/channel_manager.h | 10 | ||||
-rw-r--r-- | voice_engine/include/voe_base.h | 3 | ||||
-rw-r--r-- | voice_engine/voe_base_impl.cc | 49 | ||||
-rw-r--r-- | voice_engine/voe_base_impl.h | 5 |
5 files changed, 58 insertions, 20 deletions
diff --git a/voice_engine/channel_manager.cc b/voice_engine/channel_manager.cc index b56c54a8..93862574 100644 --- a/voice_engine/channel_manager.cc +++ b/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/voice_engine/channel_manager.h b/voice_engine/channel_manager.h index 85e64fab..1da976dc 100644 --- a/voice_engine/channel_manager.h +++ b/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/voice_engine/include/voe_base.h b/voice_engine/include/voe_base.h index 6859ddbe..f54027b8 100644 --- a/voice_engine/include/voe_base.h +++ b/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/voice_engine/voe_base_impl.cc b/voice_engine/voe_base_impl.cc index c76e06de..402395d4 100644 --- a/voice_engine/voe_base_impl.cc +++ b/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() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "CreateChannel()"); - CriticalSectionScoped cs(_shared->crit_sec()); +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; + } - if (!_shared->statistics().Initialized()) - { - _shared->SetLastError(VE_NOT_INITED, kTraceError); - return -1; - } + voe::ChannelOwner channel_owner = _shared->channel_manager().CreateChannel(); + + return InitializeChannel(&channel_owner); +} - voe::ChannelOwner channel_owner = - _shared->channel_manager().CreateChannel(); +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); +} - if (channel_owner.channel()->SetEngineInformation( +int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) +{ + 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/voice_engine/voe_base_impl.h b/voice_engine/voe_base_impl.h index 6715c360..bee2ea37 100644 --- a/voice_engine/voe_base_impl.h +++ b/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 |