From 211f968981ba6f2d33dc25b167385f971c616b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jank=C5=AF?= Date: Thu, 18 Mar 2021 10:55:58 +0100 Subject: [PATCH] wasapi: fix reinit of audioclient in prepare() 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: --- sys/wasapi/gstwasapisink.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index 87588974b7..711f6f68a6 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -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) {