wasapi: fix reinit of audioclient in prepare()
authorJakub Janků <jjanku@redhat.com>
Thu, 18 Mar 2021 09:55:58 +0000 (10:55 +0100)
committerJakub Janků <janku.jakub.jj@gmail.com>
Mon, 12 Jul 2021 11:47:07 +0000 (13:47 +0200)
When the sink goes from PLAYING to READY and then back to PLAYING,
the initialization of the audioclient in prepare() fails with the
error AUDCLNT_E_ALREADY_INITIALIZED. As a result, the playback
stops.

To fix this, we need to drop the AudioClient in unprepare() and
grab a new one in prepare() to be able to initialize it again
with the new buffer spec.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2096>

sys/wasapi/gstwasapisink.c

index 8758897..711f6f6 100644 (file)
@@ -487,6 +487,13 @@ gst_wasapi_sink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec)
 
   CoInitializeEx (NULL, COINIT_MULTITHREADED);
 
+  if (!self->client) {
+    GST_DEBUG_OBJECT (self, "no IAudioClient, creating a new one");
+    if (!gst_wasapi_util_get_audio_client (GST_ELEMENT (self),
+            self->device, &self->client))
+      goto beach;
+  }
+
   if (gst_wasapi_sink_can_audioclient3 (self)) {
     if (!gst_wasapi_util_initialize_audioclient3 (GST_ELEMENT (self), spec,
             (IAudioClient3 *) self->client, self->mix_format, self->low_latency,
@@ -592,7 +599,8 @@ gst_wasapi_sink_unprepare (GstAudioSink * asink)
   GstWasapiSink *self = GST_WASAPI_SINK (asink);
 
   if (self->client != NULL) {
-    IAudioClient_Stop (self->client);
+    IUnknown_Release (self->client);
+    self->client = NULL;
   }
 
   if (self->render_client != NULL) {