| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/base/timeutils.h" | 11 #include "webrtc/base/timeutils.h" |
| 12 #include "webrtc/voice_engine/monitor_module.h" | 12 #include "webrtc/voice_engine/monitor_module.h" |
| 13 | 13 |
| 14 namespace webrtc { | 14 namespace webrtc { |
| 15 | 15 |
| 16 namespace voe { | 16 namespace voe { |
| 17 | 17 |
| 18 MonitorModule::MonitorModule() : | 18 MonitorModule::MonitorModule() |
| 19 _observerPtr(NULL), | 19 : _observerPtr(nullptr), _lastProcessTime(rtc::TimeMillis()) {} |
| 20 _lastProcessTime(rtc::TimeMillis()) | |
| 21 { | |
| 22 } | |
| 23 | 20 |
| 24 MonitorModule::~MonitorModule() | 21 MonitorModule::~MonitorModule() |
| 25 { | 22 { |
| 26 } | 23 } |
| 27 | 24 |
| 28 int32_t | 25 int32_t |
| 29 MonitorModule::RegisterObserver(MonitorObserver& observer) | 26 MonitorModule::RegisterObserver(MonitorObserver& observer) |
| 30 { | 27 { |
| 31 rtc::CritScope lock(&_callbackCritSect); | 28 rtc::CritScope lock(&_callbackCritSect); |
| 32 if (_observerPtr) | 29 if (_observerPtr) |
| 33 { | 30 { |
| 34 return -1; | 31 return -1; |
| 35 } | 32 } |
| 36 _observerPtr = &observer; | 33 _observerPtr = &observer; |
| 37 return 0; | 34 return 0; |
| 38 } | 35 } |
| 39 | 36 |
| 40 int32_t | 37 int32_t |
| 41 MonitorModule::DeRegisterObserver() | 38 MonitorModule::DeRegisterObserver() |
| 42 { | 39 { |
| 43 rtc::CritScope lock(&_callbackCritSect); | 40 rtc::CritScope lock(&_callbackCritSect); |
| 44 if (!_observerPtr) | 41 if (!_observerPtr) |
| 45 { | 42 { |
| 46 return 0; | 43 return 0; |
| 47 } | 44 } |
| 48 _observerPtr = NULL; | 45 _observerPtr = nullptr; |
| 49 return 0; | 46 return 0; |
| 50 } | 47 } |
| 51 | 48 |
| 52 int64_t | 49 int64_t |
| 53 MonitorModule::TimeUntilNextProcess() | 50 MonitorModule::TimeUntilNextProcess() |
| 54 { | 51 { |
| 55 int64_t now = rtc::TimeMillis(); | 52 int64_t now = rtc::TimeMillis(); |
| 56 const int64_t kAverageProcessUpdateTimeMs = 1000; | 53 const int64_t kAverageProcessUpdateTimeMs = 1000; |
| 57 return kAverageProcessUpdateTimeMs - (now - _lastProcessTime); | 54 return kAverageProcessUpdateTimeMs - (now - _lastProcessTime); |
| 58 } | 55 } |
| 59 | 56 |
| 60 void | 57 void |
| 61 MonitorModule::Process() | 58 MonitorModule::Process() |
| 62 { | 59 { |
| 63 _lastProcessTime = rtc::TimeMillis(); | 60 _lastProcessTime = rtc::TimeMillis(); |
| 64 rtc::CritScope lock(&_callbackCritSect); | 61 rtc::CritScope lock(&_callbackCritSect); |
| 65 if (_observerPtr) | 62 if (_observerPtr) |
| 66 { | 63 { |
| 67 _observerPtr->OnPeriodicProcess(); | 64 _observerPtr->OnPeriodicProcess(); |
| 68 } | 65 } |
| 69 } | 66 } |
| 70 | 67 |
| 71 } // namespace voe | 68 } // namespace voe |
| 72 | 69 |
| 73 } // namespace webrtc | 70 } // namespace webrtc |
| OLD | NEW |