niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | 00c7c43 | 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" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | namespace voe { |
| 18 | |
| 19 | MonitorModule::MonitorModule() : |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | _observerPtr(NULL), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 21 | _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), |
andrew@webrtc.org | 00c7c43 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 22 | _lastProcessTime(TickTime::MillisecondTimestamp()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | { |
| 24 | } |
| 25 | |
| 26 | MonitorModule::~MonitorModule() |
| 27 | { |
| 28 | delete &_callbackCritSect; |
| 29 | } |
| 30 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 31 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | MonitorModule::RegisterObserver(MonitorObserver& observer) |
| 33 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 34 | CriticalSectionScoped lock(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | if (_observerPtr) |
| 36 | { |
| 37 | return -1; |
| 38 | } |
| 39 | _observerPtr = &observer; |
| 40 | return 0; |
| 41 | } |
| 42 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 43 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | MonitorModule::DeRegisterObserver() |
| 45 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 46 | CriticalSectionScoped lock(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | if (!_observerPtr) |
| 48 | { |
| 49 | return 0; |
| 50 | } |
| 51 | _observerPtr = NULL; |
| 52 | return 0; |
| 53 | } |
| 54 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 55 | int32_t |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 56 | MonitorModule::ChangeUniqueId(int32_t id) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame^] | 61 | int64_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | MonitorModule::TimeUntilNextProcess() |
| 63 | { |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame^] | 64 | int64_t now = TickTime::MillisecondTimestamp(); |
| 65 | const int64_t kAverageProcessUpdateTimeMs = 1000; |
| 66 | return kAverageProcessUpdateTimeMs - (now - _lastProcessTime); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | } |
| 68 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 69 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | MonitorModule::Process() |
| 71 | { |
andrew@webrtc.org | 00c7c43 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 72 | _lastProcessTime = TickTime::MillisecondTimestamp(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | if (_observerPtr) |
| 74 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 75 | CriticalSectionScoped lock(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | _observerPtr->OnPeriodicProcess(); |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 81 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 83 | } // namespace webrtc |