dynamic_flac.c
changeset 382 50501e45c57b
child 386 695494546b3c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dynamic_flac.c	Wed Feb 27 07:31:03 2008 +0000
     1.3 @@ -0,0 +1,176 @@
     1.4 +/*
     1.5 +    SDL_mixer:  An audio mixer library based on the SDL library
     1.6 +    Copyright (C) 1997-2004 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +
    1.25 +
    1.26 +    Implementation of the dynamic loading functionality for libFLAC.
    1.27 +    									~ Austen Dicken (admin@cvpcs.org)
    1.28 +*/
    1.29 +
    1.30 +#ifdef FLAC_MUSIC
    1.31 +
    1.32 +#include "SDL_loadso.h"
    1.33 +
    1.34 +#include "dynamic_flac.h"
    1.35 +
    1.36 +flac_loader flac = {
    1.37 +	0, NULL
    1.38 +};
    1.39 +
    1.40 +#ifdef FLAC_DYNAMIC
    1.41 +
    1.42 +int Mix_InitFLAC() {
    1.43 +	if ( flac.loaded == 0 ) {
    1.44 +		flac.handle = SDL_LoadObject(FLAC_DYNAMIC);
    1.45 +		if ( flac.handle == NULL ) {
    1.46 +			return -1;
    1.47 +		}
    1.48 +		flac.FLAC__stream_decoder_new =
    1.49 +			(FLAC__StreamDecoder *(*)())
    1.50 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_new");
    1.51 +		if ( flac.FLAC__stream_decoder_new == NULL ) {
    1.52 +			SDL_UnloadObject(flac.handle);
    1.53 +			return -1;
    1.54 +		}
    1.55 +		flac.FLAC__stream_decoder_delete =
    1.56 +			(void (*)(FLAC__StreamDecoder *))
    1.57 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_delete");
    1.58 +		if ( flac.FLAC__stream_decoder_delete == NULL ) {
    1.59 +			SDL_UnloadObject(flac.handle);
    1.60 +			return -1;
    1.61 +		}
    1.62 +		flac.FLAC__stream_decoder_init_stream =
    1.63 +			(FLAC__StreamDecoderInitStatus (*)(
    1.64 +						FLAC__StreamDecoder *,
    1.65 +						FLAC__StreamDecoderReadCallback,
    1.66 +						FLAC__StreamDecoderSeekCallback,
    1.67 +						FLAC__StreamDecoderTellCallback,
    1.68 +						FLAC__StreamDecoderLengthCallback,
    1.69 +						FLAC__StreamDecoderEofCallback,
    1.70 +						FLAC__StreamDecoderWriteCallback,
    1.71 +						FLAC__StreamDecoderMetadataCallback,
    1.72 +						FLAC__StreamDecoderErrorCallback,
    1.73 +						void *))
    1.74 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_init_stream");
    1.75 +		if ( flac.FLAC__stream_decoder_init_stream == NULL ) {
    1.76 +			SDL_UnloadObject(flac.handle);
    1.77 +			return -1;
    1.78 +		}
    1.79 +		flac.FLAC__stream_decoder_finish =
    1.80 +			(FLAC__bool (*)(FLAC__StreamDecoder *))
    1.81 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_finish");
    1.82 +		if ( flac.FLAC__stream_decoder_finish == NULL ) {
    1.83 +			SDL_UnloadObject(flac.handle);
    1.84 +			return -1;
    1.85 +		}
    1.86 +		flac.FLAC__stream_decoder_flush =
    1.87 +			(FLAC__bool (*)(FLAC__StreamDecoder *))
    1.88 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_flush");
    1.89 +		if ( flac.FLAC__stream_decoder_flush == NULL ) {
    1.90 +			SDL_UnloadObject(flac.handle);
    1.91 +			return -1;
    1.92 +		}
    1.93 +		flac.FLAC__stream_decoder_process_single =
    1.94 +			(FLAC__bool (*)(FLAC__StreamDecoder *))
    1.95 +			SDL_LoadFunction(flac.handle,
    1.96 +						"FLAC__stream_decoder_process_single");
    1.97 +		if ( flac.FLAC__stream_decoder_process_single == NULL ) {
    1.98 +			SDL_UnloadObject(flac.handle);
    1.99 +			return -1;
   1.100 +		}
   1.101 +		flac.FLAC__stream_decoder_process_until_end_of_metadata =
   1.102 +			(FLAC__bool (*)(FLAC__StreamDecoder *))
   1.103 +			SDL_LoadFunction(flac.handle,
   1.104 +						"FLAC__stream_decoder_process_until_end_of_metadata");
   1.105 +		if ( flac.FLAC__stream_decoder_process_until_end_of_metadata == NULL ) {
   1.106 +			SDL_UnloadObject(flac.handle);
   1.107 +			return -1;
   1.108 +		}
   1.109 +		flac.FLAC__stream_decoder_process_until_end_of_stream =
   1.110 +			(FLAC__bool (*)(FLAC__StreamDecoder *))
   1.111 +			SDL_LoadFunction(flac.handle,
   1.112 +						"FLAC__stream_decoder_process_until_end_of_stream");
   1.113 +		if ( flac.FLAC__stream_decoder_process_until_end_of_stream == NULL ) {
   1.114 +			SDL_UnloadObject(flac.handle);
   1.115 +			return -1;
   1.116 +		}
   1.117 +		flac.FLAC__stream_decoder_seek_absolute =
   1.118 +			(FLAC__bool (*)(FLAC__StreamDecoder *, FLAC__uint64))
   1.119 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_seek_absolute");
   1.120 +		if ( flac.FLAC__stream_decoder_seek_absolute == NULL ) {
   1.121 +			SDL_UnloadObject(flac.handle);
   1.122 +			return -1;
   1.123 +		}
   1.124 +		flac.FLAC__stream_decoder_get_state =
   1.125 +			(FLAC__StreamDecoderState (*)(const FLAC__StreamDecoder *decoder))
   1.126 +			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_get_state");
   1.127 +		if ( flac.FLAC__stream_decoder_get_state == NULL ) {
   1.128 +			SDL_UnloadObject(flac.handle);
   1.129 +			return -1;
   1.130 +		}
   1.131 +	}
   1.132 +	++flac.loaded;
   1.133 +
   1.134 +	return 0;
   1.135 +}
   1.136 +void Mix_QuitFLAC() {
   1.137 +	if ( flac.loaded == 0 ) {
   1.138 +		return;
   1.139 +	}
   1.140 +	if ( flac.loaded == 1 ) {
   1.141 +		SDL_UnloadObject(flac.handle);
   1.142 +	}
   1.143 +	--flac.loaded;
   1.144 +}
   1.145 +#else
   1.146 +int Mix_InitFLAC() {
   1.147 +	if ( flac.loaded == 0 ) {
   1.148 +		flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
   1.149 +		flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
   1.150 +		flac.FLAC__stream_decoder_init_stream =
   1.151 +							FLAC__stream_decoder_init_stream;
   1.152 +		flac.FLAC__stream_decoder_finish = FLAC__stream_decoder_finish;
   1.153 +		flac.FLAC__stream_decoder_flush = FLAC__stream_decoder_flush;
   1.154 +		flac.FLAC__stream_decoder_process_single =
   1.155 +							FLAC__stream_decoder_process_single;
   1.156 +		flac.FLAC__stream_decoder_process_until_end_of_metadata =
   1.157 +							FLAC__stream_decoder_process_until_end_of_metadata;
   1.158 +		flac.FLAC__stream_decoder_process_until_end_of_stream =
   1.159 +							FLAC__stream_decoder_process_until_end_of_stream;
   1.160 +		flac.FLAC__stream_decoder_seek_absolute =
   1.161 +							FLAC__stream_decoder_seek_absolute;
   1.162 +		flac.FLAC__stream_decoder_get_state =
   1.163 +							FLAC__stream_decoder_get_state;
   1.164 +	}
   1.165 +	++flac.loaded;
   1.166 +
   1.167 +	return 0;
   1.168 +}
   1.169 +void Mix_QuitFLAC() {
   1.170 +	if ( flac.loaded == 0 ) {
   1.171 +		return;
   1.172 +	}
   1.173 +	if ( flac.loaded == 1 ) {
   1.174 +	}
   1.175 +	--flac.loaded;
   1.176 +}
   1.177 +#endif // FLAC_DYNAMIC
   1.178 +
   1.179 +#endif // FLAC_MUSIC