wasapisink: Playback fails when calling gst_element_set_state in a concurrent thread
When using gst_element_set_state in a concurrent thread it fails because of a missing CoInitializeEx() in gst_wasapi_util_get_device_enumerator, so initial playback fails. I added the following patch to gstwsapiutil.c which seem to fix it, but I'm not entirely sure if this is correct:
diff --git a/sys/wasapi/gstwasapiutil.c b/sys/wasapi/gstwasapiutil.c
index 1111111..2222222 100644
--- a/sys/wasapi/gstwasapiutil.c
+++ b/sys/wasapi/gstwasapiutil.c
@@ -311,10 +311,14 @@ gst_wasapi_util_get_device_enumerator (GstObject *
self)
HRESULT hr;
IMMDeviceEnumerator *enumerator = NULL;
+ HRESULT hr_coinit = CoInitializeEx (NULL, COINIT_MULTITHREADED);
+
hr = CoCreateInstance (&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
&IID_IMMDeviceEnumerator, (void **) &enumerator);
HR_FAILED_RET (hr, CoCreateInstance (MMDeviceEnumerator), NULL);
+ if (hr_coinit == S_OK || hr_coinit == S_FALSE) CoUninitialize();
+
return enumerator;
}