libfreerdp-codec: add processor count detection and auto-enabling of threads in RemoteFX decoder
This commit is contained in:
parent
da3a3d5c9a
commit
ebefab1de4
@ -100,7 +100,7 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
|
||||
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
|
||||
MONOLITHIC ${MONOLITHIC_BUILD}
|
||||
MODULE winpr
|
||||
MODULES winpr-crt winpr-pool winpr-registry winpr-utils)
|
||||
MODULES winpr-crt winpr-pool winpr-registry winpr-sysinfo winpr-utils)
|
||||
|
||||
if(MONOLITHIC_BUILD)
|
||||
set(FREERDP_LIBS ${FREERDP_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE)
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
#include <winpr/registry.h>
|
||||
|
||||
#include <freerdp/codec/rfx.h>
|
||||
@ -146,6 +147,7 @@ RFX_CONTEXT* rfx_context_new(void)
|
||||
DWORD dwType;
|
||||
DWORD dwSize;
|
||||
DWORD dwValue;
|
||||
SYSTEM_INFO sysinfo;
|
||||
RFX_CONTEXT* context;
|
||||
|
||||
context = (RFX_CONTEXT*) malloc(sizeof(RFX_CONTEXT));
|
||||
@ -166,8 +168,26 @@ RFX_CONTEXT* rfx_context_new(void)
|
||||
|
||||
context->priv->BufferPool = BufferPool_New(TRUE, 16384, 16);
|
||||
|
||||
context->priv->UseThreads = FALSE;
|
||||
context->priv->MinThreadCount = 4;
|
||||
#ifdef _WIN32
|
||||
{
|
||||
BOOL isVistaOrLater;
|
||||
OSVERSIONINFOA verinfo;
|
||||
|
||||
ZeroMemory(&verinfo, sizeof(OSVERSIONINFOA));
|
||||
verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
|
||||
|
||||
GetVersionExA(&verinfo);
|
||||
isVistaOrLater = ((verinfo.dwMajorVersion >= 6) && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE;
|
||||
|
||||
context->priv->UseThreads = isVistaOrLater;
|
||||
}
|
||||
#else
|
||||
context->priv->UseThreads = TRUE;
|
||||
#endif
|
||||
|
||||
GetNativeSystemInfo(&sysinfo);
|
||||
|
||||
context->priv->MinThreadCount = sysinfo.dwNumberOfProcessors;
|
||||
context->priv->MaxThreadCount = 0;
|
||||
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\RemoteFX"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
||||
|
@ -71,10 +71,71 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/platform.h>
|
||||
|
||||
DWORD GetProcessorArchitecture()
|
||||
{
|
||||
DWORD cpuArch = PROCESSOR_ARCHITECTURE_UNKNOWN;
|
||||
|
||||
#if defined(_M_AMD64)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_AMD64;
|
||||
#elif defined(_M_IX86)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_INTEL;
|
||||
#elif defined(_M_ARM)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_ARM;
|
||||
#elif defined(_M_IA64)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_IA64;
|
||||
#elif defined(_M_MIPS)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_MIPS;
|
||||
#elif defined(_M_PPC)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_PPC;
|
||||
#elif defined(_M_ALPHA)
|
||||
cpuArch = PROCESSOR_ARCHITECTURE_ALPHA;
|
||||
#endif
|
||||
|
||||
return cpuArch;
|
||||
}
|
||||
|
||||
DWORD GetNumberOfProcessors()
|
||||
{
|
||||
DWORD numCPUs = 1;
|
||||
|
||||
/* TODO: Android and iOS */
|
||||
|
||||
#if defined(__linux__) || defined(__sun) || defined(_AIX)
|
||||
numCPUs = (DWORD) sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__) || \
|
||||
defined(__OpenBSD__) || defined(__DragonFly__) || defined(__MACOSX__)
|
||||
{
|
||||
int mib[4];
|
||||
size_t length = sizeof(numCPU);
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_AVAILCPU;
|
||||
|
||||
sysctl(mib, 2, &numCPUs, &length, NULL, 0);
|
||||
|
||||
if (numCPUs < 1)
|
||||
{
|
||||
mib[1] = HW_NCPU;
|
||||
sysctl(mib, 2, &numCPUs, &length, NULL, 0);
|
||||
|
||||
if (numCPUs < 1)
|
||||
numCPUs = 1;
|
||||
}
|
||||
}
|
||||
#elif defined(__hpux)
|
||||
numCPUs = (DWORD) mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
||||
#elif defined(__sgi)
|
||||
numCPUs = (DWORD) sysconf(_SC_NPROC_ONLN);
|
||||
#endif
|
||||
|
||||
return numCPUs;
|
||||
}
|
||||
|
||||
void GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
|
||||
{
|
||||
lpSystemInfo->wProcessorArchitecture = 0;
|
||||
lpSystemInfo->wProcessorArchitecture = GetProcessorArchitecture();
|
||||
lpSystemInfo->wReserved = 0;
|
||||
|
||||
lpSystemInfo->dwPageSize = 0;
|
||||
@ -82,7 +143,7 @@ void GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
|
||||
lpSystemInfo->lpMaximumApplicationAddress = NULL;
|
||||
lpSystemInfo->dwActiveProcessorMask = 0;
|
||||
|
||||
lpSystemInfo->dwNumberOfProcessors = 0;
|
||||
lpSystemInfo->dwNumberOfProcessors = GetNumberOfProcessors();
|
||||
lpSystemInfo->dwProcessorType = 0;
|
||||
|
||||
lpSystemInfo->dwAllocationGranularity = 0;
|
||||
|
@ -4,6 +4,23 @@
|
||||
|
||||
int TestGetNativeSystemInfo(int argc, char* argv[])
|
||||
{
|
||||
SYSTEM_INFO sysinfo;
|
||||
|
||||
GetNativeSystemInfo(&sysinfo);
|
||||
|
||||
printf("SystemInfo:\n");
|
||||
printf("\twProcessorArchitecture: %d\n", sysinfo.wProcessorArchitecture);
|
||||
printf("\twReserved: %d\n", sysinfo.wReserved);
|
||||
printf("\tdwPageSize: 0x%08X\n", sysinfo.dwPageSize);
|
||||
printf("\tlpMinimumApplicationAddress: %p\n", sysinfo.lpMinimumApplicationAddress);
|
||||
printf("\tlpMaximumApplicationAddress: %p\n", sysinfo.lpMaximumApplicationAddress);
|
||||
printf("\tdwActiveProcessorMask: 0x%08X\n", sysinfo.dwActiveProcessorMask);
|
||||
printf("\tdwNumberOfProcessors: %d\n", sysinfo.dwNumberOfProcessors);
|
||||
printf("\tdwProcessorType: %d\n", sysinfo.dwProcessorType);
|
||||
printf("\tdwAllocationGranularity: %d\n", sysinfo.dwAllocationGranularity);
|
||||
printf("\twProcessorLevel: %d\n", sysinfo.wProcessorLevel);
|
||||
printf("\twProcessorRevision: %d\n", sysinfo.wProcessorRevision);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user