audioutilsprivate: Don't try to load avrt for UWP application

All APIs in avrt.h are desktop only.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/763>
This commit is contained in:
Seungha Yang 2020-07-17 18:48:15 +09:00
parent 26a88fdb7a
commit f0a9907097

View file

@ -222,7 +222,6 @@ exit:
static struct static struct
{ {
HMODULE dll; HMODULE dll;
gboolean tried_loading;
FARPROC AvSetMmThreadCharacteristics; FARPROC AvSetMmThreadCharacteristics;
FARPROC AvRevertMmThreadCharacteristics; FARPROC AvRevertMmThreadCharacteristics;
@ -234,29 +233,45 @@ static gboolean
__gst_audio_init_thread_priority (void) __gst_audio_init_thread_priority (void)
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (_gst_audio_avrt_tbl.tried_loading) static gsize init_once = 0;
return _gst_audio_avrt_tbl.dll != NULL; static gboolean ret = FALSE;
if (!_gst_audio_avrt_tbl.dll) if (g_once_init_enter (&init_once)) {
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
_gst_audio_avrt_tbl.dll = LoadPackagedLibrary (TEXT ("avrt.dll"), 0);
#else
_gst_audio_avrt_tbl.dll = LoadLibrary (TEXT ("avrt.dll")); _gst_audio_avrt_tbl.dll = LoadLibrary (TEXT ("avrt.dll"));
#endif
if (!_gst_audio_avrt_tbl.dll) { if (!_gst_audio_avrt_tbl.dll) {
GST_WARNING ("Failed to set thread priority, can't find avrt.dll"); GST_WARNING ("Failed to set thread priority, can't find avrt.dll");
_gst_audio_avrt_tbl.tried_loading = TRUE; goto done;
return FALSE; }
_gst_audio_avrt_tbl.AvSetMmThreadCharacteristics =
GetProcAddress (_gst_audio_avrt_tbl.dll,
"AvSetMmThreadCharacteristicsA");
if (!_gst_audio_avrt_tbl.AvSetMmThreadCharacteristics) {
GST_WARNING ("Cannot load AvSetMmThreadCharacteristicsA symbol");
FreeLibrary (_gst_audio_avrt_tbl.dll);
goto done;
}
_gst_audio_avrt_tbl.AvRevertMmThreadCharacteristics =
GetProcAddress (_gst_audio_avrt_tbl.dll,
"AvRevertMmThreadCharacteristics");
if (!_gst_audio_avrt_tbl.AvRevertMmThreadCharacteristics) {
GST_WARNING ("Cannot load AvRevertMmThreadCharacteristics symbol");
FreeLibrary (_gst_audio_avrt_tbl.dll);
goto done;
}
ret = TRUE;
done:
#endif
g_once_init_leave (&init_once, 1);
} }
_gst_audio_avrt_tbl.AvSetMmThreadCharacteristics = return ret;
GetProcAddress (_gst_audio_avrt_tbl.dll, "AvSetMmThreadCharacteristicsA");
_gst_audio_avrt_tbl.AvRevertMmThreadCharacteristics =
GetProcAddress (_gst_audio_avrt_tbl.dll,
"AvRevertMmThreadCharacteristics");
_gst_audio_avrt_tbl.tried_loading = TRUE;
#endif #endif
return TRUE; return TRUE;