blob: 07b17fb1a4787f20b9a5565e458215cff93d191f [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
11#include "critical_section_wrapper.h"
12#include "monitor_module.h"
13
14namespace webrtc {
15
16namespace voe {
17
18MonitorModule::MonitorModule() :
niklase@google.com470e71d2011-07-07 08:21:25 +000019 _observerPtr(NULL),
xians@google.com22963ab2011-08-03 12:40:23 +000020 _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
niklase@google.com470e71d2011-07-07 08:21:25 +000021 _lastProcessTime(GET_TIME_IN_MS())
22{
23}
24
25MonitorModule::~MonitorModule()
26{
27 delete &_callbackCritSect;
28}
29
30WebRtc_Word32
31MonitorModule::RegisterObserver(MonitorObserver& observer)
32{
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000033 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000034 if (_observerPtr)
35 {
36 return -1;
37 }
38 _observerPtr = &observer;
39 return 0;
40}
41
42WebRtc_Word32
43MonitorModule::DeRegisterObserver()
44{
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000045 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000046 if (!_observerPtr)
47 {
48 return 0;
49 }
50 _observerPtr = NULL;
51 return 0;
52}
53
54WebRtc_Word32
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +000055MonitorModule::Version(char* version,
niklase@google.com470e71d2011-07-07 08:21:25 +000056 WebRtc_UWord32& remainingBufferInBytes,
57 WebRtc_UWord32& position) const
58{
59 return 0;
60}
61
62WebRtc_Word32
63MonitorModule::ChangeUniqueId(const WebRtc_Word32 id)
64{
65 return 0;
66}
67
68WebRtc_Word32
69MonitorModule::TimeUntilNextProcess()
70{
71 WebRtc_UWord32 now = GET_TIME_IN_MS();
72 WebRtc_Word32 timeToNext =
73 kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
74 return (timeToNext);
75}
76
77WebRtc_Word32
78MonitorModule::Process()
79{
80 _lastProcessTime = GET_TIME_IN_MS();
81 if (_observerPtr)
82 {
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +000083 CriticalSectionScoped lock(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +000084 _observerPtr->OnPeriodicProcess();
85 }
86 return 0;
87}
88
89} // namespace voe
90
91} // namespace webrtc