clean up resources better if DirectSound OpenStream fails

This commit is contained in:
rossb 2010-01-24 09:34:48 +00:00
commit 91d13a5866

View file

@ -1585,6 +1585,8 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
PaError result = paNoError; PaError result = paNoError;
PaWinDsHostApiRepresentation *winDsHostApi = (PaWinDsHostApiRepresentation*)hostApi; PaWinDsHostApiRepresentation *winDsHostApi = (PaWinDsHostApiRepresentation*)hostApi;
PaWinDsStream *stream = 0; PaWinDsStream *stream = 0;
int bufferProcessorIsInitialized = 0;
int streamRepresentationIsInitialized = 0;
PaWinDsDeviceInfo *inputWinDsDeviceInfo, *outputWinDsDeviceInfo; PaWinDsDeviceInfo *inputWinDsDeviceInfo, *outputWinDsDeviceInfo;
PaDeviceInfo *inputDeviceInfo, *outputDeviceInfo; PaDeviceInfo *inputDeviceInfo, *outputDeviceInfo;
int inputChannelCount, outputChannelCount; int inputChannelCount, outputChannelCount;
@ -1721,6 +1723,8 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
&winDsHostApi->blockingStreamInterface, streamCallback, userData ); &winDsHostApi->blockingStreamInterface, streamCallback, userData );
} }
streamRepresentationIsInitialized = 1;
PaUtil_InitializeCpuLoadMeasurer( &stream->cpuLoadMeasurer, sampleRate ); PaUtil_InitializeCpuLoadMeasurer( &stream->cpuLoadMeasurer, sampleRate );
@ -1763,6 +1767,7 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
if( result != paNoError ) if( result != paNoError )
goto error; goto error;
bufferProcessorIsInitialized = 1;
stream->streamRepresentation.streamInfo.inputLatency = stream->streamRepresentation.streamInfo.inputLatency =
PaUtil_GetBufferProcessorInputLatency(&stream->bufferProcessor); /* FIXME: not initialised anywhere else */ PaUtil_GetBufferProcessorInputLatency(&stream->bufferProcessor); /* FIXME: not initialised anywhere else */
@ -1930,6 +1935,38 @@ error:
if( stream->processingCompleted != NULL ) if( stream->processingCompleted != NULL )
CloseHandle( stream->processingCompleted ); CloseHandle( stream->processingCompleted );
if( stream->pDirectSoundOutputBuffer )
{
IDirectSoundBuffer_Stop( stream->pDirectSoundOutputBuffer );
IDirectSoundBuffer_Release( stream->pDirectSoundOutputBuffer );
stream->pDirectSoundOutputBuffer = NULL;
}
if( stream->pDirectSoundInputBuffer )
{
IDirectSoundCaptureBuffer_Stop( stream->pDirectSoundInputBuffer );
IDirectSoundCaptureBuffer_Release( stream->pDirectSoundInputBuffer );
stream->pDirectSoundInputBuffer = NULL;
}
if( stream->pDirectSoundCapture )
{
IDirectSoundCapture_Release( stream->pDirectSoundCapture );
stream->pDirectSoundCapture = NULL;
}
if( stream->pDirectSound )
{
IDirectSound_Release( stream->pDirectSound );
stream->pDirectSound = NULL;
}
if( bufferProcessorIsInitialized )
PaUtil_TerminateBufferProcessor( &stream->bufferProcessor );
if( streamRepresentationIsInitialized )
PaUtil_TerminateStreamRepresentation( &stream->streamRepresentation );
PaUtil_FreeMemory( stream ); PaUtil_FreeMemory( stream );
} }