self->low_latency = DEFAULT_LOW_LATENCY;
self->try_audioclient3 = DEFAULT_AUDIOCLIENT3;
self->event_handle = CreateEvent (NULL, FALSE, FALSE, NULL);
+ self->cancellable = CreateEvent (NULL, TRUE, FALSE, NULL);
self->client_needs_restart = FALSE;
CoInitializeEx (NULL, COINIT_MULTITHREADED);
self->event_handle = NULL;
}
+ if (self->cancellable != NULL) {
+ CloseHandle (self->cancellable);
+ self->cancellable = NULL;
+ }
+
if (self->client != NULL) {
IUnknown_Release (self->client);
self->client = NULL;
res = TRUE;
+ /* reset cancellable event handle */
+ ResetEvent (self->cancellable);
+
beach:
/* unprepare() is not called if prepare() fails, but we want it to be, so call
* it manually when needed */
gint16 *dst = NULL;
DWORD dwWaitResult;
guint can_frames, have_frames, n_frames, write_len, written_len = 0;
+ HANDLE event_handle[2];
+
+ event_handle[0] = self->event_handle;
+ event_handle[1] = self->cancellable;
GST_OBJECT_LOCK (self);
if (self->client_needs_restart) {
HR_FAILED_ELEMENT_ERROR_AND (hr, IAudioClient::Start, self,
GST_OBJECT_UNLOCK (self); goto err);
self->client_needs_restart = FALSE;
+ ResetEvent (self->cancellable);
}
GST_OBJECT_UNLOCK (self);
if (self->sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE) {
/* In exclusive mode we have to wait always */
- dwWaitResult = WaitForSingleObject (self->event_handle, INFINITE);
- if (dwWaitResult != WAIT_OBJECT_0) {
+ dwWaitResult = WaitForMultipleObjects (2, event_handle, FALSE, INFINITE);
+ if (dwWaitResult != WAIT_OBJECT_0 && dwWaitResult != WAIT_OBJECT_0 + 1) {
GST_ERROR_OBJECT (self, "Error waiting for event handle: %x",
(guint) dwWaitResult);
goto err;
}
+ /* ::reset was requested */
+ if (dwWaitResult == WAIT_OBJECT_0 + 1) {
+ GST_DEBUG_OBJECT (self, "operation was cancelled");
+ return -1;
+ }
+
can_frames = gst_wasapi_sink_get_can_frames (self);
if (can_frames < 0) {
GST_ERROR_OBJECT (self, "Error getting frames to write to");
}
if (can_frames == 0) {
- dwWaitResult = WaitForSingleObject (self->event_handle, INFINITE);
- if (dwWaitResult != WAIT_OBJECT_0) {
+ dwWaitResult = WaitForMultipleObjects (2, event_handle, FALSE, INFINITE);
+ if (dwWaitResult != WAIT_OBJECT_0 && dwWaitResult != WAIT_OBJECT_0 + 1) {
GST_ERROR_OBJECT (self, "Error waiting for event handle: %x",
(guint) dwWaitResult);
goto err;
}
+
+ /* ::reset was requested */
+ if (dwWaitResult == WAIT_OBJECT_0 + 1) {
+ GST_DEBUG_OBJECT (self, "operation was cancelled");
+ return -1;
+ }
+
can_frames = gst_wasapi_sink_get_can_frames (self);
if (can_frames < 0) {
GST_ERROR_OBJECT (self, "Error getting frames to write to");
if (!self->client)
return;
+ SetEvent (self->cancellable);
+
GST_OBJECT_LOCK (self);
hr = IAudioClient_Stop (self->client);
HR_FAILED_AND (hr, IAudioClient::Stop,);
self->low_latency = DEFAULT_LOW_LATENCY;
self->try_audioclient3 = DEFAULT_AUDIOCLIENT3;
self->event_handle = CreateEvent (NULL, FALSE, FALSE, NULL);
+ self->cancellable = CreateEvent (NULL, TRUE, FALSE, NULL);
self->client_needs_restart = FALSE;
self->adapter = gst_adapter_new ();
self->event_handle = NULL;
}
+ if (self->cancellable != NULL) {
+ CloseHandle (self->cancellable);
+ self->cancellable = NULL;
+ }
+
if (self->client_clock != NULL) {
IUnknown_Release (self->client_clock);
self->client_clock = NULL;
(self)->ringbuffer, self->positions);
res = TRUE;
+
+ /* reset cancellable event handle */
+ ResetEvent (self->cancellable);
+
beach:
+
/* unprepare() is not called if prepare() fails, but we want it to be, so call
* it manually when needed */
if (!res)
HR_FAILED_ELEMENT_ERROR_AND (hr, IAudioClient::Start, self,
GST_OBJECT_UNLOCK (self); goto err);
self->client_needs_restart = FALSE;
+ ResetEvent (self->cancellable);
gst_adapter_clear (self->adapter);
}
while (wanted > 0) {
DWORD dwWaitResult;
guint got_frames, avail_frames, n_frames, want_frames, read_len;
+ HANDLE event_handle[2];
+
+ event_handle[0] = self->event_handle;
+ event_handle[1] = self->cancellable;
/* Wait for data to become available */
- dwWaitResult = WaitForSingleObject (self->event_handle, INFINITE);
- if (dwWaitResult != WAIT_OBJECT_0) {
+ dwWaitResult = WaitForMultipleObjects (2, event_handle, FALSE, INFINITE);
+ if (dwWaitResult != WAIT_OBJECT_0 && dwWaitResult != WAIT_OBJECT_0 + 1) {
GST_ERROR_OBJECT (self, "Error waiting for event handle: %x",
(guint) dwWaitResult);
goto err;
}
+ /* ::reset was requested */
+ if (dwWaitResult == WAIT_OBJECT_0 + 1) {
+ GST_DEBUG_OBJECT (self, "operation was cancelled");
+ return -1;
+ }
+
hr = IAudioCaptureClient_GetBuffer (self->capture_client,
(BYTE **) & from, &got_frames, &flags, NULL, NULL);
if (hr != S_OK) {
if (!self->client)
return;
+ SetEvent (self->cancellable);
+
GST_OBJECT_LOCK (self);
hr = IAudioClient_Stop (self->client);
HR_FAILED_RET (hr, IAudioClock::Stop,);