Date: Tue, 01 Feb 2005 17:53:07 -0800
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Feb 2005 19:39:08 +0000
changeset 1037c5dedfdb4e42
parent 1036 50f4e7e4d117
child 1038 29d7db09776e
Date: Tue, 01 Feb 2005 17:53:07 -0800
From: Bill May
Subject: [SDL] Diffs for dsp audio in case of failures.

The rewrite recently done for 1.2.8 forgot to handle error cases
by closing the audio.

Here is a patch that does.
src/audio/dsp/SDL_dspaudio.c
     1.1 --- a/src/audio/dsp/SDL_dspaudio.c	Sat Feb 12 18:03:54 2005 +0000
     1.2 +++ b/src/audio/dsp/SDL_dspaudio.c	Sat Feb 12 19:39:08 2005 +0000
     1.3 @@ -187,6 +187,7 @@
     1.4  		flags &= ~O_NONBLOCK;
     1.5  		if ( fcntl(audio_fd, F_SETFL, flags) < 0 ) {
     1.6  			SDL_SetError("Couldn't set audio blocking mode");
     1.7 +			DSP_CloseAudio(this);
     1.8  			return(-1);
     1.9  		}
    1.10  	}
    1.11 @@ -195,6 +196,7 @@
    1.12  	if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) {
    1.13  		perror("SNDCTL_DSP_GETFMTS");
    1.14  		SDL_SetError("Couldn't get audio format list");
    1.15 +		DSP_CloseAudio(this);
    1.16  		return(-1);
    1.17  	}
    1.18  
    1.19 @@ -252,6 +254,7 @@
    1.20  	}
    1.21  	if ( format == 0 ) {
    1.22  		SDL_SetError("Couldn't find any hardware audio formats");
    1.23 +		DSP_CloseAudio(this);
    1.24  		return(-1);
    1.25  	}
    1.26  	spec->format = test_format;
    1.27 @@ -262,6 +265,7 @@
    1.28  						(value != format) ) {
    1.29  		perror("SNDCTL_DSP_SETFMT");
    1.30  		SDL_SetError("Couldn't set audio format");
    1.31 +		DSP_CloseAudio(this);
    1.32  		return(-1);
    1.33  	}
    1.34  
    1.35 @@ -270,6 +274,7 @@
    1.36  	if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0 ) {
    1.37  		perror("SNDCTL_DSP_CHANNELS");
    1.38  		SDL_SetError("Cannot set the number of channels");
    1.39 +		DSP_CloseAudio(this);
    1.40  		return(-1);
    1.41  	}
    1.42  	spec->channels = value;
    1.43 @@ -279,6 +284,7 @@
    1.44  	if ( ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0 ) {
    1.45  		perror("SNDCTL_DSP_SPEED");
    1.46  		SDL_SetError("Couldn't set audio frequency");
    1.47 +		DSP_CloseAudio(this);
    1.48  		return(-1);
    1.49  	}
    1.50  	spec->freq = value;
    1.51 @@ -290,6 +296,7 @@
    1.52  	for ( frag_spec = 0; (0x01<<frag_spec) < spec->size; ++frag_spec );
    1.53  	if ( (0x01<<frag_spec) != spec->size ) {
    1.54  		SDL_SetError("Fragment size must be a power of two");
    1.55 +		DSP_CloseAudio(this);
    1.56  		return(-1);
    1.57  	}
    1.58  	frag_spec |= 0x00020000;	/* two fragments, for low latency */
    1.59 @@ -317,6 +324,7 @@
    1.60  	mixlen = spec->size;
    1.61  	mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
    1.62  	if ( mixbuf == NULL ) {
    1.63 +	  DSP_CloseAudio(this);
    1.64  		return(-1);
    1.65  	}
    1.66  	memset(mixbuf, spec->silence, spec->size);