[host] general performance improvements

This commit is contained in:
Geoffrey McRae
2018-10-04 00:07:34 +10:00
parent 471303a179
commit 8f0a6cd810
7 changed files with 200 additions and 158 deletions

View File

@@ -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, &currentRes);
/* 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;
}