diff options
author | wu@webrtc.org <wu@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-03-27 23:38:21 +0000 |
---|---|---|
committer | wu@webrtc.org <wu@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-03-27 23:38:21 +0000 |
commit | 2ffc8bf69efc5cfcaae1027a78df72e7dfeb5e0b (patch) | |
tree | e5d32cf5deff7bbaeeb20f34862ce869d779cff1 /voice_engine | |
parent | 365ca407f428f03d0882531073974263787201e6 (diff) | |
download | webrtc-2ffc8bf69efc5cfcaae1027a78df72e7dfeb5e0b.tar.gz |
Revert 3736 "Removed CPU APIs from VoEHardware. Code is now only..."
> Removed CPU APIs from VoEHardware. Code is now only used by test applications.
>
> BUG=8404677
>
> Review URL: https://webrtc-codereview.appspot.com/1238004
TBR=henrike@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1267004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@3737 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'voice_engine')
-rw-r--r-- | voice_engine/include/voe_hardware.h | 7 | ||||
-rw-r--r-- | voice_engine/test/auto_test/standard/hardware_before_streaming_test.cc | 11 | ||||
-rw-r--r-- | voice_engine/test/auto_test/standard/hardware_test.cc | 14 | ||||
-rw-r--r-- | voice_engine/voe_hardware_impl.cc | 55 | ||||
-rw-r--r-- | voice_engine/voe_hardware_impl.h | 4 |
5 files changed, 90 insertions, 1 deletions
diff --git a/voice_engine/include/voe_hardware.h b/voice_engine/include/voe_hardware.h index 1537aab6..e973c110 100644 --- a/voice_engine/include/voe_hardware.h +++ b/voice_engine/include/voe_hardware.h @@ -93,6 +93,13 @@ public: // of total CPU availability. [Windows only] virtual int GetCPULoad(int& loadPercent) = 0; + // Gets the computer's current CPU consumption in terms of the percent + // of the total CPU availability. This method may fail a few times on + // Windows because it needs a certain warm-up time before reporting the + // result. You should check the return value and either try again or + // give up when it fails. + virtual int GetSystemCPULoad(int& loadPercent) = 0; + // Not supported virtual int ResetAudioDevice() = 0; diff --git a/voice_engine/test/auto_test/standard/hardware_before_streaming_test.cc b/voice_engine/test/auto_test/standard/hardware_before_streaming_test.cc index 6136543b..edb7f562 100644 --- a/voice_engine/test/auto_test/standard/hardware_before_streaming_test.cc +++ b/voice_engine/test/auto_test/standard/hardware_before_streaming_test.cc @@ -51,6 +51,17 @@ TEST_F(HardwareBeforeStreamingTest, ResetsAudioDeviceOnIphone) { // Tests that only apply to desktop: #if !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID) +TEST_F(HardwareBeforeStreamingTest, GetSystemCpuLoadSucceeds) { +#ifdef _WIN32 + // This method needs some warm-up time on Windows. We sleep a good amount + // of time instead of retrying to make the test simpler. + Sleep(2000); +#endif + + int load_percent; + EXPECT_EQ(0, voe_hardware_->GetSystemCPULoad(load_percent)); +} + TEST_F(HardwareBeforeStreamingTest, GetPlayoutDeviceStatusReturnsTrue) { bool play_available = false; EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceStatus(play_available)); diff --git a/voice_engine/test/auto_test/standard/hardware_test.cc b/voice_engine/test/auto_test/standard/hardware_test.cc index d026f516..7310e52d 100644 --- a/voice_engine/test/auto_test/standard/hardware_test.cc +++ b/voice_engine/test/auto_test/standard/hardware_test.cc @@ -69,6 +69,20 @@ TEST_F(HardwareTest, GetCpuLoadReturnsErrorOnNonWindowsPlatform) { } #endif +#if !defined(WEBRTC_MAC) && !defined(WEBRTC_ANDROID) +TEST_F(HardwareTest, GetSystemCpuLoadWorksExceptOnMacAndAndroid) { +#ifdef _WIN32 + // This method needs some warm-up time on Windows. We sleep a good amount + // of time instead of retrying to make the test simpler. + Sleep(2000); +#endif + int load = -1; + EXPECT_EQ(0, voe_hardware_->GetSystemCPULoad(load)); + EXPECT_GE(load, 0); + TEST_LOG("System CPU load = %d%%\n", load); +} +#endif + TEST_F(HardwareTest, BuiltInWasapiAECWorksForAudioWindowsCoreAudioLayer) { #ifdef WEBRTC_IOS // Ensure the sound device is reset on iPhone. diff --git a/voice_engine/voe_hardware_impl.cc b/voice_engine/voe_hardware_impl.cc index a374bc9a..db7e18fa 100644 --- a/voice_engine/voe_hardware_impl.cc +++ b/voice_engine/voe_hardware_impl.cc @@ -12,6 +12,7 @@ #include <cassert> +#include "cpu_wrapper.h" #include "critical_section_wrapper.h" #include "trace.h" #include "voe_errors.h" @@ -37,16 +38,29 @@ VoEHardware* VoEHardware::GetInterface(VoiceEngine* voiceEngine) #ifdef WEBRTC_VOICE_ENGINE_HARDWARE_API -VoEHardwareImpl::VoEHardwareImpl(voe::SharedData* shared) : _shared(shared) +VoEHardwareImpl::VoEHardwareImpl(voe::SharedData* shared) : + _cpu(NULL), _shared(shared) { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), "VoEHardwareImpl() - ctor"); + + _cpu = CpuWrapper::CreateCpu(); + if (_cpu) + { + _cpu->CpuUsage(); // init cpu usage + } } VoEHardwareImpl::~VoEHardwareImpl() { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), "~VoEHardwareImpl() - dtor"); + + if (_cpu) + { + delete _cpu; + _cpu = NULL; + } } int VoEHardwareImpl::SetAudioDeviceLayer(AudioLayers audioLayer) @@ -739,6 +753,45 @@ int VoEHardwareImpl::GetCPULoad(int& loadPercent) return 0; } +int VoEHardwareImpl::GetSystemCPULoad(int& loadPercent) +{ + WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), + "GetSystemCPULoad(loadPercent=?)"); + ANDROID_NOT_SUPPORTED(_shared->statistics()); + IPHONE_NOT_SUPPORTED(_shared->statistics()); + + if (!_shared->statistics().Initialized()) + { + _shared->SetLastError(VE_NOT_INITED, kTraceError); + return -1; + } + + // Check if implemented for this platform + if (!_cpu) + { + _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, + " no support for getting system CPU load"); + return -1; + } + + // Get CPU load + WebRtc_Word32 load = _cpu->CpuUsage(); + if (load < 0) + { + _shared->SetLastError(VE_CPU_INFO_ERROR, kTraceError, + " error getting system CPU load"); + return -1; + } + + loadPercent = static_cast<int> (load); + + WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, + VoEId(_shared->instance_id(), -1), + " Output: loadPercent = %d", loadPercent); + + return 0; +} + int VoEHardwareImpl::EnableBuiltInAEC(bool enable) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/voice_engine/voe_hardware_impl.h b/voice_engine/voe_hardware_impl.h index 1b2f3434..94775672 100644 --- a/voice_engine/voe_hardware_impl.h +++ b/voice_engine/voe_hardware_impl.h @@ -17,6 +17,7 @@ namespace webrtc { +class CpuWrapper; class VoEHardwareImpl: public VoEHardware { @@ -49,6 +50,8 @@ public: virtual int GetCPULoad(int& loadPercent); + virtual int GetSystemCPULoad(int& loadPercent); + virtual int ResetAudioDevice(); virtual int AudioDeviceControl(unsigned int par1, @@ -72,6 +75,7 @@ protected: virtual ~VoEHardwareImpl(); private: + CpuWrapper* _cpu; voe::SharedData* _shared; }; |