From 5f7cfa50e515634f84198f5f4a713f78e8e2019b Mon Sep 17 00:00:00 2001 From: ossu Date: Mon, 30 May 2016 08:11:28 -0700 Subject: [PATCH] Moved CreateBuiltinDecoderFactory out to VoEBaseImpl. VoEBase is plumbed to optionally take an AudioDecoderFactory, or create a builtin factory if none is provided. Retained the CreateChannel interfaces in Channel and ChannelManager and added variants for injecting an AudioDecoderFactory. The "old-style" variants call CreateBuiltinAudioDecoderFactory to get a factory to use. (Just realized this means each channel uses a separate factory with the old-style calls. Probably ok.) BUG=webrtc:5805 Review-Url: https://codereview.webrtc.org/1993783002 Cr-Commit-Position: refs/heads/master@{#12961} --- webrtc/media/engine/fakewebrtcvoiceengine.h | 7 +++++-- webrtc/test/mock_voice_engine.h | 8 +++++--- webrtc/voice_engine/channel.cc | 19 +++++++++++++++--- webrtc/voice_engine/channel.h | 10 +++++++++- webrtc/voice_engine/channel_manager.cc | 22 +++++++++++++++++---- webrtc/voice_engine/channel_manager.h | 11 ++++++++++- webrtc/voice_engine/include/voe_base.h | 7 ++++++- webrtc/voice_engine/voe_base_impl.cc | 17 ++++++++++++---- webrtc/voice_engine/voe_base_impl.h | 5 ++++- 9 files changed, 86 insertions(+), 20 deletions(-) diff --git a/webrtc/media/engine/fakewebrtcvoiceengine.h b/webrtc/media/engine/fakewebrtcvoiceengine.h index 13a3696853..9a328e9b8d 100644 --- a/webrtc/media/engine/fakewebrtcvoiceengine.h +++ b/webrtc/media/engine/fakewebrtcvoiceengine.h @@ -229,8 +229,11 @@ class FakeWebRtcVoiceEngine WEBRTC_STUB(RegisterVoiceEngineObserver, ( webrtc::VoiceEngineObserver& observer)); WEBRTC_STUB(DeRegisterVoiceEngineObserver, ()); - WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm, - webrtc::AudioProcessing* audioproc)) { + WEBRTC_FUNC(Init, + (webrtc::AudioDeviceModule* adm, + webrtc::AudioProcessing* audioproc, + const rtc::scoped_refptr& + decoder_factory)) { inited_ = true; return 0; } diff --git a/webrtc/test/mock_voice_engine.h b/webrtc/test/mock_voice_engine.h index b9eb05fb8b..aa71e434b7 100644 --- a/webrtc/test/mock_voice_engine.h +++ b/webrtc/test/mock_voice_engine.h @@ -106,9 +106,11 @@ class MockVoiceEngine : public VoiceEngineImpl { // VoEBase MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer)); MOCK_METHOD0(DeRegisterVoiceEngineObserver, int()); - MOCK_METHOD2(Init, - int(AudioDeviceModule* external_adm, - AudioProcessing* audioproc)); + MOCK_METHOD3( + Init, + int(AudioDeviceModule* external_adm, + AudioProcessing* audioproc, + const rtc::scoped_refptr& decoder_factory)); MOCK_METHOD0(audio_processing, AudioProcessing*()); MOCK_METHOD0(Terminate, int()); MOCK_METHOD0(CreateChannel, int()); diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 8ccad33161..6b9de2976e 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -673,11 +673,23 @@ int32_t Channel::CreateChannel(Channel*& channel, uint32_t instanceId, RtcEventLog* const event_log, const Config& config) { + return CreateChannel(channel, channelId, instanceId, event_log, config, + CreateBuiltinAudioDecoderFactory()); +} + +int32_t Channel::CreateChannel( + Channel*& channel, + int32_t channelId, + uint32_t instanceId, + RtcEventLog* const event_log, + const Config& config, + const rtc::scoped_refptr& decoder_factory) { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, instanceId); - channel = new Channel(channelId, instanceId, event_log, config); + channel = + new Channel(channelId, instanceId, event_log, config, decoder_factory); if (channel == NULL) { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), "Channel::CreateChannel() unable to allocate memory for" @@ -737,7 +749,8 @@ void Channel::RecordFileEnded(int32_t id) { Channel::Channel(int32_t channelId, uint32_t instanceId, RtcEventLog* const event_log, - const Config& config) + const Config& config, + const rtc::scoped_refptr& decoder_factory) : _instanceId(instanceId), _channelId(channelId), event_log_(event_log), @@ -826,7 +839,7 @@ Channel::Channel(int32_t channelId, acm_config.neteq_config.enable_fast_accelerate = config.Get().enabled; acm_config.neteq_config.enable_muted_state = true; - acm_config.decoder_factory = CreateBuiltinAudioDecoderFactory(); + acm_config.decoder_factory = decoder_factory; audio_coding_.reset(AudioCodingModule::Create(acm_config)); _outputAudioLevel.Clear(); diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index cd31e7702d..9f789dfac3 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -175,10 +175,18 @@ class Channel uint32_t instanceId, RtcEventLog* const event_log, const Config& config); + static int32_t CreateChannel( + Channel*& channel, + int32_t channelId, + uint32_t instanceId, + RtcEventLog* const event_log, + const Config& config, + const rtc::scoped_refptr& decoder_factory); Channel(int32_t channelId, uint32_t instanceId, RtcEventLog* const event_log, - const Config& config); + const Config& config, + const rtc::scoped_refptr& decoder_factory); int32_t Init(); int32_t SetEngineInformation(Statistics& engineStatistics, OutputMixer& outputMixer, diff --git a/webrtc/voice_engine/channel_manager.cc b/webrtc/voice_engine/channel_manager.cc index 6071f19548..47350b59c9 100644 --- a/webrtc/voice_engine/channel_manager.cc +++ b/webrtc/voice_engine/channel_manager.cc @@ -11,6 +11,7 @@ #include "webrtc/voice_engine/channel_manager.h" #include "webrtc/common.h" +#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" #include "webrtc/voice_engine/channel.h" namespace webrtc { @@ -52,17 +53,30 @@ ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) event_log_(RtcEventLog::Create(Clock::GetRealTimeClock())) {} ChannelOwner ChannelManager::CreateChannel() { - return CreateChannelInternal(config_); + return CreateChannel(CreateBuiltinAudioDecoderFactory()); } ChannelOwner ChannelManager::CreateChannel(const Config& external_config) { - return CreateChannelInternal(external_config); + return CreateChannel(external_config, CreateBuiltinAudioDecoderFactory()); } -ChannelOwner ChannelManager::CreateChannelInternal(const Config& config) { +ChannelOwner ChannelManager::CreateChannel( + const rtc::scoped_refptr& decoder_factory) { + return CreateChannelInternal(config_, decoder_factory); +} + +ChannelOwner ChannelManager::CreateChannel( + const Config& external_config, + const rtc::scoped_refptr& decoder_factory) { + return CreateChannelInternal(external_config, decoder_factory); +} + +ChannelOwner ChannelManager::CreateChannelInternal( + const Config& config, + const rtc::scoped_refptr& decoder_factory) { Channel* channel; Channel::CreateChannel(channel, ++last_channel_id_, instance_id_, - event_log_.get(), config); + event_log_.get(), config, decoder_factory); ChannelOwner channel_owner(channel); rtc::CritScope crit(&lock_); diff --git a/webrtc/voice_engine/channel_manager.h b/webrtc/voice_engine/channel_manager.h index 77dfc454d8..213a48f769 100644 --- a/webrtc/voice_engine/channel_manager.h +++ b/webrtc/voice_engine/channel_manager.h @@ -16,6 +16,7 @@ #include "webrtc/base/constructormagic.h" #include "webrtc/base/criticalsection.h" +#include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/call/rtc_event_log.h" #include "webrtc/system_wrappers/include/atomic32.h" #include "webrtc/typedefs.h" @@ -23,6 +24,7 @@ namespace webrtc { class Config; +class AudioDecoderFactory; namespace voe { @@ -101,6 +103,11 @@ class ChannelManager { // CreateChannel(const Config& external_config) is called. ChannelOwner CreateChannel(); ChannelOwner CreateChannel(const Config& external_config); + ChannelOwner CreateChannel( + const rtc::scoped_refptr& decoder_factory); + ChannelOwner CreateChannel( + const Config& external_config, + const rtc::scoped_refptr& decoder_factory); // ChannelOwner.channel() will be NULL if channel_id is invalid or no longer // exists. This should be checked with ChannelOwner::IsValid(). @@ -117,7 +124,9 @@ class ChannelManager { private: // Create a channel given a configuration, |config|. - ChannelOwner CreateChannelInternal(const Config& config); + ChannelOwner CreateChannelInternal( + const Config& config, + const rtc::scoped_refptr& decoder_factory); uint32_t instance_id_; diff --git a/webrtc/voice_engine/include/voe_base.h b/webrtc/voice_engine/include/voe_base.h index 4001b94577..91df7d3e4f 100644 --- a/webrtc/voice_engine/include/voe_base.h +++ b/webrtc/voice_engine/include/voe_base.h @@ -34,6 +34,8 @@ #ifndef WEBRTC_VOICE_ENGINE_VOE_BASE_H #define WEBRTC_VOICE_ENGINE_VOE_BASE_H +#include "webrtc/base/scoped_ref_ptr.h" +#include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h" #include "webrtc/common_types.h" namespace webrtc { @@ -123,11 +125,14 @@ class WEBRTC_DLLEXPORT VoEBase { // functionality in a separate (reference counted) module. // - The AudioProcessing module handles capture-side processing. VoiceEngine // takes ownership of this object. + // - An AudioDecoderFactory - used to create audio decoders. // If NULL is passed for any of these, VoiceEngine will create its own. // Returns -1 in case of an error, 0 otherwise. // TODO(ajm): Remove default NULLs. virtual int Init(AudioDeviceModule* external_adm = NULL, - AudioProcessing* audioproc = NULL) = 0; + AudioProcessing* audioproc = NULL, + const rtc::scoped_refptr& + decoder_factory = nullptr) = 0; // Returns NULL before Init() is called. virtual AudioProcessing* audio_processing() = 0; diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc index 8e93778f7e..bfc85fc02a 100644 --- a/webrtc/voice_engine/voe_base_impl.cc +++ b/webrtc/voice_engine/voe_base_impl.cc @@ -14,6 +14,7 @@ #include "webrtc/base/logging.h" #include "webrtc/common.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_device/audio_device_impl.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" @@ -211,8 +212,10 @@ int VoEBaseImpl::DeRegisterVoiceEngineObserver() { return 0; } -int VoEBaseImpl::Init(AudioDeviceModule* external_adm, - AudioProcessing* audioproc) { +int VoEBaseImpl::Init( + AudioDeviceModule* external_adm, + AudioProcessing* audioproc, + const rtc::scoped_refptr& decoder_factory) { rtc::CritScope cs(shared_->crit_sec()); WebRtcSpl_Init(); if (shared_->statistics().Initialized()) { @@ -375,6 +378,11 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm, } #endif + if (decoder_factory) + decoder_factory_ = decoder_factory; + else + decoder_factory_ = CreateBuiltinAudioDecoderFactory(); + return shared_->statistics().SetInitialized(); } @@ -390,7 +398,8 @@ int VoEBaseImpl::CreateChannel() { return -1; } - voe::ChannelOwner channel_owner = shared_->channel_manager().CreateChannel(); + voe::ChannelOwner channel_owner = + shared_->channel_manager().CreateChannel(decoder_factory_); return InitializeChannel(&channel_owner); } @@ -401,7 +410,7 @@ int VoEBaseImpl::CreateChannel(const Config& config) { return -1; } voe::ChannelOwner channel_owner = - shared_->channel_manager().CreateChannel(config); + shared_->channel_manager().CreateChannel(config, decoder_factory_); return InitializeChannel(&channel_owner); } diff --git a/webrtc/voice_engine/voe_base_impl.h b/webrtc/voice_engine/voe_base_impl.h index ec18c59786..192518a025 100644 --- a/webrtc/voice_engine/voe_base_impl.h +++ b/webrtc/voice_engine/voe_base_impl.h @@ -29,7 +29,9 @@ class VoEBaseImpl : public VoEBase, int DeRegisterVoiceEngineObserver() override; int Init(AudioDeviceModule* external_adm = nullptr, - AudioProcessing* audioproc = nullptr) override; + AudioProcessing* audioproc = nullptr, + const rtc::scoped_refptr& decoder_factory = + nullptr) override; AudioProcessing* audio_processing() override { return shared_->audio_processing(); } @@ -143,6 +145,7 @@ class VoEBaseImpl : public VoEBase, int InitializeChannel(voe::ChannelOwner* channel_owner); VoiceEngineObserver* voiceEngineObserverPtr_; rtc::CriticalSection callbackCritSect_; + rtc::scoped_refptr decoder_factory_; AudioFrame audioFrame_; voe::SharedData* shared_;