diff --git a/webrtc/voice_engine/BUILD.gn b/webrtc/voice_engine/BUILD.gn index e2755f3004..39a6697c8e 100644 --- a/webrtc/voice_engine/BUILD.gn +++ b/webrtc/voice_engine/BUILD.gn @@ -84,7 +84,6 @@ rtc_static_library("voice_engine") { "include/voe_network.h", "include/voe_rtp_rtcp.h", "include/voe_volume_control.h", - "monitor_module.cc", "monitor_module.h", "output_mixer.cc", "output_mixer.h", diff --git a/webrtc/voice_engine/monitor_module.cc b/webrtc/voice_engine/monitor_module.cc deleted file mode 100644 index 8a1865a95b..0000000000 --- a/webrtc/voice_engine/monitor_module.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/base/timeutils.h" -#include "webrtc/voice_engine/monitor_module.h" - -namespace webrtc { - -namespace voe { - -MonitorModule::MonitorModule() : - _observerPtr(NULL), - _lastProcessTime(rtc::TimeMillis()) -{ -} - -MonitorModule::~MonitorModule() -{ -} - -int32_t -MonitorModule::RegisterObserver(MonitorObserver& observer) -{ - rtc::CritScope lock(&_callbackCritSect); - if (_observerPtr) - { - return -1; - } - _observerPtr = &observer; - return 0; -} - -int32_t -MonitorModule::DeRegisterObserver() -{ - rtc::CritScope lock(&_callbackCritSect); - if (!_observerPtr) - { - return 0; - } - _observerPtr = NULL; - return 0; -} - -int64_t -MonitorModule::TimeUntilNextProcess() -{ - int64_t now = rtc::TimeMillis(); - const int64_t kAverageProcessUpdateTimeMs = 1000; - return kAverageProcessUpdateTimeMs - (now - _lastProcessTime); -} - -void -MonitorModule::Process() -{ - _lastProcessTime = rtc::TimeMillis(); - rtc::CritScope lock(&_callbackCritSect); - if (_observerPtr) - { - _observerPtr->OnPeriodicProcess(); - } -} - -} // namespace voe - -} // namespace webrtc diff --git a/webrtc/voice_engine/monitor_module.h b/webrtc/voice_engine/monitor_module.h index f026f725d5..ea29d93d80 100644 --- a/webrtc/voice_engine/monitor_module.h +++ b/webrtc/voice_engine/monitor_module.h @@ -11,47 +11,30 @@ #ifndef WEBRTC_VOICE_ENGINE_MONITOR_MODULE_H #define WEBRTC_VOICE_ENGINE_MONITOR_MODULE_H -#include "webrtc/base/criticalsection.h" -#include "webrtc/base/thread_annotations.h" #include "webrtc/modules/include/module.h" -#include "webrtc/typedefs.h" -#include "webrtc/voice_engine/voice_engine_defines.h" - -class MonitorObserver -{ -public: - virtual void OnPeriodicProcess() = 0; -protected: - virtual ~MonitorObserver() {} -}; - namespace webrtc { namespace voe { -class MonitorModule : public Module -{ -public: - int32_t RegisterObserver(MonitorObserver& observer); +// When associated with a ProcessThread, calls a callback method +// |OnPeriodicProcess()| implemented by the |Observer|. +// TODO(tommi): This could be replaced with PostDelayedTask(). +// Better yet, delete it and delete code related to |_saturationWarning| +// in TransmitMixer (and the OnPeriodicProcess callback). +template +class MonitorModule : public Module { + public: + explicit MonitorModule(Observer* observer) : observer_(observer) {} + ~MonitorModule() override {} - int32_t DeRegisterObserver(); + private: + int64_t TimeUntilNextProcess() override { return 1000; } + void Process() override { observer_->OnPeriodicProcess(); } - MonitorModule(); - - virtual ~MonitorModule(); -public: // module - int64_t TimeUntilNextProcess() override; - - void Process() override; - -private: - rtc::CriticalSection _callbackCritSect; - MonitorObserver* _observerPtr GUARDED_BY(_callbackCritSect); - int64_t _lastProcessTime; + Observer* const observer_; }; } // namespace voe - } // namespace webrtc -#endif // VOICE_ENGINE_MONITOR_MODULE +#endif // VOICE_ENGINE_MONITOR_MODULE diff --git a/webrtc/voice_engine/transmit_mixer.cc b/webrtc/voice_engine/transmit_mixer.cc index 5deee42854..7dbe380de9 100644 --- a/webrtc/voice_engine/transmit_mixer.cc +++ b/webrtc/voice_engine/transmit_mixer.cc @@ -64,7 +64,7 @@ TransmitMixer::OnPeriodicProcess() } } } -#endif +#endif // WEBRTC_VOICE_ENGINE_TYPING_DETECTION bool saturationWarning = false; { @@ -176,6 +176,7 @@ TransmitMixer::Destroy(TransmitMixer*& mixer) } TransmitMixer::TransmitMixer(uint32_t instanceId) : + _monitorModule(this), // Avoid conflict with other channels by adding 1024 - 1026, // won't use as much as 1024 channels. _filePlayerId(instanceId + 1024), @@ -191,7 +192,6 @@ TransmitMixer::~TransmitMixer() { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), "TransmitMixer::~TransmitMixer() - dtor"); - _monitorModule.DeRegisterObserver(); if (_processThreadPtr) { _processThreadPtr->DeRegisterModule(&_monitorModule); @@ -226,7 +226,6 @@ TransmitMixer::SetEngineInformation(ProcessThread& processThread, _channelManagerPtr = &channelManager; _processThreadPtr->RegisterModule(&_monitorModule); - _monitorModule.RegisterObserver(*this); return 0; } diff --git a/webrtc/voice_engine/transmit_mixer.h b/webrtc/voice_engine/transmit_mixer.h index 25f02b3bbc..d7ad473a1a 100644 --- a/webrtc/voice_engine/transmit_mixer.h +++ b/webrtc/voice_engine/transmit_mixer.h @@ -42,8 +42,7 @@ class ChannelManager; class MixedAudio; class Statistics; -class TransmitMixer : public MonitorObserver, - public FileCallback { +class TransmitMixer : public FileCallback { public: static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId); @@ -133,10 +132,9 @@ public: virtual ~TransmitMixer(); - // MonitorObserver + // Periodic callback from the MonitorModule. void OnPeriodicProcess(); - // FileCallback void PlayNotification(const int32_t id, const uint32_t durationMs); @@ -163,7 +161,7 @@ public: bool IsStereoChannelSwappingEnabled(); protected: - TransmitMixer() = default; + TransmitMixer() : _monitorModule(this) {} private: TransmitMixer(uint32_t instanceId); @@ -196,7 +194,7 @@ private: ProcessThread* _processThreadPtr = nullptr; // owns - MonitorModule _monitorModule; + MonitorModule _monitorModule; AudioFrame _audioFrame; PushResampler resampler_; // ADM sample rate -> mixing rate std::unique_ptr file_player_;