mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-12-20 19:50:11 +00:00
[host] general performance improvements
This commit is contained in:
@@ -19,6 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
#include <windows.h>
|
||||
#include <shlwapi.h>
|
||||
#include <avrt.h>
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "vendor/getopt/getopt.h"
|
||||
@@ -41,6 +42,8 @@ void doLicense();
|
||||
bool consoleActive = false;
|
||||
void setupConsole();
|
||||
|
||||
extern "C" NTSYSAPI NTSTATUS NTAPI NtSetTimerResolution(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
|
||||
|
||||
struct StartupArgs
|
||||
{
|
||||
bool foreground;
|
||||
@@ -54,8 +57,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdParam
|
||||
TraceUtil::Initialize();
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
|
||||
|
||||
struct StartupArgs args;
|
||||
args.foreground = false;
|
||||
args.captureDevice = NULL;
|
||||
@@ -89,6 +90,19 @@ int run(struct StartupArgs & args)
|
||||
if (args.foreground)
|
||||
setupConsole();
|
||||
|
||||
/* increase the system timer resolution */
|
||||
ULONG currentRes;
|
||||
NtSetTimerResolution(0, TRUE, ¤tRes);
|
||||
|
||||
/* boost our thread priority class as high as possible */
|
||||
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
|
||||
|
||||
/* use MMCSS to boost our priority for capture */
|
||||
DWORD taskIndex = 0;
|
||||
HANDLE task = AvSetMmThreadCharacteristics(L"Capture", &taskIndex);
|
||||
if (!task || (AvSetMmThreadPriority(task, AVRT_PRIORITY_CRITICAL) == FALSE))
|
||||
DEBUG_WARN("Failed to boosted priority using MMCSS");
|
||||
|
||||
ICapture * captureDevice;
|
||||
if (args.captureDevice == NULL)
|
||||
captureDevice = CaptureFactory::DetectDevice(&args.captureOptions);
|
||||
@@ -121,6 +135,10 @@ int run(struct StartupArgs & args)
|
||||
}
|
||||
|
||||
svc->DeInitialize();
|
||||
|
||||
if (task)
|
||||
AvRevertMmThreadCharacteristics(task);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user