From 5409cd49208cf5fe2cdb9233963f40e21291e01a Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 10 Apr 2018 05:13:17 +0530 Subject: [PATCH] wasapi: Handle return value of WaitForSingleObject The wait could've failed for whatever reason, we should handle that. --- sys/wasapi/gstwasapisink.c | 9 ++++++++- sys/wasapi/gstwasapisrc.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index 8267d3fe4f..77720be326 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -616,9 +616,16 @@ gst_wasapi_sink_write (GstAudioSink * asink, gpointer data, guint length) GST_OBJECT_UNLOCK (self); while (pending > 0) { + DWORD dwWaitResult; guint can_frames, have_frames, n_frames, write_len; - WaitForSingleObject (self->event_handle, INFINITE); + dwWaitResult = WaitForSingleObject (self->event_handle, INFINITE); + if (dwWaitResult != WAIT_OBJECT_0) { + GST_ERROR_OBJECT (self, "Error waiting for event handle: %x", + (guint) dwWaitResult); + length -= pending; + goto beach; + } /* We have N frames to be written out */ have_frames = pending / (self->mix_format->nBlockAlign); diff --git a/sys/wasapi/gstwasapisrc.c b/sys/wasapi/gstwasapisrc.c index da1e0975e3..4c51a40241 100644 --- a/sys/wasapi/gstwasapisrc.c +++ b/sys/wasapi/gstwasapisrc.c @@ -565,10 +565,17 @@ gst_wasapi_src_read (GstAudioSrc * asrc, gpointer data, guint length, GST_OBJECT_UNLOCK (self); while (wanted > 0) { + DWORD dwWaitResult; guint have_frames, n_frames, want_frames, read_len; /* Wait for data to become available */ - WaitForSingleObject (self->event_handle, INFINITE); + dwWaitResult = WaitForSingleObject (self->event_handle, INFINITE); + if (dwWaitResult != WAIT_OBJECT_0) { + GST_ERROR_OBJECT (self, "Error waiting for event handle: %x", + (guint) dwWaitResult); + length = 0; + goto beach; + } hr = IAudioCaptureClient_GetBuffer (self->capture_client, (BYTE **) & from, &have_frames, &flags, NULL, NULL);