directsoundsrc: Check return values of DirectSound functions in read loop

Otherwise we might end up in an infinite loop because of errors.

Also take the element's mutex in unprepare().

https://bugzilla.gnome.org/show_bug.cgi?id=738292
This commit is contained in:
Thomas Roos 2015-12-11 11:39:08 +01:00 committed by Sebastian Dröge
parent 7ae23d13c8
commit d794908dfd

View File

@ -545,12 +545,14 @@ gst_directsound_src_unprepare (GstAudioSrc * asrc)
dsoundsrc = GST_DIRECTSOUND_SRC (asrc); dsoundsrc = GST_DIRECTSOUND_SRC (asrc);
GST_DSOUND_LOCK (dsoundsrc);
/* Stop capturing */ /* Stop capturing */
IDirectSoundCaptureBuffer_Stop (dsoundsrc->pDSBSecondary); IDirectSoundCaptureBuffer_Stop (dsoundsrc->pDSBSecondary);
/* Release buffer */ /* Release buffer */
IDirectSoundCaptureBuffer_Release (dsoundsrc->pDSBSecondary); IDirectSoundCaptureBuffer_Release (dsoundsrc->pDSBSecondary);
GST_DSOUND_UNLOCK (dsoundsrc);
return TRUE; return TRUE;
} }
@ -583,6 +585,11 @@ gst_directsound_src_read (GstAudioSrc * asrc, gpointer data, guint length,
hRes = IDirectSoundCaptureBuffer_GetStatus (dsoundsrc->pDSBSecondary, hRes = IDirectSoundCaptureBuffer_GetStatus (dsoundsrc->pDSBSecondary,
&dwStatus); &dwStatus);
if (FAILED (hRes)) {
GST_DSOUND_UNLOCK (dsoundsrc);
return -1;
}
/* Starting capturing if not already */ /* Starting capturing if not already */
if (!(dwStatus & DSCBSTATUS_CAPTURING)) { if (!(dwStatus & DSCBSTATUS_CAPTURING)) {
hRes = IDirectSoundCaptureBuffer_Start (dsoundsrc->pDSBSecondary, hRes = IDirectSoundCaptureBuffer_Start (dsoundsrc->pDSBSecondary,
@ -598,6 +605,11 @@ gst_directsound_src_read (GstAudioSrc * asrc, gpointer data, guint length,
IDirectSoundCaptureBuffer_GetCurrentPosition (dsoundsrc->pDSBSecondary, IDirectSoundCaptureBuffer_GetCurrentPosition (dsoundsrc->pDSBSecondary,
&dwCurrentCaptureCursor, NULL); &dwCurrentCaptureCursor, NULL);
if (FAILED (hRes)) {
GST_DSOUND_UNLOCK (dsoundsrc);
return -1;
}
/* calculate the buffer */ /* calculate the buffer */
if (dwCurrentCaptureCursor < dsoundsrc->current_circular_offset) { if (dwCurrentCaptureCursor < dsoundsrc->current_circular_offset) {
dwBufferSize = dsoundsrc->buffer_size - dwBufferSize = dsoundsrc->buffer_size -