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