blob: 88de5c880d74b98c7406c359c39eb94455811a12 [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
pbos@webrtc.org6141e132013-04-09 10:09:10 +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
pbos@webrtc.org6141e132013-04-09 10:09:10 +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
pbos@webrtc.org6141e132013-04-09 10:09:10 +000055int32_t
pbos@webrtc.org92135212013-05-14 08:31:39 +000056MonitorModule::ChangeUniqueId(int32_t id)
niklase@google.com470e71d2011-07-07 08:21:25 +000057{
58 return 0;
59}
60
pbos@webrtc.org6141e132013-04-09 10:09:10 +000061int32_t
niklase@google.com470e71d2011-07-07 08:21:25 +000062MonitorModule::TimeUntilNextProcess()
63{
pbos@webrtc.org6141e132013-04-09 10:09:10 +000064 uint32_t now = TickTime::MillisecondTimestamp();
65 int32_t timeToNext =
niklase@google.com470e71d2011-07-07 08:21:25 +000066 kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
67 return (timeToNext);
68}
69
pbos@webrtc.org6141e132013-04-09 10:09:10 +000070int32_t
niklase@google.com470e71d2011-07-07 08:21:25 +000071MonitorModule::Process()
72{
andrew@webrtc.org00c7c432013-01-02 16:06:39 +000073 _lastProcessTime = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +000074 if (_observerPtr)
75 {
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000076 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000077 _observerPtr->OnPeriodicProcess();
78 }
79 return 0;
80}
81
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000082} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +000083
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000084} // namespace webrtc