From 6e9890d1aa07375d0c34d568324fe6fe3447401f Mon Sep 17 00:00:00 2001 From: "mflodman@webrtc.org" Date: Wed, 7 Nov 2012 10:48:40 +0000 Subject: [PATCH] Removed ViEBaseObserver. BUG=1037 TEST=Still compiles and ViE autotest passes. Review URL: https://webrtc-codereview.appspot.com/929012 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3052 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/video_engine/include/vie_base.h | 18 --- .../auto_test/source/vie_autotest_base.cc | 23 --- webrtc/video_engine/video_engine_core.gypi | 2 - webrtc/video_engine/vie_base_impl.cc | 25 ---- webrtc/video_engine/vie_base_impl.h | 2 - webrtc/video_engine/vie_channel_manager.cc | 1 - webrtc/video_engine/vie_channel_manager.h | 2 - .../video_engine/vie_performance_monitor.cc | 139 ------------------ webrtc/video_engine/vie_performance_monitor.h | 54 ------- webrtc/video_engine/vie_shared_data.cc | 2 - webrtc/video_engine/vie_shared_data.h | 4 - 11 files changed, 272 deletions(-) delete mode 100644 webrtc/video_engine/vie_performance_monitor.cc delete mode 100644 webrtc/video_engine/vie_performance_monitor.h diff --git a/webrtc/video_engine/include/vie_base.h b/webrtc/video_engine/include/vie_base.h index 5c7759d6b..8bbf1d585 100644 --- a/webrtc/video_engine/include/vie_base.h +++ b/webrtc/video_engine/include/vie_base.h @@ -25,17 +25,6 @@ namespace webrtc { class VoiceEngine; -// Class used for all callbacks from ViEBase. -class WEBRTC_DLLEXPORT ViEBaseObserver { - public: - // This method will be called periodically if the average system CPU usage - // exceeds 75%. - virtual void PerformanceAlarm(const unsigned int cpu_load) = 0; - - protected: - virtual ~ViEBaseObserver() {} -}; - class WEBRTC_DLLEXPORT VideoEngine { public: // Creates a VideoEngine object, which can then be used to acquire subā€APIs. @@ -126,13 +115,6 @@ class WEBRTC_DLLEXPORT ViEBase { // Stops receiving incoming RTP and RTCP packets on the specified channel. virtual int StopReceive(const int video_channel) = 0; - // Registers an instance of a user implementation of the ViEBase - // observer. - virtual int RegisterObserver(ViEBaseObserver& observer) = 0; - - // Removes an already registered instance of ViEBaseObserver. - virtual int DeregisterObserver() = 0; - // Retrieves the version information for VideoEngine and its components. virtual int GetVersion(char version[1024]) = 0; diff --git a/webrtc/video_engine/test/auto_test/source/vie_autotest_base.cc b/webrtc/video_engine/test/auto_test/source/vie_autotest_base.cc index a41b3097b..5f0ef7cff 100644 --- a/webrtc/video_engine/test/auto_test/source/vie_autotest_base.cc +++ b/webrtc/video_engine/test/auto_test/source/vie_autotest_base.cc @@ -15,17 +15,6 @@ #include "video_engine/test/auto_test/primitives/general_primitives.h" #include "video_engine/test/libvietest/include/tb_interfaces.h" -class BaseObserver : public webrtc::ViEBaseObserver { - public: - BaseObserver() - : cpu_load_(0) {} - - virtual void PerformanceAlarm(const unsigned int cpu_load) { - cpu_load_ = cpu_load; - } - unsigned int cpu_load_; -}; - void ViEAutoTest::ViEBaseStandardTest() { // *************************************************************** // Begin create/initialize WebRTC Video Engine for testing @@ -100,18 +89,6 @@ void ViEAutoTest::ViEBaseExtendedTest() { // Start with standard test ViEBaseAPITest(); ViEBaseStandardTest(); - - // *************************************************************** - // Test BaseObserver - // *************************************************************** - // TODO(mflodman) Add test for base observer. Cpu load must be over 75%. -// BaseObserver base_observer; -// EXPECT_EQ(vie_base->RegisterObserver(base_observer), 0); -// -// AutoTestSleep(KAutoTestSleepTimeMs); -// -// EXPECT_EQ(vie_base->DeregisterObserver(), 0); -// EXPECT_GT(base_observer.cpu_load, 0); } void ViEAutoTest::ViEBaseAPITest() { diff --git a/webrtc/video_engine/video_engine_core.gypi b/webrtc/video_engine/video_engine_core.gypi index bd0d2c71f..5606c2955 100644 --- a/webrtc/video_engine/video_engine_core.gypi +++ b/webrtc/video_engine/video_engine_core.gypi @@ -95,7 +95,6 @@ 'vie_frame_provider_base.h', 'vie_input_manager.h', 'vie_manager_base.h', - 'vie_performance_monitor.h', 'vie_receiver.h', 'vie_renderer.h', 'vie_render_manager.h', @@ -129,7 +128,6 @@ 'vie_frame_provider_base.cc', 'vie_input_manager.cc', 'vie_manager_base.cc', - 'vie_performance_monitor.cc', 'vie_receiver.cc', 'vie_remb.cc', 'vie_renderer.cc', diff --git a/webrtc/video_engine/vie_base_impl.cc b/webrtc/video_engine/vie_base_impl.cc index da24e92a0..386256b9f 100644 --- a/webrtc/video_engine/vie_base_impl.cc +++ b/webrtc/video_engine/vie_base_impl.cc @@ -27,7 +27,6 @@ #include "video_engine/include/vie_errors.h" #include "video_engine/vie_impl.h" #include "video_engine/vie_input_manager.h" -#include "video_engine/vie_performance_monitor.h" #include "video_engine/vie_shared_data.h" namespace webrtc { @@ -362,30 +361,6 @@ int ViEBaseImpl::StopReceive(const int video_channel) { return 0; } -int ViEBaseImpl::RegisterObserver(ViEBaseObserver& observer) { // NOLINT - WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()), - "%s", __FUNCTION__); - if (shared_data_.vie_performance_monitor()->ViEBaseObserverRegistered()) { - shared_data_.SetLastError(kViEBaseObserverAlreadyRegistered); - return -1; - } - return shared_data_.vie_performance_monitor()->Init(&observer); -} - -int ViEBaseImpl::DeregisterObserver() { - WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()), - "%s", __FUNCTION__); - - if (!shared_data_.vie_performance_monitor()->ViEBaseObserverRegistered()) { - shared_data_.SetLastError(kViEBaseObserverNotRegistered); - WEBRTC_TRACE(kTraceError, kTraceVideo, shared_data_.instance_id(), - "%s No observer registered.", __FUNCTION__); - return -1; - } - shared_data_.vie_performance_monitor()->Terminate(); - return 0; -} - int ViEBaseImpl::GetVersion(char version[1024]) { WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()), "GetVersion(version=?)"); diff --git a/webrtc/video_engine/vie_base_impl.h b/webrtc/video_engine/vie_base_impl.h index 3d914ec39..db63a7cfe 100644 --- a/webrtc/video_engine/vie_base_impl.h +++ b/webrtc/video_engine/vie_base_impl.h @@ -43,8 +43,6 @@ class ViEBaseImpl virtual int StopSend(const int video_channel); virtual int StartReceive(const int video_channel); virtual int StopReceive(const int video_channel); - virtual int RegisterObserver(ViEBaseObserver& observer); // NOLINT - virtual int DeregisterObserver(); virtual int GetVersion(char version[1024]); virtual int LastError(); diff --git a/webrtc/video_engine/vie_channel_manager.cc b/webrtc/video_engine/vie_channel_manager.cc index 13be55c8a..b1998c3e9 100644 --- a/webrtc/video_engine/vie_channel_manager.cc +++ b/webrtc/video_engine/vie_channel_manager.cc @@ -28,7 +28,6 @@ namespace webrtc { ViEChannelManager::ViEChannelManager( int engine_id, int number_of_cores, - ViEPerformanceMonitor* vie_performance_monitor, const OverUseDetectorOptions& options) : channel_id_critsect_(CriticalSectionWrapper::CreateCriticalSection()), engine_id_(engine_id), diff --git a/webrtc/video_engine/vie_channel_manager.h b/webrtc/video_engine/vie_channel_manager.h index 04bd37aa8..313635c04 100644 --- a/webrtc/video_engine/vie_channel_manager.h +++ b/webrtc/video_engine/vie_channel_manager.h @@ -30,7 +30,6 @@ class MapWrapper; class ProcessThread; class ViEChannel; class ViEEncoder; -class ViEPerformanceMonitor; class VoEVideoSync; class VoiceEngine; @@ -44,7 +43,6 @@ class ViEChannelManager: private ViEManagerBase { public: ViEChannelManager(int engine_id, int number_of_cores, - ViEPerformanceMonitor* vie_performance_monitor, const OverUseDetectorOptions& options); ~ViEChannelManager(); diff --git a/webrtc/video_engine/vie_performance_monitor.cc b/webrtc/video_engine/vie_performance_monitor.cc deleted file mode 100644 index 4cab915d6..000000000 --- a/webrtc/video_engine/vie_performance_monitor.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "video_engine/vie_performance_monitor.h" - -#include "system_wrappers/interface/cpu_wrapper.h" -#include "system_wrappers/interface/critical_section_wrapper.h" -#include "system_wrappers/interface/event_wrapper.h" -#include "system_wrappers/interface/thread_wrapper.h" -#include "system_wrappers/interface/tick_util.h" -#include "system_wrappers/interface/trace.h" -#include "video_engine/include/vie_base.h" -#include "video_engine/vie_defines.h" - -namespace webrtc { - -enum { kVieMonitorPeriodMs = 975 }; - -ViEPerformanceMonitor::ViEPerformanceMonitor(int engine_id) - : engine_id_(engine_id), - pointer_cs_(CriticalSectionWrapper::CreateCriticalSection()), - monitor_thread_(NULL), - monitor_event_(*EventWrapper::Create()), - cpu_(NULL), - vie_base_observer_(NULL) { -} - -ViEPerformanceMonitor::~ViEPerformanceMonitor() { - Terminate(); - delete pointer_cs_; - delete &monitor_event_; -} - -int ViEPerformanceMonitor::Init(ViEBaseObserver* vie_base_observer) { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), - "%s", __FUNCTION__); - - CriticalSectionScoped cs(pointer_cs_); - if (!vie_base_observer || vie_base_observer_) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(engine_id_), - "%s: Bad input argument or observer already set", - __FUNCTION__); - return -1; - } - - cpu_ = CpuWrapper::CreateCpu(); - if (cpu_ == NULL) { - // Performance monitoring not supported - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(engine_id_), "%s: Not supported", __FUNCTION__); - return 0; - } - - if (monitor_thread_ == NULL) { - monitor_event_.StartTimer(true, kVieMonitorPeriodMs); - monitor_thread_ = ThreadWrapper::CreateThread(ViEMonitorThreadFunction, - this, kNormalPriority, - "ViEPerformanceMonitor"); - unsigned int t_id = 0; - if (monitor_thread_->Start(t_id)) { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), - "%s: Performance monitor thread started %u", - __FUNCTION__, t_id); - } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(engine_id_), - "%s: Could not start performance monitor", __FUNCTION__); - monitor_event_.StopTimer(); - return -1; - } - } - vie_base_observer_ = vie_base_observer; - return 0; -} - -void ViEPerformanceMonitor::Terminate() { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), - "%s", __FUNCTION__); - - pointer_cs_->Enter(); - if (!vie_base_observer_) { - pointer_cs_->Leave(); - return; - } - - vie_base_observer_ = NULL; - monitor_event_.StopTimer(); - if (monitor_thread_) { - ThreadWrapper* tmp_thread = monitor_thread_; - monitor_thread_ = NULL; - monitor_event_.Set(); - pointer_cs_->Leave(); - if (tmp_thread->Stop()) { - pointer_cs_->Enter(); - delete tmp_thread; - tmp_thread = NULL; - delete cpu_; - } - cpu_ = NULL; - } - pointer_cs_->Leave(); -} - -bool ViEPerformanceMonitor::ViEBaseObserverRegistered() { - CriticalSectionScoped cs(pointer_cs_); - return vie_base_observer_ != NULL; -} - -bool ViEPerformanceMonitor::ViEMonitorThreadFunction(void* obj) { - return static_cast(obj)->ViEMonitorProcess(); -} - -bool ViEPerformanceMonitor::ViEMonitorProcess() { - // Periodically triggered with time KViEMonitorPeriodMs - monitor_event_.Wait(kVieMonitorPeriodMs); - if (monitor_thread_ == NULL) { - // Thread removed, exit - return false; - } - - CriticalSectionScoped cs(pointer_cs_); - if (cpu_) { - int cpu_load = cpu_->CpuUsage(); - if (cpu_load > 75) { - if (vie_base_observer_) { - vie_base_observer_->PerformanceAlarm(cpu_load); - } - } - } - return true; -} - -} // namespace webrtc diff --git a/webrtc/video_engine/vie_performance_monitor.h b/webrtc/video_engine/vie_performance_monitor.h deleted file mode 100644 index 1dc72ec62..000000000 --- a/webrtc/video_engine/vie_performance_monitor.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// ViEPerformanceMonitor is used to check the current CPU usage and triggers a -// callback when getting over a specified threshold. - -#ifndef WEBRTC_VIDEO_ENGINE_VIE_PERFORMANCE_MONITOR_H_ -#define WEBRTC_VIDEO_ENGINE_VIE_PERFORMANCE_MONITOR_H_ - -#include "system_wrappers/interface/scoped_ptr.h" -#include "typedefs.h" // NOLINT -#include "video_engine/vie_defines.h" - -namespace webrtc { - -class CpuWrapper; -class CriticalSectionWrapper; -class EventWrapper; -class ThreadWrapper; -class ViEBaseObserver; - -class ViEPerformanceMonitor { - public: - explicit ViEPerformanceMonitor(int engine_id); - ~ViEPerformanceMonitor(); - - int Init(ViEBaseObserver* vie_base_observer); - void Terminate(); - bool ViEBaseObserverRegistered(); - - protected: - static bool ViEMonitorThreadFunction(void* obj); - bool ViEMonitorProcess(); - - private: - const int engine_id_; - // TODO(mfldoman) Make this one scoped_ptr. - CriticalSectionWrapper* pointer_cs_; - ThreadWrapper* monitor_thread_; - EventWrapper& monitor_event_; - CpuWrapper* cpu_; - ViEBaseObserver* vie_base_observer_; -}; - -} // namespace webrtc - -#endif // WEBRTC_VIDEO_ENGINE_VIE_PERFORMANCE_MONITOR_H_ diff --git a/webrtc/video_engine/vie_shared_data.cc b/webrtc/video_engine/vie_shared_data.cc index b92714488..574aa9a42 100644 --- a/webrtc/video_engine/vie_shared_data.cc +++ b/webrtc/video_engine/vie_shared_data.cc @@ -27,9 +27,7 @@ ViESharedData::ViESharedData() initialized_(false), number_cores_(CpuInfo::DetectNumberOfCores()), over_use_detector_options_(), - vie_performance_monitor_(ViEPerformanceMonitor(instance_id_)), channel_manager_(*new ViEChannelManager(instance_id_, number_cores_, - &vie_performance_monitor_, over_use_detector_options_)), input_manager_(*new ViEInputManager(instance_id_)), render_manager_(*new ViERenderManager(instance_id_)), diff --git a/webrtc/video_engine/vie_shared_data.h b/webrtc/video_engine/vie_shared_data.h index 062e5c50a..886cf67fb 100644 --- a/webrtc/video_engine/vie_shared_data.h +++ b/webrtc/video_engine/vie_shared_data.h @@ -15,7 +15,6 @@ #define WEBRTC_VIDEO_ENGINE_VIE_SHARED_DATA_H_ #include "video_engine/vie_defines.h" -#include "video_engine/vie_performance_monitor.h" namespace webrtc { @@ -38,8 +37,6 @@ class ViESharedData { int NumberOfCores() const; int instance_id() { return instance_id_;} - ViEPerformanceMonitor* vie_performance_monitor() { - return &vie_performance_monitor_; } ViEChannelManager* channel_manager() { return &channel_manager_; } ViEInputManager* input_manager() { return &input_manager_; } ViERenderManager* render_manager() { return &render_manager_; } @@ -51,7 +48,6 @@ class ViESharedData { const int number_cores_; OverUseDetectorOptions over_use_detector_options_; - ViEPerformanceMonitor vie_performance_monitor_; ViEChannelManager& channel_manager_; ViEInputManager& input_manager_; ViERenderManager& render_manager_;