blob: 2389a51ce31e1a7df2af4188fb27f4d3b072b2ce [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-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
andrew@webrtc.org143ce522013-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"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000014
15namespace webrtc {
16
17namespace voe {
18
19MonitorModule::MonitorModule() :
20 _observerPtr(NULL),
21 _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
andrew@webrtc.org143ce522013-01-02 16:06:39 +000022 _lastProcessTime(TickTime::MillisecondTimestamp())
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000023{
24}
25
26MonitorModule::~MonitorModule()
27{
28 delete &_callbackCritSect;
29}
30
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000031int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000032MonitorModule::RegisterObserver(MonitorObserver& observer)
33{
34 CriticalSectionScoped lock(&_callbackCritSect);
35 if (_observerPtr)
36 {
37 return -1;
38 }
39 _observerPtr = &observer;
40 return 0;
41}
42
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000043int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000044MonitorModule::DeRegisterObserver()
45{
46 CriticalSectionScoped lock(&_callbackCritSect);
47 if (!_observerPtr)
48 {
49 return 0;
50 }
51 _observerPtr = NULL;
52 return 0;
53}
54
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000055int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000056MonitorModule::Version(char* version,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000057 uint32_t& remainingBufferInBytes,
58 uint32_t& position) const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000059{
60 return 0;
61}
62
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000063int32_t
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000064MonitorModule::ChangeUniqueId(int32_t id)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000065{
66 return 0;
67}
68
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000069int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000070MonitorModule::TimeUntilNextProcess()
71{
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000072 uint32_t now = TickTime::MillisecondTimestamp();
73 int32_t timeToNext =
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000074 kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
75 return (timeToNext);
76}
77
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000078int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000079MonitorModule::Process()
80{
andrew@webrtc.org143ce522013-01-02 16:06:39 +000081 _lastProcessTime = TickTime::MillisecondTimestamp();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000082 if (_observerPtr)
83 {
84 CriticalSectionScoped lock(&_callbackCritSect);
85 _observerPtr->OnPeriodicProcess();
86 }
87 return 0;
88}
89
pbos@webrtc.org3b89e102013-07-03 15:12:26 +000090} // namespace voe
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000091
pbos@webrtc.org3b89e102013-07-03 15:12:26 +000092} // namespace webrtc