From 4d72fd98842f519c2ec3c0352642b159ffc6ca57 Mon Sep 17 00:00:00 2001 From: Thomas Roos Date: Fri, 11 Dec 2015 11:23:13 +0100 Subject: [PATCH] directsoundsink: Check the return value of GetStatus() too to decide if there was an error If GetStatus() fails, the status itself won't be very meaningful but we also have to look at its return value. This fixes blocking pipelines when removing sound devices or during other errors, where we wouldn't notice the error and then wait forever. https://bugzilla.gnome.org/show_bug.cgi?id=734098 --- sys/directsound/gstdirectsoundsink.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sys/directsound/gstdirectsoundsink.c b/sys/directsound/gstdirectsoundsink.c index 39cb092..5a4e356 100644 --- a/sys/directsound/gstdirectsoundsink.c +++ b/sys/directsound/gstdirectsoundsink.c @@ -589,8 +589,8 @@ static gint gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length) { GstDirectSoundSink *dsoundsink; - DWORD dwStatus; - HRESULT hRes; + DWORD dwStatus = 0; + HRESULT hRes, hRes2; LPVOID pLockedBuffer1 = NULL, pLockedBuffer2 = NULL; DWORD dwSizeBuffer1, dwSizeBuffer2; DWORD dwCurrentPlayCursor; @@ -603,10 +603,10 @@ gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length) hRes = IDirectSoundBuffer_GetStatus (dsoundsink->pDSBSecondary, &dwStatus); /* get current play cursor position */ - hRes = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary, + hRes2 = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary, &dwCurrentPlayCursor, NULL); - if (SUCCEEDED (hRes) && (dwStatus & DSBSTATUS_PLAYING)) { + if (SUCCEEDED (hRes) && SUCCEEDED (hRes2) && (dwStatus & DSBSTATUS_PLAYING)) { DWORD dwFreeBufferSize; calculate_freesize: @@ -624,14 +624,19 @@ gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length) hRes = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary, &dwCurrentPlayCursor, NULL); - hRes = + hRes2 = IDirectSoundBuffer_GetStatus (dsoundsink->pDSBSecondary, &dwStatus); - if (SUCCEEDED (hRes) && (dwStatus & DSBSTATUS_PLAYING)) + if (SUCCEEDED (hRes) && SUCCEEDED (hRes2) + && (dwStatus & DSBSTATUS_PLAYING)) goto calculate_freesize; else { dsoundsink->first_buffer_after_reset = FALSE; GST_DSOUND_UNLOCK (dsoundsink); - return 0; + GST_ELEMENT_ERROR (dsoundsink, RESOURCE, OPEN_WRITE, + ("gst_directsound_sink_write: IDirectSoundBuffer_GetStatus %s, IDirectSoundBuffer_GetCurrentPosition: %s, dwStatus: %lu", + DXGetErrorString9 (hRes2), DXGetErrorString9 (hRes), dwStatus), + (NULL)); + return -1; } } } @@ -690,7 +695,7 @@ gst_directsound_sink_delay (GstAudioSink * asink) /* get current buffer status */ hRes = IDirectSoundBuffer_GetStatus (dsoundsink->pDSBSecondary, &dwStatus); - if (dwStatus & DSBSTATUS_PLAYING) { + if (SUCCEEDED (hRes) && (dwStatus & DSBSTATUS_PLAYING)) { /*evaluate the number of samples in queue in the circular buffer */ hRes = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary, &dwCurrentPlayCursor, NULL); -- 2.7.4