blob: ca358022a5b702dead95feef961f3ce37f767e3a [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
andrew@webrtc.org00c7c432013-01-02 16:06:39 +000011#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
12#include "webrtc/system_wrappers/interface/tick_util.h"
13#include "webrtc/voice_engine/monitor_module.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000014
15namespace webrtc {
16
17namespace voe {
18
19MonitorModule::MonitorModule() :
niklase@google.com470e71d2011-07-07 08:21:25 +000020 _observerPtr(NULL),
xians@google.com22963ab2011-08-03 12:40:23 +000021 _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
andrew@webrtc.org00c7c432013-01-02 16:06:39 +000022 _lastProcessTime(TickTime::MillisecondTimestamp())
niklase@google.com470e71d2011-07-07 08:21:25 +000023{
24}
25
26MonitorModule::~MonitorModule()
27{
28 delete &_callbackCritSect;
29}
30
tommi@webrtc.org41617152015-01-29 12:12:49 +000031int32_t
niklase@google.com470e71d2011-07-07 08:21:25 +000032MonitorModule::RegisterObserver(MonitorObserver& observer)
33{
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000034 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000035 if (_observerPtr)
36 {
37 return -1;
38 }
39 _observerPtr = &observer;
40 return 0;
41}
42
tommi@webrtc.org41617152015-01-29 12:12:49 +000043int32_t
niklase@google.com470e71d2011-07-07 08:21:25 +000044MonitorModule::DeRegisterObserver()
45{
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000046 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000047 if (!_observerPtr)
48 {
49 return 0;
50 }
51 _observerPtr = NULL;
52 return 0;
53}
54
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +000055int64_t
niklase@google.com470e71d2011-07-07 08:21:25 +000056MonitorModule::TimeUntilNextProcess()
57{
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +000058 int64_t now = TickTime::MillisecondTimestamp();
59 const int64_t kAverageProcessUpdateTimeMs = 1000;
60 return kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +000061}
62
tommi@webrtc.org41617152015-01-29 12:12:49 +000063int32_t
niklase@google.com470e71d2011-07-07 08:21:25 +000064MonitorModule::Process()
65{
andrew@webrtc.org00c7c432013-01-02 16:06:39 +000066 _lastProcessTime = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +000067 if (_observerPtr)
68 {
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000069 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000070 _observerPtr->OnPeriodicProcess();
71 }
72 return 0;
73}
74
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000075} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +000076
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000077} // namespace webrtc