blob: 07b17fb1a4787f20b9a5565e458215cff93d191f [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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() :
19 _observerPtr(NULL),
20 _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
21 _lastProcessTime(GET_TIME_IN_MS())
22{
23}
24
25MonitorModule::~MonitorModule()
26{
27 delete &_callbackCritSect;
28}
29
30WebRtc_Word32
31MonitorModule::RegisterObserver(MonitorObserver& observer)
32{
33 CriticalSectionScoped lock(&_callbackCritSect);
34 if (_observerPtr)
35 {
36 return -1;
37 }
38 _observerPtr = &observer;
39 return 0;
40}
41
42WebRtc_Word32
43MonitorModule::DeRegisterObserver()
44{
45 CriticalSectionScoped lock(&_callbackCritSect);
46 if (!_observerPtr)
47 {
48 return 0;
49 }
50 _observerPtr = NULL;
51 return 0;
52}
53
54WebRtc_Word32
55MonitorModule::Version(char* version,
56 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 {
83 CriticalSectionScoped lock(&_callbackCritSect);
84 _observerPtr->OnPeriodicProcess();
85 }
86 return 0;
87}
88
89} // namespace voe
90
91} // namespace webrtc