1
0
Эх сурвалжийг харах

libobs/media-io: Register audio thread with MMCSS

Ensure audio gets more priority to help prevent glitching.
jpark37 4 жил өмнө
parent
commit
e582879303

+ 1 - 1
libobs/CMakeLists.txt

@@ -120,7 +120,7 @@ if(WIN32)
 	set(libobs_audio_monitoring_HEADERS
 		audio-monitoring/win32/wasapi-output.h
 		)
-	set(libobs_PLATFORM_DEPS winmm)
+	set(libobs_PLATFORM_DEPS Avrt winmm)
 	if(MSVC)
 		set(libobs_PLATFORM_DEPS
 		${libobs_PLATFORM_DEPS}

+ 16 - 0
libobs/media-io/audio-io.c

@@ -28,6 +28,12 @@
 #include "audio-io.h"
 #include "audio-resampler.h"
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+#include <avrt.h>
+#endif
+
 extern profiler_name_store_t *obs_get_profiler_name_store(void);
 
 /* #define DEBUG_AUDIO */
@@ -197,6 +203,11 @@ static void input_and_output(struct audio_output *audio, uint64_t audio_time,
 
 static void *audio_thread(void *param)
 {
+#ifdef _WIN32
+	DWORD unused = 0;
+	const HANDLE handle = AvSetMmThreadCharacteristics(L"Audio", &unused);
+#endif
+
 	struct audio_output *audio = param;
 	size_t rate = audio->info.samples_per_sec;
 	uint64_t samples = 0;
@@ -234,6 +245,11 @@ static void *audio_thread(void *param)
 		profile_reenable_thread();
 	}
 
+#ifdef _WIN32
+	if (handle)
+		AvRevertMmThreadCharacteristics(handle);
+#endif
+
 	return NULL;
 }