diff --git a/webrtc/modules/audio_coding/main/interface/audio_coding_module.h b/webrtc/modules/audio_coding/main/interface/audio_coding_module.h index b705b4d982..12b5a63e11 100644 --- a/webrtc/modules/audio_coding/main/interface/audio_coding_module.h +++ b/webrtc/modules/audio_coding/main/interface/audio_coding_module.h @@ -1017,6 +1017,20 @@ class AudioCodingModule: public Module { virtual std::vector GetNackList(int round_trip_time_ms) const = 0; }; +struct AudioCodingModuleFactory { + AudioCodingModuleFactory() {} + virtual ~AudioCodingModuleFactory() {} + + virtual AudioCodingModule* Create(int id) const; +}; + +struct NewAudioCodingModuleFactory : AudioCodingModuleFactory { + NewAudioCodingModuleFactory() {} + virtual ~NewAudioCodingModuleFactory() {} + + virtual AudioCodingModule* Create(int id) const; +}; + } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_H_ diff --git a/webrtc/modules/audio_coding/main/source/audio_coding_module.cc b/webrtc/modules/audio_coding/main/source/audio_coding_module.cc index 570fec51c7..4ac40b77df 100644 --- a/webrtc/modules/audio_coding/main/source/audio_coding_module.cc +++ b/webrtc/modules/audio_coding/main/source/audio_coding_module.cc @@ -98,4 +98,14 @@ bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { } } +AudioCodingModule* AudioCodingModuleFactory::Create(int id) const { + return new AudioCodingModuleImpl(static_cast(id), + Clock::GetRealTimeClock()); +} + +AudioCodingModule* NewAudioCodingModuleFactory::Create(int id) const { + // TODO(minyue): return new AudioCodingModuleImpl (new version). + return NULL; +} + } // namespace webrtc diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 96554711fa..b1a2aa6c2d 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -10,6 +10,7 @@ #include "webrtc/voice_engine/channel.h" +#include "webrtc/common.h" #include "webrtc/modules/audio_device/include/audio_device.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" @@ -816,13 +817,14 @@ Channel::NeededFrequency(int32_t id) int32_t Channel::CreateChannel(Channel*& channel, int32_t channelId, - uint32_t instanceId) + uint32_t instanceId, + const Config& config) { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId,channelId), "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, instanceId); - channel = new Channel(channelId, instanceId); + channel = new Channel(channelId, instanceId, config); if (channel == NULL) { WEBRTC_TRACE(kTraceMemory, kTraceVoice, @@ -900,7 +902,8 @@ Channel::RecordFileEnded(int32_t id) } Channel::Channel(int32_t channelId, - uint32_t instanceId) : + uint32_t instanceId, + const Config& config) : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()), _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), _instanceId(instanceId), @@ -915,7 +918,7 @@ Channel::Channel(int32_t channelId, VoEModuleId(instanceId, channelId), Clock::GetRealTimeClock(), this, this, this, rtp_payload_registry_.get())), telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), - _audioCodingModule(*AudioCodingModule::Create( + _audioCodingModule(*config.Get().Create( VoEModuleId(instanceId, channelId))), _rtpDumpIn(*RtpDump::CreateRtpDump()), _rtpDumpOut(*RtpDump::CreateRtpDump()), diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index a61470755f..4d9146eb1b 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -36,6 +36,7 @@ namespace webrtc { class AudioDeviceModule; +class Config; class CriticalSectionWrapper; class FileWrapper; class ProcessThread; @@ -80,8 +81,9 @@ public: virtual ~Channel(); static int32_t CreateChannel(Channel*& channel, int32_t channelId, - uint32_t instanceId); - Channel(int32_t channelId, uint32_t instanceId); + uint32_t instanceId, + const Config& config); + Channel(int32_t channelId, uint32_t instanceId, const Config& config); int32_t Init(); int32_t SetEngineInformation( Statistics& engineStatistics, diff --git a/webrtc/voice_engine/channel_manager.cc b/webrtc/voice_engine/channel_manager.cc index 8110bb6a2d..b56c54a828 100644 --- a/webrtc/voice_engine/channel_manager.cc +++ b/webrtc/voice_engine/channel_manager.cc @@ -44,14 +44,15 @@ ChannelOwner& ChannelOwner::operator=(const ChannelOwner& other) { ChannelOwner::ChannelRef::ChannelRef(class Channel* channel) : channel(channel), ref_count(1) {} -ChannelManager::ChannelManager(uint32_t instance_id) +ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) : instance_id_(instance_id), last_channel_id_(-1), - lock_(CriticalSectionWrapper::CreateCriticalSection()) {} + lock_(CriticalSectionWrapper::CreateCriticalSection()), + config_(config) {} ChannelOwner ChannelManager::CreateChannel() { Channel* channel; - Channel::CreateChannel(channel, ++last_channel_id_, instance_id_); + 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 4efeb15fc2..85e64fabaf 100644 --- a/webrtc/voice_engine/channel_manager.h +++ b/webrtc/voice_engine/channel_manager.h @@ -20,6 +20,9 @@ #include "webrtc/typedefs.h" namespace webrtc { + +class Config; + namespace voe { class Channel; @@ -66,7 +69,7 @@ class ChannelOwner { class ChannelManager { public: - ChannelManager(uint32_t instance_id); + ChannelManager(uint32_t instance_id, const Config& config); // Upon construction of an Iterator it will grab a copy of the channel list of // the ChannelManager. The iteration will then occur over this state, not the @@ -110,6 +113,8 @@ class ChannelManager { scoped_ptr lock_; std::vector channels_; + const Config& config_; + DISALLOW_COPY_AND_ASSIGN(ChannelManager); }; } // namespace voe diff --git a/webrtc/voice_engine/include/voe_base.h b/webrtc/voice_engine/include/voe_base.h index de483b4356..6859ddbe4e 100644 --- a/webrtc/voice_engine/include/voe_base.h +++ b/webrtc/voice_engine/include/voe_base.h @@ -40,6 +40,7 @@ namespace webrtc { class AudioDeviceModule; class AudioProcessing; +class Config; const int kVoEDefault = -1; @@ -63,6 +64,7 @@ public: // Creates a VoiceEngine object, which can then be used to acquire // sub-APIs. Returns NULL on failure. static VoiceEngine* Create(); + static VoiceEngine* Create(const Config& config); // Deletes a created VoiceEngine object and releases the utilized resources. // Note that if there are outstanding references held via other interfaces, diff --git a/webrtc/voice_engine/shared_data.cc b/webrtc/voice_engine/shared_data.cc index 843d5db6e3..2d485ae719 100644 --- a/webrtc/voice_engine/shared_data.cc +++ b/webrtc/voice_engine/shared_data.cc @@ -23,10 +23,10 @@ namespace voe { static int32_t _gInstanceCounter = 0; -SharedData::SharedData() : +SharedData::SharedData(const Config& config) : _instanceId(++_gInstanceCounter), _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()), - _channelManager(_gInstanceCounter), + _channelManager(_gInstanceCounter, config), _engineStatistics(_gInstanceCounter), _audioDevicePtr(NULL), audioproc_(NULL), diff --git a/webrtc/voice_engine/shared_data.h b/webrtc/voice_engine/shared_data.h index a841547a2e..7c7ad5c93b 100644 --- a/webrtc/voice_engine/shared_data.h +++ b/webrtc/voice_engine/shared_data.h @@ -22,6 +22,7 @@ class ProcessThread; namespace webrtc { +class Config; class CriticalSectionWrapper; namespace voe { @@ -79,7 +80,7 @@ protected: AudioDeviceModule::AudioLayer _audioDeviceLayer; - SharedData(); + SharedData(const Config& config); virtual ~SharedData(); }; diff --git a/webrtc/voice_engine/voice_engine_impl.cc b/webrtc/voice_engine/voice_engine_impl.cc index 4c923ebc00..703b6a4470 100644 --- a/webrtc/voice_engine/voice_engine_impl.cc +++ b/webrtc/voice_engine/voice_engine_impl.cc @@ -16,6 +16,7 @@ #endif #endif +#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" #include "webrtc/system_wrappers/interface/trace.h" #include "webrtc/voice_engine/voice_engine_impl.h" @@ -28,13 +29,26 @@ namespace webrtc // improvement here. static int32_t gVoiceEngineInstanceCounter = 0; -extern "C" +VoiceEngine* GetVoiceEngine(const Config* config, bool owns_config) { -WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine(); +#if (defined _WIN32) + HMODULE hmod = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll")); -VoiceEngine* GetVoiceEngine() -{ - VoiceEngineImpl* self = new VoiceEngineImpl(); + if (hmod) { + typedef VoiceEngine* (*PfnGetVoiceEngine)(void); + PfnGetVoiceEngine pfn = (PfnGetVoiceEngine)GetProcAddress( + hmod,"GetVoiceEngine"); + if (pfn) { + VoiceEngine* self = pfn(); + if (owns_config) { + delete config; + } + return (self); + } + } +#endif + + VoiceEngineImpl* self = new VoiceEngineImpl(config, owns_config); if (self != NULL) { self->AddRef(); // First reference. Released in VoiceEngine::Delete. @@ -42,7 +56,6 @@ VoiceEngine* GetVoiceEngine() } return self; } -} // extern "C" int VoiceEngineImpl::AddRef() { return ++_ref_count; @@ -63,25 +76,15 @@ int VoiceEngineImpl::Release() { return new_ref; } -VoiceEngine* VoiceEngine::Create() -{ -#if (defined _WIN32) - HMODULE hmod_ = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll")); +VoiceEngine* VoiceEngine::Create() { + Config* config = new Config(); + config->Set(new AudioCodingModuleFactory()); - if (hmod_) - { - typedef VoiceEngine* (*PfnGetVoiceEngine)(void); - PfnGetVoiceEngine pfn = (PfnGetVoiceEngine)GetProcAddress( - hmod_,"GetVoiceEngine"); - if (pfn) - { - VoiceEngine* self = pfn(); - return (self); - } - } -#endif + return GetVoiceEngine(config, true); +} - return GetVoiceEngine(); +VoiceEngine* VoiceEngine::Create(const Config& config) { + return GetVoiceEngine(&config, false); } int VoiceEngine::SetTraceFilter(unsigned int filter) diff --git a/webrtc/voice_engine/voice_engine_impl.h b/webrtc/voice_engine/voice_engine_impl.h index 55c4209543..fe6a7915ac 100644 --- a/webrtc/voice_engine/voice_engine_impl.h +++ b/webrtc/voice_engine/voice_engine_impl.h @@ -98,7 +98,8 @@ class VoiceEngineImpl : public voe::SharedData, // Must be the first base class public VoEBaseImpl { public: - VoiceEngineImpl() : + VoiceEngineImpl(const Config* config, bool owns_config) : + SharedData(*config), #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API VoEAudioProcessingImpl(this), #endif @@ -137,7 +138,8 @@ public: VoEVolumeControlImpl(this), #endif VoEBaseImpl(this), - _ref_count(0) + _ref_count(0), + own_config_(owns_config ? config : NULL) { } virtual ~VoiceEngineImpl() @@ -152,6 +154,7 @@ public: private: Atomic32 _ref_count; + scoped_ptr own_config_; }; } // namespace webrtc