dynamic_flac.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Nov 2009 18:40:07 +0000
changeset 474 a2c238c0c4b2
parent 472 463ba3222193
child 518 8bc9b5fd2aae
permissions -rw-r--r--
Don't break binary compatibility!
     1 /*
     2     SDL_mixer:  An audio mixer library based on the SDL library
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 
    22 
    23     Implementation of the dynamic loading functionality for libFLAC.
    24     									~ Austen Dicken (admin@cvpcs.org)
    25 */
    26 
    27 #ifdef FLAC_MUSIC
    28 
    29 #include "SDL_loadso.h"
    30 
    31 #include "dynamic_flac.h"
    32 
    33 flac_loader flac = {
    34 	0, NULL
    35 };
    36 
    37 #ifdef FLAC_DYNAMIC
    38 int Mix_InitFLAC()
    39 {
    40 	if ( flac.loaded == 0 ) {
    41 		flac.handle = SDL_LoadObject(FLAC_DYNAMIC);
    42 		if ( flac.handle == NULL ) {
    43 			return -1;
    44 		}
    45 		flac.FLAC__stream_decoder_new =
    46 			(FLAC__StreamDecoder *(*)())
    47 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_new");
    48 		if ( flac.FLAC__stream_decoder_new == NULL ) {
    49 			SDL_UnloadObject(flac.handle);
    50 			return -1;
    51 		}
    52 		flac.FLAC__stream_decoder_delete =
    53 			(void (*)(FLAC__StreamDecoder *))
    54 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_delete");
    55 		if ( flac.FLAC__stream_decoder_delete == NULL ) {
    56 			SDL_UnloadObject(flac.handle);
    57 			return -1;
    58 		}
    59 		flac.FLAC__stream_decoder_init_stream =
    60 			(FLAC__StreamDecoderInitStatus (*)(
    61 						FLAC__StreamDecoder *,
    62 						FLAC__StreamDecoderReadCallback,
    63 						FLAC__StreamDecoderSeekCallback,
    64 						FLAC__StreamDecoderTellCallback,
    65 						FLAC__StreamDecoderLengthCallback,
    66 						FLAC__StreamDecoderEofCallback,
    67 						FLAC__StreamDecoderWriteCallback,
    68 						FLAC__StreamDecoderMetadataCallback,
    69 						FLAC__StreamDecoderErrorCallback,
    70 						void *))
    71 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_init_stream");
    72 		if ( flac.FLAC__stream_decoder_init_stream == NULL ) {
    73 			SDL_UnloadObject(flac.handle);
    74 			return -1;
    75 		}
    76 		flac.FLAC__stream_decoder_finish =
    77 			(FLAC__bool (*)(FLAC__StreamDecoder *))
    78 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_finish");
    79 		if ( flac.FLAC__stream_decoder_finish == NULL ) {
    80 			SDL_UnloadObject(flac.handle);
    81 			return -1;
    82 		}
    83 		flac.FLAC__stream_decoder_flush =
    84 			(FLAC__bool (*)(FLAC__StreamDecoder *))
    85 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_flush");
    86 		if ( flac.FLAC__stream_decoder_flush == NULL ) {
    87 			SDL_UnloadObject(flac.handle);
    88 			return -1;
    89 		}
    90 		flac.FLAC__stream_decoder_process_single =
    91 			(FLAC__bool (*)(FLAC__StreamDecoder *))
    92 			SDL_LoadFunction(flac.handle,
    93 						"FLAC__stream_decoder_process_single");
    94 		if ( flac.FLAC__stream_decoder_process_single == NULL ) {
    95 			SDL_UnloadObject(flac.handle);
    96 			return -1;
    97 		}
    98 		flac.FLAC__stream_decoder_process_until_end_of_metadata =
    99 			(FLAC__bool (*)(FLAC__StreamDecoder *))
   100 			SDL_LoadFunction(flac.handle,
   101 						"FLAC__stream_decoder_process_until_end_of_metadata");
   102 		if ( flac.FLAC__stream_decoder_process_until_end_of_metadata == NULL ) {
   103 			SDL_UnloadObject(flac.handle);
   104 			return -1;
   105 		}
   106 		flac.FLAC__stream_decoder_process_until_end_of_stream =
   107 			(FLAC__bool (*)(FLAC__StreamDecoder *))
   108 			SDL_LoadFunction(flac.handle,
   109 						"FLAC__stream_decoder_process_until_end_of_stream");
   110 		if ( flac.FLAC__stream_decoder_process_until_end_of_stream == NULL ) {
   111 			SDL_UnloadObject(flac.handle);
   112 			return -1;
   113 		}
   114 		flac.FLAC__stream_decoder_seek_absolute =
   115 			(FLAC__bool (*)(FLAC__StreamDecoder *, FLAC__uint64))
   116 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_seek_absolute");
   117 		if ( flac.FLAC__stream_decoder_seek_absolute == NULL ) {
   118 			SDL_UnloadObject(flac.handle);
   119 			return -1;
   120 		}
   121 		flac.FLAC__stream_decoder_get_state =
   122 			(FLAC__StreamDecoderState (*)(const FLAC__StreamDecoder *decoder))
   123 			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_get_state");
   124 		if ( flac.FLAC__stream_decoder_get_state == NULL ) {
   125 			SDL_UnloadObject(flac.handle);
   126 			return -1;
   127 		}
   128 	}
   129 	++flac.loaded;
   130 
   131 	return 0;
   132 }
   133 void Mix_QuitFLAC()
   134 {
   135 	if ( flac.loaded == 0 ) {
   136 		return;
   137 	}
   138 	if ( flac.loaded == 1 ) {
   139 		SDL_UnloadObject(flac.handle);
   140 	}
   141 	--flac.loaded;
   142 }
   143 #else
   144 int Mix_InitFLAC()
   145 {
   146 	if ( flac.loaded == 0 ) {
   147 		flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
   148 		flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
   149 		flac.FLAC__stream_decoder_init_stream =
   150 							FLAC__stream_decoder_init_stream;
   151 		flac.FLAC__stream_decoder_finish = FLAC__stream_decoder_finish;
   152 		flac.FLAC__stream_decoder_flush = FLAC__stream_decoder_flush;
   153 		flac.FLAC__stream_decoder_process_single =
   154 							FLAC__stream_decoder_process_single;
   155 		flac.FLAC__stream_decoder_process_until_end_of_metadata =
   156 							FLAC__stream_decoder_process_until_end_of_metadata;
   157 		flac.FLAC__stream_decoder_process_until_end_of_stream =
   158 							FLAC__stream_decoder_process_until_end_of_stream;
   159 		flac.FLAC__stream_decoder_seek_absolute =
   160 							FLAC__stream_decoder_seek_absolute;
   161 		flac.FLAC__stream_decoder_get_state =
   162 							FLAC__stream_decoder_get_state;
   163 	}
   164 	++flac.loaded;
   165 
   166 	return 0;
   167 }
   168 void Mix_QuitFLAC()
   169 {
   170 	if ( flac.loaded == 0 ) {
   171 		return;
   172 	}
   173 	if ( flac.loaded == 1 ) {
   174 	}
   175 	--flac.loaded;
   176 }
   177 #endif /* FLAC_DYNAMIC */
   178 
   179 #endif /* FLAC_MUSIC */