andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
andrew@webrtc.org | 143ce52 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 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" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | namespace voe { |
| 18 | |
| 19 | MonitorModule::MonitorModule() : |
| 20 | _observerPtr(NULL), |
| 21 | _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), |
andrew@webrtc.org | 143ce52 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 22 | _lastProcessTime(TickTime::MillisecondTimestamp()) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 23 | { |
| 24 | } |
| 25 | |
| 26 | MonitorModule::~MonitorModule() |
| 27 | { |
| 28 | delete &_callbackCritSect; |
| 29 | } |
| 30 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 31 | int32_t |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 43 | int32_t |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 44 | MonitorModule::DeRegisterObserver() |
| 45 | { |
| 46 | CriticalSectionScoped lock(&_callbackCritSect); |
| 47 | if (!_observerPtr) |
| 48 | { |
| 49 | return 0; |
| 50 | } |
| 51 | _observerPtr = NULL; |
| 52 | return 0; |
| 53 | } |
| 54 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 55 | int32_t |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 56 | MonitorModule::Version(char* version, |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 57 | uint32_t& remainingBufferInBytes, |
| 58 | uint32_t& position) const |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 59 | { |
| 60 | return 0; |
| 61 | } |
| 62 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 63 | int32_t |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 64 | MonitorModule::ChangeUniqueId(int32_t id) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 65 | { |
| 66 | return 0; |
| 67 | } |
| 68 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 69 | int32_t |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 70 | MonitorModule::TimeUntilNextProcess() |
| 71 | { |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 72 | uint32_t now = TickTime::MillisecondTimestamp(); |
| 73 | int32_t timeToNext = |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 74 | kAverageProcessUpdateTimeMs - (now - _lastProcessTime); |
| 75 | return (timeToNext); |
| 76 | } |
| 77 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 78 | int32_t |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 79 | MonitorModule::Process() |
| 80 | { |
andrew@webrtc.org | 143ce52 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 81 | _lastProcessTime = TickTime::MillisecondTimestamp(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 82 | if (_observerPtr) |
| 83 | { |
| 84 | CriticalSectionScoped lock(&_callbackCritSect); |
| 85 | _observerPtr->OnPeriodicProcess(); |
| 86 | } |
| 87 | return 0; |
| 88 | } |
| 89 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 90 | } // namespace voe |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 91 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 92 | } // namespace webrtc |