diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 3d4b13337766f..fc6eec8f027e3 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -364,6 +364,8 @@ bool CApplication::Create(const CAppParamParser ¶ms) m_bTestMode = params.m_testmode; m_bStandalone = params.m_standAlone; + CServiceBroker::RegisterCPUInfo(CCPUInfo::GetCPUInfo()); + m_pSettingsComponent.reset(new CSettingsComponent()); m_pSettingsComponent->Init(params); diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp index 139352d4bbf22..9f5bc275bdd59 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp @@ -15,6 +15,28 @@ #include "utils/StringUtils.h" #include "utils/log.h" +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +class CDriverMonitor +{ +public: + CDriverMonitor() = default; + virtual ~CDriverMonitor(); + bool Start(); + bool IsInitialized(); + + CCriticalSection m_sec; + +protected: + pa_context* m_pContext = nullptr; + pa_threaded_mainloop* m_pMainLoop = nullptr; + bool m_isInit = false; +}; + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + static const char *ContextStateToString(pa_context_state s) { switch (s) @@ -206,6 +228,42 @@ static void SinkInputInfoCallback(pa_context *c, const pa_sink_input_info *i, in p->UpdateInternalVolume(&(i->volume)); } +static void SinkCallback(pa_context* c, + pa_subscription_event_type_t t, + uint32_t idx, + void* userdata) +{ + CDriverMonitor* p = static_cast(userdata); + if (!p) + return; + + CSingleLock lock(p->m_sec); + if (p->IsInitialized()) + { + if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK) + { + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) + { + CLog::Log(LOGDEBUG, "Sink appeared"); + CServiceBroker::GetActiveAE()->DeviceChange(); + } + else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) + { + CLog::Log(LOGDEBUG, "Sink removed"); + CServiceBroker::GetActiveAE()->DeviceChange(); + } + else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE) + { + CLog::Log(LOGDEBUG, "Sink changed"); + } + } + else + { + CLog::Log(LOGDEBUG, "Not subscribed to Event: %d", static_cast(t)); + } + } +} + static void SinkChangedCallback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { CAESinkPULSE* p = static_cast(userdata); @@ -232,23 +290,6 @@ static void SinkChangedCallback(pa_context *c, pa_subscription_event_type_t t, u pa_operation_unref(op); } } - else if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK) - { - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) - { - CLog::Log(LOGDEBUG, "Sink appeared"); - CServiceBroker::GetActiveAE()->DeviceChange(); - } - else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) - { - CLog::Log(LOGDEBUG, "Sink removed"); - CServiceBroker::GetActiveAE()->DeviceChange(); - } - else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE) - { - CLog::Log(LOGDEBUG, "Sink changed"); - } - } else { CLog::Log(LOGDEBUG, "Not subscribed to Event: %d", static_cast(t)); @@ -497,8 +538,119 @@ static void SinkInfoRequestCallback(pa_context *c, const pa_sink_info *i, int eo pa_threaded_mainloop_signal(sinkStruct->mainloop, 0); } +static bool SetupContext(const char* host, + const char* appname, + pa_context** context, + pa_threaded_mainloop** mainloop) +{ + if ((*mainloop = pa_threaded_mainloop_new()) == nullptr) + { + CLog::Log(LOGERROR, "PulseAudio: Failed to allocate main loop"); + return false; + } + + if (((*context) = pa_context_new(pa_threaded_mainloop_get_api(*mainloop), appname)) == nullptr) + { + CLog::Log(LOGERROR, "PulseAudio: Failed to allocate context"); + return false; + } + + pa_context_set_state_callback(*context, ContextStateCallback, *mainloop); + + if (pa_context_connect(*context, host, (pa_context_flags_t)0, nullptr) < 0) + { + CLog::Log(LOGERROR, "PulseAudio: Failed to connect context"); + return false; + } + pa_threaded_mainloop_lock(*mainloop); + + if (pa_threaded_mainloop_start(*mainloop) < 0) + { + CLog::Log(LOGERROR, "PulseAudio: Failed to start MainLoop"); + pa_threaded_mainloop_unlock(*mainloop); + return false; + } + + /* Wait until the context is ready */ + do + { + pa_threaded_mainloop_wait(*mainloop); + CLog::Log(LOGDEBUG, "PulseAudio: Context %s", + ContextStateToString(pa_context_get_state(*context))); + } while (pa_context_get_state(*context) != PA_CONTEXT_READY && + pa_context_get_state(*context) != PA_CONTEXT_FAILED); + + if (pa_context_get_state(*context) == PA_CONTEXT_FAILED) + { + CLog::Log(LOGERROR, "PulseAudio: Waited for the Context but it failed"); + pa_threaded_mainloop_unlock(*mainloop); + return false; + } + + pa_threaded_mainloop_unlock(*mainloop); + return true; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +CDriverMonitor::~CDriverMonitor() +{ + m_isInit = false; + + if (m_pMainLoop) + pa_threaded_mainloop_stop(m_pMainLoop); + + if (m_pContext) + { + pa_context_disconnect(m_pContext); + pa_context_unref(m_pContext); + m_pContext = nullptr; + } + + if (m_pMainLoop) + { + pa_threaded_mainloop_free(m_pMainLoop); + m_pMainLoop = nullptr; + } +} + +bool CDriverMonitor::IsInitialized() +{ + return m_isInit; +} + +bool CDriverMonitor::Start() +{ + if (!SetupContext(nullptr, "KodiDriver", &m_pContext, &m_pMainLoop)) + { + CLog::Log(LOGNOTICE, "PulseAudio might not be running. Context was not created."); + return false; + } + + pa_threaded_mainloop_lock(m_pMainLoop); + + m_isInit = true; + + CSingleLock lock(m_sec); + // Register Callback for Sink changes + pa_context_set_subscribe_callback(m_pContext, SinkCallback, this); + const pa_subscription_mask_t mask = pa_subscription_mask_t(PA_SUBSCRIPTION_MASK_SINK); + pa_operation* op = pa_context_subscribe(m_pContext, mask, nullptr, this); + if (op != nullptr) + pa_operation_unref(op); + + pa_threaded_mainloop_unlock(m_pMainLoop); + + return true; +} +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + /* PulseAudio class memberfunctions*/ +std::unique_ptr CAESinkPULSE::m_pMonitor; + bool CAESinkPULSE::Register() { // check if pulseaudio is actually available @@ -519,10 +671,14 @@ bool CAESinkPULSE::Register() pa_simple_free(s); } + m_pMonitor.reset(new CDriverMonitor()); + m_pMonitor->Start(); + AE::AESinkRegEntry entry; entry.sinkName = "PULSE"; entry.createFunc = CAESinkPULSE::Create; entry.enumerateFunc = CAESinkPULSE::EnumerateDevicesEx; + entry.cleanupFunc = CAESinkPULSE::Cleanup; AE::CAESinkFactory::RegisterSink(entry); return true; } @@ -571,7 +727,7 @@ bool CAESinkPULSE::Initialize(AEAudioFormat &format, std::string &device) m_Context = NULL; m_periodSize = 0; - if (!SetupContext(NULL, &m_Context, &m_MainLoop)) + if (!SetupContext(NULL, "KodiSink", &m_Context, &m_MainLoop)) { CLog::Log(LOGNOTICE, "PulseAudio might not be running. Context was not created."); Deinitialize(); @@ -816,7 +972,7 @@ bool CAESinkPULSE::Initialize(AEAudioFormat &format, std::string &device) CSingleLock lock(m_sec); // Register Callback for Sink changes pa_context_set_subscribe_callback(m_Context, SinkChangedCallback, this); - const pa_subscription_mask_t mask = pa_subscription_mask_t (PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SINK_INPUT); + const pa_subscription_mask_t mask = pa_subscription_mask_t(PA_SUBSCRIPTION_MASK_SINK_INPUT); pa_operation *op = pa_context_subscribe(m_Context, mask, NULL, this); if (op != NULL) pa_operation_unref(op); @@ -1013,7 +1169,7 @@ void CAESinkPULSE::EnumerateDevicesEx(AEDeviceInfoList &list, bool force) pa_context *context; pa_threaded_mainloop *mainloop; - if (!SetupContext(NULL, &context, &mainloop)) + if (!SetupContext(NULL, "KodiSink", &context, &mainloop)) { CLog::Log(LOGNOTICE, "PulseAudio might not be running. Context was not created."); return; @@ -1093,51 +1249,7 @@ inline bool CAESinkPULSE::WaitForOperation(pa_operation *op, pa_threaded_mainloo return success; } -bool CAESinkPULSE::SetupContext(const char *host, pa_context **context, pa_threaded_mainloop **mainloop) +void CAESinkPULSE::Cleanup() { - if ((*mainloop = pa_threaded_mainloop_new()) == NULL) - { - CLog::Log(LOGERROR, "PulseAudio: Failed to allocate main loop"); - return false; - } - - if (((*context) = pa_context_new(pa_threaded_mainloop_get_api(*mainloop), "Kodi")) == NULL) - { - CLog::Log(LOGERROR, "PulseAudio: Failed to allocate context"); - return false; - } - - pa_context_set_state_callback(*context, ContextStateCallback, *mainloop); - - if (pa_context_connect(*context, host, (pa_context_flags_t)0, NULL) < 0) - { - CLog::Log(LOGERROR, "PulseAudio: Failed to connect context"); - return false; - } - pa_threaded_mainloop_lock(*mainloop); - - if (pa_threaded_mainloop_start(*mainloop) < 0) - { - CLog::Log(LOGERROR, "PulseAudio: Failed to start MainLoop"); - pa_threaded_mainloop_unlock(*mainloop); - return false; - } - - /* Wait until the context is ready */ - do - { - pa_threaded_mainloop_wait(*mainloop); - CLog::Log(LOGDEBUG, "PulseAudio: Context %s", ContextStateToString(pa_context_get_state(*context))); - } - while (pa_context_get_state(*context) != PA_CONTEXT_READY && pa_context_get_state(*context) != PA_CONTEXT_FAILED); - - if (pa_context_get_state(*context) == PA_CONTEXT_FAILED) - { - CLog::Log(LOGERROR, "PulseAudio: Waited for the Context but it failed"); - pa_threaded_mainloop_unlock(*mainloop); - return false; - } - - pa_threaded_mainloop_unlock(*mainloop); - return true; + m_pMonitor.reset(); } diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.h b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.h index 21c97f3bbaebc..30e7eac9136c7 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.h +++ b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.h @@ -13,9 +13,13 @@ #include "cores/AudioEngine/Utils/AEUtil.h" #include "threads/CriticalSection.h" +#include + #include #include +class CDriverMonitor; + class CAESinkPULSE : public IAESink { public: @@ -27,6 +31,7 @@ class CAESinkPULSE : public IAESink static bool Register(); static IAESink* Create(std::string &device, AEAudioFormat &desiredFormat); static void EnumerateDevicesEx(AEDeviceInfoList &list, bool force = false); + static void Cleanup(); bool Initialize(AEAudioFormat &format, std::string &device) override; void Deinitialize() override; @@ -47,7 +52,6 @@ class CAESinkPULSE : public IAESink private: void Pause(bool pause); static inline bool WaitForOperation(pa_operation *op, pa_threaded_mainloop *mainloop, const char *LogEntry); - static bool SetupContext(const char *host, pa_context **context, pa_threaded_mainloop **mainloop); bool m_IsAllocated; bool m_passthrough; @@ -65,4 +69,6 @@ class CAESinkPULSE : public IAESink pa_context *m_Context; pa_threaded_mainloop *m_MainLoop; + + static std::unique_ptr m_pMonitor; }; diff --git a/xbmc/platform/Platform.cpp b/xbmc/platform/Platform.cpp index cfd88baa1623b..e1f1465c7949c 100644 --- a/xbmc/platform/Platform.cpp +++ b/xbmc/platform/Platform.cpp @@ -9,7 +9,6 @@ #include "Platform.h" #include "ServiceBroker.h" -#include "utils/CPUInfo.h" // Override for platform ports #if !defined(PLATFORM_OVERRIDE) @@ -29,6 +28,5 @@ CPlatform::~CPlatform() = default; void CPlatform::Init() { - CServiceBroker::RegisterCPUInfo(CCPUInfo::GetCPUInfo()); } diff --git a/xbmc/platform/android/CPUInfoAndroid.h b/xbmc/platform/android/CPUInfoAndroid.h index 2ec2e6f7a84f8..8c7bf91d63ac3 100644 --- a/xbmc/platform/android/CPUInfoAndroid.h +++ b/xbmc/platform/android/CPUInfoAndroid.h @@ -8,10 +8,11 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" -class CCPUInfoAndroid : public CCPUInfo +#include "platform/posix/CPUInfoPosix.h" + +class CCPUInfoAndroid : public CCPUInfoPosix { public: CCPUInfoAndroid(); diff --git a/xbmc/platform/darwin/ios/CPUInfoIos.h b/xbmc/platform/darwin/ios/CPUInfoIos.h index 785761dbe5e94..e7a0cffa1ae37 100644 --- a/xbmc/platform/darwin/ios/CPUInfoIos.h +++ b/xbmc/platform/darwin/ios/CPUInfoIos.h @@ -8,14 +8,15 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" +#include "platform/posix/CPUInfoPosix.h" + #include class CPosixResourceCounter; -class CCPUInfoIos : public CCPUInfo +class CCPUInfoIos : public CCPUInfoPosix { public: CCPUInfoIos(); diff --git a/xbmc/platform/darwin/osx/CPUInfoOsx.h b/xbmc/platform/darwin/osx/CPUInfoOsx.h index 5ded61f1a5b60..39b2b1bee32bc 100644 --- a/xbmc/platform/darwin/osx/CPUInfoOsx.h +++ b/xbmc/platform/darwin/osx/CPUInfoOsx.h @@ -8,12 +8,13 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" +#include "platform/posix/CPUInfoPosix.h" + class CPosixResourceCounter; -class CCPUInfoOsx : public CCPUInfo +class CCPUInfoOsx : public CCPUInfoPosix { public: CCPUInfoOsx(); diff --git a/xbmc/platform/freebsd/CPUInfoFreebsd.h b/xbmc/platform/freebsd/CPUInfoFreebsd.h index c33ba20985478..08713b176de9c 100644 --- a/xbmc/platform/freebsd/CPUInfoFreebsd.h +++ b/xbmc/platform/freebsd/CPUInfoFreebsd.h @@ -8,10 +8,11 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" -class CCPUInfoFreebsd : public CCPUInfo +#include "platform/posix/CPUInfoPosix.h" + +class CCPUInfoFreebsd : public CCPUInfoPosix { public: CCPUInfoFreebsd(); diff --git a/xbmc/platform/linux/CPUInfoLinux.cpp b/xbmc/platform/linux/CPUInfoLinux.cpp index 9b107353e7da4..a60051dcde92c 100644 --- a/xbmc/platform/linux/CPUInfoLinux.cpp +++ b/xbmc/platform/linux/CPUInfoLinux.cpp @@ -16,10 +16,10 @@ #include #include -#if defined(HAS_NEON) +#if (defined(__arm__) && defined(HAS_NEON)) || defined(__aarch64__) #include #include -#else +#elif defined(__i386__) || defined(__x86_64__) #include #endif @@ -94,7 +94,7 @@ CCPUInfoLinux::CCPUInfoLinux() m_cores.emplace_back(coreInfo); } -#if !defined(HAS_NEON) +#if defined(__i386__) || defined(__x86_64__) unsigned int eax; unsigned int ebx; unsigned int ecx; @@ -184,10 +184,8 @@ CCPUInfoLinux::CCPUInfoLinux() } #endif -#if defined(HAS_NEON) && !defined(__LP64__) +#if defined(HAS_NEON) && defined(__arm__) if (getauxval(AT_HWCAP) & HWCAP_NEON) -#endif -#if defined(HAS_NEON) m_cpuFeatures |= CPU_FEATURE_NEON; #endif @@ -266,7 +264,7 @@ float CCPUInfoLinux::GetCPUFrequency() bool CCPUInfoLinux::GetTemperature(CTemperature& temperature) { if (!SysfsUtils::Has("/sys/class/hwmon/hwmon0/temp1_input")) - return CCPUInfo::GetTemperature(temperature); + return CCPUInfoPosix::GetTemperature(temperature); int value{-1}; char scale{'c'}; @@ -279,6 +277,8 @@ bool CCPUInfoLinux::GetTemperature(CTemperature& temperature) temperature = CTemperature::CreateFromCelsius(value); else if (scale == 'F' || scale == 'f') temperature = CTemperature::CreateFromFahrenheit(value); + else + return false; temperature.SetValid(true); diff --git a/xbmc/platform/linux/CPUInfoLinux.h b/xbmc/platform/linux/CPUInfoLinux.h index ad1354653a272..cc4d95d00da1f 100644 --- a/xbmc/platform/linux/CPUInfoLinux.h +++ b/xbmc/platform/linux/CPUInfoLinux.h @@ -8,10 +8,11 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" -class CCPUInfoLinux : public CCPUInfo +#include "platform/posix/CPUInfoPosix.h" + +class CCPUInfoLinux : public CCPUInfoPosix { public: CCPUInfoLinux(); diff --git a/xbmc/platform/posix/CMakeLists.txt b/xbmc/platform/posix/CMakeLists.txt index 56c7487238408..2c4acd977d605 100644 --- a/xbmc/platform/posix/CMakeLists.txt +++ b/xbmc/platform/posix/CMakeLists.txt @@ -1,4 +1,5 @@ set(SOURCES ConvUtils.cpp + CPUInfoPosix.cpp Filesystem.cpp MessagePrinter.cpp PlatformPosix.cpp @@ -10,6 +11,7 @@ set(SOURCES ConvUtils.cpp XTimeUtils.cpp) set(HEADERS ConvUtils.h + CPUInfoPosix.h PlatformDefs.h PlatformPosix.h PosixMountProvider.h diff --git a/xbmc/platform/posix/CPUInfoPosix.cpp b/xbmc/platform/posix/CPUInfoPosix.cpp new file mode 100644 index 0000000000000..a261b6e385de3 --- /dev/null +++ b/xbmc/platform/posix/CPUInfoPosix.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "CPUInfoPosix.h" + +#include "ServiceBroker.h" +#include "settings/AdvancedSettings.h" +#include "settings/SettingsComponent.h" + +bool CCPUInfoPosix::GetTemperature(CTemperature& temperature) +{ + std::string cmd = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_cpuTempCmd; + + temperature.SetValid(false); + + int value{-1}; + char scale{'c'}; + + if (!cmd.empty()) + { + auto p = popen(cmd.c_str(), "r"); + if (p) + { + int ret = fscanf(p, "%d %c", &value, &scale); + pclose(p); + + if (ret < 2) + return false; + } + } + + if (scale == 'C' || scale == 'c') + temperature = CTemperature::CreateFromCelsius(value); + else if (scale == 'F' || scale == 'f') + temperature = CTemperature::CreateFromFahrenheit(value); + else + return false; + + temperature.SetValid(true); + + return true; +} diff --git a/xbmc/platform/posix/CPUInfoPosix.h b/xbmc/platform/posix/CPUInfoPosix.h new file mode 100644 index 0000000000000..0043a60dcdae3 --- /dev/null +++ b/xbmc/platform/posix/CPUInfoPosix.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "utils/CPUInfo.h" + +class CCPUInfoPosix : public CCPUInfo +{ +public: + virtual bool GetTemperature(CTemperature& temperature) override; + +protected: + CCPUInfoPosix() = default; + virtual ~CCPUInfoPosix() = default; +}; diff --git a/xbmc/platform/win10/CPUInfoWin10.cpp b/xbmc/platform/win10/CPUInfoWin10.cpp index 4885ef6cf114b..8a18c89699a5d 100644 --- a/xbmc/platform/win10/CPUInfoWin10.cpp +++ b/xbmc/platform/win10/CPUInfoWin10.cpp @@ -117,3 +117,9 @@ int CCPUInfoWin10::GetUsedPercentage() return static_cast(m_lastUsedPercentage); } + +bool CCPUInfoWin10::GetTemperature(CTemperature& temperature) +{ + temperature.SetValid(false); + return false; +} diff --git a/xbmc/platform/win10/CPUInfoWin10.h b/xbmc/platform/win10/CPUInfoWin10.h index 220f38d6eedfb..dc924901931b8 100644 --- a/xbmc/platform/win10/CPUInfoWin10.h +++ b/xbmc/platform/win10/CPUInfoWin10.h @@ -19,4 +19,5 @@ class CCPUInfoWin10 : public CCPUInfo int GetUsedPercentage() override; float GetCPUFrequency() override { return 0; } + bool GetTemperature(CTemperature& temperature) override; }; diff --git a/xbmc/platform/win32/CPUInfoWin32.cpp b/xbmc/platform/win32/CPUInfoWin32.cpp index 213f74db35836..086402f8bfe03 100644 --- a/xbmc/platform/win32/CPUInfoWin32.cpp +++ b/xbmc/platform/win32/CPUInfoWin32.cpp @@ -125,7 +125,6 @@ CCPUInfoWin32::CCPUInfoWin32() else m_cpuQueryLoad = nullptr; -#ifndef _M_ARM int CPUInfo[4]; // receives EAX, EBX, ECD and EDX in that order __cpuid(CPUInfo, 0); @@ -164,7 +163,6 @@ CCPUInfoWin32::CCPUInfoWin32() if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_3DNOWEXT) m_cpuFeatures |= CPU_FEATURE_3DNOWEXT; } -#endif // ! _M_ARM // Set MMX2 when SSE is present as SSE is a superset of MMX2 and Intel doesn't set the MMX2 cap if (m_cpuFeatures & CPU_FEATURE_SSE) @@ -287,3 +285,9 @@ float CCPUInfoWin32::GetCPUFrequency() return 0; } + +bool CCPUInfoWin32::GetTemperature(CTemperature& temperature) +{ + temperature.SetValid(false); + return false; +} diff --git a/xbmc/platform/win32/CPUInfoWin32.h b/xbmc/platform/win32/CPUInfoWin32.h index 996de4efaffe1..69bfac2f79a26 100644 --- a/xbmc/platform/win32/CPUInfoWin32.h +++ b/xbmc/platform/win32/CPUInfoWin32.h @@ -19,6 +19,7 @@ class CCPUInfoWin32 : public CCPUInfo int GetUsedPercentage() override; float GetCPUFrequency() override; + bool GetTemperature(CTemperature& temperature) override; private: // avoid inclusion of and others diff --git a/xbmc/utils/CPUInfo.cpp b/xbmc/utils/CPUInfo.cpp index 98dbceb7de99f..b0afdf3f8775e 100644 --- a/xbmc/utils/CPUInfo.cpp +++ b/xbmc/utils/CPUInfo.cpp @@ -8,9 +8,6 @@ #include "CPUInfo.h" -#include "ServiceBroker.h" -#include "settings/AdvancedSettings.h" -#include "settings/SettingsComponent.h" #include "utils/StringUtils.h" bool CCPUInfo::HasCoreId(int coreId) const @@ -60,35 +57,3 @@ std::string CCPUInfo::GetCoresUsageString() const return strCores; } - -bool CCPUInfo::GetTemperature(CTemperature& temperature) -{ - std::string cmd = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_cpuTempCmd; - - temperature.SetValid(false); - - int value{-1}; - char scale{'c'}; - - if (!cmd.empty()) - { - auto p = popen(cmd.c_str(), "r"); - if (p) - { - int ret = fscanf(p, "%d %c", &value, &scale); - pclose(p); - - if (ret < 2) - return false; - } - } - - if (scale == 'C' || scale == 'c') - temperature = CTemperature::CreateFromCelsius(value); - else if (scale == 'F' || scale == 'f') - temperature = CTemperature::CreateFromFahrenheit(value); - - temperature.SetValid(true); - - return true; -} diff --git a/xbmc/utils/CPUInfo.h b/xbmc/utils/CPUInfo.h index dc298a52a94d9..ad8dd95607a87 100644 --- a/xbmc/utils/CPUInfo.h +++ b/xbmc/utils/CPUInfo.h @@ -77,7 +77,7 @@ class CCPUInfo virtual int GetUsedPercentage() = 0; virtual float GetCPUFrequency() = 0; - virtual bool GetTemperature(CTemperature& temperature); + virtual bool GetTemperature(CTemperature& temperature) = 0; bool HasCoreId(int coreId) const; const CoreInfo GetCoreInfo(int coreId); diff --git a/xbmc/utils/test/TestCPUInfo.cpp b/xbmc/utils/test/TestCPUInfo.cpp index d395eb41bb7cf..9cf2db9152681 100644 --- a/xbmc/utils/test/TestCPUInfo.cpp +++ b/xbmc/utils/test/TestCPUInfo.cpp @@ -44,7 +44,11 @@ TEST_F(TestCPUInfo, GetCPUFrequency) EXPECT_GE(CServiceBroker::GetCPUInfo()->GetCPUFrequency(), 0.f); } +#if defined(TARGET_WINDOWS) +TEST_F(TestCPUInfo, DISABLED_GetTemperature) +#else TEST_F(TestCPUInfo, GetTemperature) +#endif { CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_cpuTempCmd = "echo '50 c'"; CTemperature t;