Fix: Add AVX2 runtime check and optional x264 compilation
This commit is contained in:
@@ -6,11 +6,22 @@
|
||||
#include <common/iniFile.h>
|
||||
#include <common/LANChecker.h>
|
||||
#include <common/VerifyV2.h>
|
||||
#include <intrin.h> // for __cpuid, __cpuidex
|
||||
extern "C" {
|
||||
#include "reg_startup.h"
|
||||
#include "ServiceWrapper.h"
|
||||
}
|
||||
|
||||
// Check if CPU supports AVX2 instruction set
|
||||
static BOOL IsAVX2Supported()
|
||||
{
|
||||
int cpuInfo[4] = { 0, 0, 0, 0 };
|
||||
__cpuid(cpuInfo, 0);
|
||||
if (cpuInfo[0] < 7) return FALSE;
|
||||
__cpuidex(cpuInfo, 7, 0);
|
||||
return (cpuInfo[1] & (1 << 5)) != 0; // EBX bit 5 = AVX2
|
||||
}
|
||||
|
||||
// 自动启动注册表中的值
|
||||
#define REG_NAME GetExeHashStr().c_str()
|
||||
|
||||
@@ -195,6 +206,14 @@ BOOL CALLBACK callback(DWORD CtrlType)
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
// Check AVX2 support at startup
|
||||
if (!IsAVX2Supported()) {
|
||||
MessageBoxA(NULL,
|
||||
"此程序需要支持 AVX2 指令集的 CPU(2013年后的处理器)。您的 CPU 不支持 AVX2,程序无法运行。",
|
||||
"CPU 不兼容", MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Mprintf("启动运行: %s %s. Arg Count: %d\n", argv[0], argc>1 ? argv[1] : "", argc);
|
||||
InitWindowsService(NewService(
|
||||
g_SETTINGS.installName[0] ? g_SETTINGS.installName : "RemoteControlService",
|
||||
@@ -312,6 +331,13 @@ BOOL APIENTRY DllMain( HINSTANCE hInstance,
|
||||
{
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH: {
|
||||
// Check AVX2 support before starting
|
||||
if (!IsAVX2Supported()) {
|
||||
MessageBoxA(NULL,
|
||||
"此程序需要支持 AVX2 指令集的 CPU(2013年后的处理器)。您的 CPU 不支持 AVX2,程序无法运行。",
|
||||
"CPU 不兼容", MB_ICONERROR);
|
||||
return FALSE;
|
||||
}
|
||||
g_MyApp.g_hInstance = (HINSTANCE)hInstance;
|
||||
CloseHandle(__CreateThread(NULL, 0, AutoRun, hInstance, 0, NULL));
|
||||
break;
|
||||
|
||||
@@ -191,6 +191,7 @@ public:
|
||||
m_pScrollDetector(nullptr), m_bEnableScrollDetect(false), m_bServerSupportsScroll(false),
|
||||
m_bLastFrameWasScroll(false), m_nScrollDetectInterval(1)
|
||||
{
|
||||
SetAlgorithm(algo);
|
||||
m_BitmapInfor_Send = nullptr;
|
||||
m_BmpZoomBuffer = nullptr;
|
||||
m_BmpZoomFirst = nullptr;
|
||||
@@ -985,7 +986,7 @@ public:
|
||||
virtual BYTE SetAlgorithm(int algo)
|
||||
{
|
||||
BYTE oldAlgo = m_bAlgorithm;
|
||||
m_bAlgorithm = algo;
|
||||
m_bAlgorithm = (DISABLE_X264_FOR_TEST && algo == ALGORITHM_H264) ? ALGORITHM_RGB565 : algo;
|
||||
return oldAlgo;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if DISABLE_X264_FOR_TEST
|
||||
CX264Encoder::CX264Encoder() { memset(&m_Param, 0, sizeof(m_Param)); m_pCodec = NULL; m_pPicIn = NULL; m_pPicOut = NULL; }
|
||||
CX264Encoder::~CX264Encoder() {}
|
||||
bool CX264Encoder::open(int, int, int, int) { return false; }
|
||||
bool CX264Encoder::open(x264_param_t*) { return false; }
|
||||
void CX264Encoder::close() {}
|
||||
int CX264Encoder::encode(uint8_t*, uint8_t, uint32_t, uint32_t, uint32_t, uint8_t**, uint32_t*, int) { return -1; }
|
||||
|
||||
#else
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib,"libyuv/libyuv_x64.lib")
|
||||
#pragma comment(lib,"x264/libx264_x64.lib")
|
||||
@@ -153,3 +162,5 @@ int CX264Encoder::encode(
|
||||
*lpSize = encode_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,8 @@ extern "C" {
|
||||
#include <x264\x264.h>
|
||||
}
|
||||
|
||||
#define DISABLE_X264_FOR_TEST 0
|
||||
|
||||
class CX264Encoder
|
||||
{
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user