Simplify webrtc::voe::MonitorModule and remove the .cc file.

The class basically implements a timer and can be replaced with a PostDelayedTask call down the line.

BUG=none

Review-Url: https://codereview.webrtc.org/2722613002
Cr-Commit-Position: refs/heads/master@{#16891}
This commit is contained in:
tommi
2017-02-28 01:16:48 -08:00
committed by Commit bot
parent 985371bda9
commit b1175bb101
5 changed files with 21 additions and 115 deletions

View File

@ -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",

View File

@ -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

View File

@ -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 <typename Observer>
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

View File

@ -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;
}

View File

@ -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<TransmitMixer> _monitorModule;
AudioFrame _audioFrame;
PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate
std::unique_ptr<FilePlayer> file_player_;