blob: a69c2b61560b61d5f4f81c95bf86e1554e63cfe0 [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
31WebRtc_Word32
32MonitorModule::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
43WebRtc_Word32
44MonitorModule::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
55WebRtc_Word32
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +000056MonitorModule::Version(char* version,
niklase@google.com470e71d2011-07-07 08:21:25 +000057 WebRtc_UWord32& remainingBufferInBytes,
58 WebRtc_UWord32& position) const
59{
60 return 0;
61}
62
63WebRtc_Word32
64MonitorModule::ChangeUniqueId(const WebRtc_Word32 id)
65{
66 return 0;
67}
68
69WebRtc_Word32
70MonitorModule::TimeUntilNextProcess()
71{
andrew@webrtc.org00c7c432013-01-02 16:06:39 +000072 WebRtc_UWord32 now = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +000073 WebRtc_Word32 timeToNext =
74 kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
75 return (timeToNext);
76}
77
78WebRtc_Word32
79MonitorModule::Process()
80{
andrew@webrtc.org00c7c432013-01-02 16:06:39 +000081 _lastProcessTime = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +000082 if (_observerPtr)
83 {
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000084 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000085 _observerPtr->OnPeriodicProcess();
86 }
87 return 0;
88}
89
90} // namespace voe
91
92} // namespace webrtc