From 16cd20c46f02a052f06742329dc375a695bb6e0b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 8 Nov 2015 19:31:09 +0100 Subject: [PATCH] win32: request MMCSS "Playback" profile --- video/out/w32_common.c | 10 ++++++++++ wscript | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 09088df79d..667d7b425a 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "options/options.h" #include "input/keycodes.h" @@ -107,6 +108,8 @@ struct vo_w32_state { // updates on move/resize/displaychange double display_fps; + + HANDLE avrt_handle; }; typedef struct tagDropTarget { @@ -1263,6 +1266,11 @@ int vo_w32_init(struct vo *vo) goto fail; } + // While the UI runs in its own thread, the thread in which this function + // runs in will be the renderer thread. Apply magic MMCSS cargo-cult, + // which might stop Windows from throttling clock rate and so on. + w32->avrt_handle = AvSetMmThreadCharacteristicsW(L"Playback", &(DWORD){0}); + return 1; fail: talloc_free(w32); @@ -1393,6 +1401,8 @@ void vo_w32_uninit(struct vo *vo) mp_dispatch_run(w32->dispatch, do_terminate, w32); pthread_join(w32->thread, NULL); + AvRevertMmThreadCharacteristics(w32->avrt_handle); + talloc_free(w32); vo->w32 = NULL; } diff --git a/wscript b/wscript index 572be4b176..d96f74b757 100644 --- a/wscript +++ b/wscript @@ -130,7 +130,7 @@ main_dependencies = [ 'name': 'win32', 'desc': 'win32', 'deps_any': [ 'os-win32', 'os-cygwin' ], - 'func': check_cc(lib=['winmm', 'gdi32', 'ole32', 'uuid']), + 'func': check_cc(lib=['winmm', 'gdi32', 'ole32', 'uuid', 'avrt']), }, { 'name': '--win32-internal-pthreads', 'desc': 'internal pthread wrapper for win32 (Vista+)',