Browse Source

win-wasapi: Register capture thread with MMCSS

Ensure audio gets more priority to help prevent glitching.
jpark37 4 years ago
parent
commit
d1230c292e
2 changed files with 9 additions and 0 deletions
  1. 1 0
      plugins/win-wasapi/CMakeLists.txt
  2. 8 0
      plugins/win-wasapi/win-wasapi.cpp

+ 1 - 0
plugins/win-wasapi/CMakeLists.txt

@@ -15,6 +15,7 @@ add_library(win-wasapi MODULE
 	${win-wasapi_SOURCES}
 	${win-wasapi_HEADERS})
 target_link_libraries(win-wasapi
+	Avrt
 	libobs)
 set_target_properties(win-wasapi PROPERTIES FOLDER "plugins")
 

+ 8 - 0
plugins/win-wasapi/win-wasapi.cpp

@@ -13,6 +13,8 @@
 #include <atomic>
 #include <cinttypes>
 
+#include <avrt.h>
+
 using namespace std;
 
 #define OPT_DEVICE_ID "device_id"
@@ -577,6 +579,9 @@ DWORD WINAPI WASAPISource::CaptureThread(LPVOID param)
 		     hr);
 	}
 
+	DWORD unused = 0;
+	const HANDLE handle = AvSetMmThreadCharacteristics(L"Audio", &unused);
+
 	WASAPISource *source = (WASAPISource *)param;
 
 	const HANDLE inactive_sigs[] = {
@@ -684,6 +689,9 @@ DWORD WINAPI WASAPISource::CaptureThread(LPVOID param)
 		}
 	}
 
+	if (handle)
+		AvRevertMmThreadCharacteristics(handle);
+
 	if (com_initialized)
 		CoUninitialize();