music_flac.c
changeset 545 32e5ed415a34
parent 542 3de4970b36d4
child 561 87bdb4c81c0b
     1.1 --- a/music_flac.c	Wed Jan 04 01:09:57 2012 -0500
     1.2 +++ b/music_flac.c	Wed Jan 04 01:41:10 2012 -0500
     1.3 @@ -306,6 +306,13 @@
     1.4  	int init_stage = 0;
     1.5  	int was_error = 1;
     1.6  
     1.7 +	if (!Mix_Init(MIX_INIT_FLAC)) {
     1.8 +		if (freerw) {
     1.9 +			SDL_RWclose(rw);
    1.10 +		}
    1.11 +		return NULL;
    1.12 +	}
    1.13 +
    1.14  	music = (FLAC_music *)malloc ( sizeof (*music));
    1.15  	if (music) {
    1.16  		/* Initialize the music structure */
    1.17 @@ -323,35 +330,33 @@
    1.18  		music->flac_data.data_len = 0;
    1.19  		music->flac_data.data_read = 0;
    1.20  
    1.21 -		if (Mix_Init(MIX_INIT_FLAC)) {
    1.22 -			init_stage++; // stage 1!
    1.23 +		init_stage++; // stage 1!
    1.24  
    1.25 -			music->flac_decoder = flac.FLAC__stream_decoder_new ();
    1.26 +		music->flac_decoder = flac.FLAC__stream_decoder_new ();
    1.27  
    1.28 -			if (music->flac_decoder != NULL) {
    1.29 -				init_stage++; // stage 2!
    1.30 +		if (music->flac_decoder != NULL) {
    1.31 +			init_stage++; // stage 2!
    1.32  
    1.33 -				if (flac.FLAC__stream_decoder_init_stream(
    1.34 -							music->flac_decoder,
    1.35 -							flac_read_music_cb, flac_seek_music_cb,
    1.36 -							flac_tell_music_cb, flac_length_music_cb,
    1.37 -							flac_eof_music_cb, flac_write_music_cb,
    1.38 -							flac_metadata_music_cb, flac_error_music_cb,
    1.39 -							music) == FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
    1.40 -					init_stage++; // stage 3!
    1.41 +			if (flac.FLAC__stream_decoder_init_stream(
    1.42 +						music->flac_decoder,
    1.43 +						flac_read_music_cb, flac_seek_music_cb,
    1.44 +						flac_tell_music_cb, flac_length_music_cb,
    1.45 +						flac_eof_music_cb, flac_write_music_cb,
    1.46 +						flac_metadata_music_cb, flac_error_music_cb,
    1.47 +						music) == FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
    1.48 +				init_stage++; // stage 3!
    1.49  
    1.50 -					if (flac.FLAC__stream_decoder_process_until_end_of_metadata
    1.51 -											(music->flac_decoder)) {
    1.52 -						was_error = 0;
    1.53 -					} else {
    1.54 -						SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
    1.55 -					}
    1.56 +				if (flac.FLAC__stream_decoder_process_until_end_of_metadata
    1.57 +										(music->flac_decoder)) {
    1.58 +					was_error = 0;
    1.59  				} else {
    1.60 -					SDL_SetError("FLAC__stream_decoder_init_stream() failed");
    1.61 +					SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
    1.62  				}
    1.63  			} else {
    1.64 -				SDL_SetError("FLAC__stream_decoder_new() failed");
    1.65 +				SDL_SetError("FLAC__stream_decoder_init_stream() failed");
    1.66  			}
    1.67 +		} else {
    1.68 +			SDL_SetError("FLAC__stream_decoder_new() failed");
    1.69  		}
    1.70  
    1.71  		if (was_error) {