From cf2d8f71d6173c34fa0b233e2e04196d1c9642ea Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 13 Aug 2018 22:23:05 -0700 Subject: [PATCH] Avoid setting timer resolution to 1 ms while Moonlight is not streaming --- app/main.cpp | 5 +++++ app/streaming/session.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/main.cpp b/app/main.cpp index 1f6a4dca..5d5ba17b 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -200,6 +200,11 @@ int main(int argc, char *argv[]) SDL_GetError()); } + // Avoid the default behavior of changing the timer resolution to 1 ms. + // We don't want this all the time that Moonlight is open. We will set + // it manually when we start streaming. + SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0"); + int err = app.exec(); SDL_Quit(); diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 1e779a9e..551a5567 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -756,6 +756,10 @@ void Session::exec() // Disable the screen saver SDL_DisableScreenSaver(); + // Set timer resolution to 1 ms on Windows for greater + // sleep precision and more accurate callback timing. + SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); + // Raise the priority of the main thread, since it handles // time-sensitive video rendering if (SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH) < 0) { @@ -873,6 +877,7 @@ DispatchDeferredCleanup: // so we can return to the Qt GUI ASAP. SDL_SetRelativeMouseMode(SDL_FALSE); SDL_EnableScreenSaver(); + SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0"); // Destroy the decoder, since this must be done on the main thread SDL_AtomicLock(&m_DecoderLock);