• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "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"
14 
15 namespace webrtc  {
16 
17 namespace voe  {
18 
MonitorModule()19 MonitorModule::MonitorModule() :
20     _observerPtr(NULL),
21     _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
22     _lastProcessTime(TickTime::MillisecondTimestamp())
23 {
24 }
25 
~MonitorModule()26 MonitorModule::~MonitorModule()
27 {
28     delete &_callbackCritSect;
29 }
30 
31 int32_t
RegisterObserver(MonitorObserver & observer)32 MonitorModule::RegisterObserver(MonitorObserver& observer)
33 {
34     CriticalSectionScoped lock(&_callbackCritSect);
35     if (_observerPtr)
36     {
37         return -1;
38     }
39     _observerPtr = &observer;
40     return 0;
41 }
42 
43 int32_t
DeRegisterObserver()44 MonitorModule::DeRegisterObserver()
45 {
46     CriticalSectionScoped lock(&_callbackCritSect);
47     if (!_observerPtr)
48     {
49         return 0;
50     }
51     _observerPtr = NULL;
52     return 0;
53 }
54 
55 int32_t
Version(char * version,uint32_t & remainingBufferInBytes,uint32_t & position) const56 MonitorModule::Version(char* version,
57                        uint32_t& remainingBufferInBytes,
58                        uint32_t& position) const
59 {
60     return 0;
61 }
62 
63 int32_t
ChangeUniqueId(int32_t id)64 MonitorModule::ChangeUniqueId(int32_t id)
65 {
66     return 0;
67 }
68 
69 int32_t
TimeUntilNextProcess()70 MonitorModule::TimeUntilNextProcess()
71 {
72     uint32_t now = TickTime::MillisecondTimestamp();
73     int32_t timeToNext =
74         kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
75     return (timeToNext);
76 }
77 
78 int32_t
Process()79 MonitorModule::Process()
80 {
81     _lastProcessTime = TickTime::MillisecondTimestamp();
82     if (_observerPtr)
83     {
84         CriticalSectionScoped lock(&_callbackCritSect);
85         _observerPtr->OnPeriodicProcess();
86     }
87     return 0;
88 }
89 
90 }  // namespace voe
91 
92 }  // namespace webrtc
93