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 | |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 11 | #include "webrtc/system_wrappers/include/tick_util.h" |
andrew@webrtc.org | 00c7c43 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 12 | #include "webrtc/voice_engine/monitor_module.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | namespace webrtc { |
| 15 | |
| 16 | namespace voe { |
| 17 | |
| 18 | MonitorModule::MonitorModule() : |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | _observerPtr(NULL), |
andrew@webrtc.org | 00c7c43 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 20 | _lastProcessTime(TickTime::MillisecondTimestamp()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | { |
| 22 | } |
| 23 | |
| 24 | MonitorModule::~MonitorModule() |
| 25 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | } |
| 27 | |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 28 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | MonitorModule::RegisterObserver(MonitorObserver& observer) |
| 30 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 31 | rtc::CritScope lock(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | if (_observerPtr) |
| 33 | { |
| 34 | return -1; |
| 35 | } |
| 36 | _observerPtr = &observer; |
| 37 | return 0; |
| 38 | } |
| 39 | |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 40 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | MonitorModule::DeRegisterObserver() |
| 42 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 43 | rtc::CritScope lock(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | if (!_observerPtr) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | _observerPtr = NULL; |
| 49 | return 0; |
| 50 | } |
| 51 | |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 52 | int64_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | MonitorModule::TimeUntilNextProcess() |
| 54 | { |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 55 | int64_t now = TickTime::MillisecondTimestamp(); |
| 56 | const int64_t kAverageProcessUpdateTimeMs = 1000; |
| 57 | return kAverageProcessUpdateTimeMs - (now - _lastProcessTime); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | } |
| 59 | |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 60 | void |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | MonitorModule::Process() |
| 62 | { |
andrew@webrtc.org | 00c7c43 | 2013-01-02 16:06:39 +0000 | [diff] [blame] | 63 | _lastProcessTime = TickTime::MillisecondTimestamp(); |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 64 | rtc::CritScope lock(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | if (_observerPtr) |
| 66 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | _observerPtr->OnPeriodicProcess(); |
| 68 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | } |
| 70 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 71 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 73 | } // namespace webrtc |