dynamic_flac.c
changeset 777 92882ef2ab81
parent 776 07b8e286bc03
child 778 05c93f7af403
     1.1 --- a/dynamic_flac.c	Mon Oct 16 02:16:47 2017 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,187 +0,0 @@
     1.4 -/*
     1.5 -  SDL_mixer:  An audio mixer library based on the SDL library
     1.6 -  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     1.7 -
     1.8 -  This software is provided 'as-is', without any express or implied
     1.9 -  warranty.  In no event will the authors be held liable for any damages
    1.10 -  arising from the use of this software.
    1.11 -
    1.12 -  Permission is granted to anyone to use this software for any purpose,
    1.13 -  including commercial applications, and to alter it and redistribute it
    1.14 -  freely, subject to the following restrictions:
    1.15 -
    1.16 -  1. The origin of this software must not be misrepresented; you must not
    1.17 -     claim that you wrote the original software. If you use this software
    1.18 -     in a product, an acknowledgment in the product documentation would be
    1.19 -     appreciated but is not required.
    1.20 -  2. Altered source versions must be plainly marked as such, and must not be
    1.21 -     misrepresented as being the original software.
    1.22 -  3. This notice may not be removed or altered from any source distribution.
    1.23 -
    1.24 -  Implementation of the dynamic loading functionality for libFLAC.
    1.25 -    ~ Austen Dicken (admin@cvpcs.org)
    1.26 -*/
    1.27 -
    1.28 -#ifdef FLAC_MUSIC
    1.29 -
    1.30 -#include "SDL_loadso.h"
    1.31 -#include "SDL_mixer.h"
    1.32 -#include "dynamic_flac.h"
    1.33 -
    1.34 -flac_loader flac = {
    1.35 -    0, NULL
    1.36 -};
    1.37 -
    1.38 -#ifdef FLAC_DYNAMIC
    1.39 -int Mix_InitFLAC()
    1.40 -{
    1.41 -    if ( flac.loaded == 0 ) {
    1.42 -        flac.handle = SDL_LoadObject(FLAC_DYNAMIC);
    1.43 -        if ( flac.handle == NULL ) {
    1.44 -            return -1;
    1.45 -        }
    1.46 -        flac.FLAC__stream_decoder_new =
    1.47 -            (FLAC__StreamDecoder *(*)())
    1.48 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_new");
    1.49 -        if ( flac.FLAC__stream_decoder_new == NULL ) {
    1.50 -            SDL_UnloadObject(flac.handle);
    1.51 -            return -1;
    1.52 -        }
    1.53 -        flac.FLAC__stream_decoder_delete =
    1.54 -            (void (*)(FLAC__StreamDecoder *))
    1.55 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_delete");
    1.56 -        if ( flac.FLAC__stream_decoder_delete == NULL ) {
    1.57 -            SDL_UnloadObject(flac.handle);
    1.58 -            return -1;
    1.59 -        }
    1.60 -        flac.FLAC__stream_decoder_init_stream =
    1.61 -            (FLAC__StreamDecoderInitStatus (*)(
    1.62 -                        FLAC__StreamDecoder *,
    1.63 -                        FLAC__StreamDecoderReadCallback,
    1.64 -                        FLAC__StreamDecoderSeekCallback,
    1.65 -                        FLAC__StreamDecoderTellCallback,
    1.66 -                        FLAC__StreamDecoderLengthCallback,
    1.67 -                        FLAC__StreamDecoderEofCallback,
    1.68 -                        FLAC__StreamDecoderWriteCallback,
    1.69 -                        FLAC__StreamDecoderMetadataCallback,
    1.70 -                        FLAC__StreamDecoderErrorCallback,
    1.71 -                        void *))
    1.72 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_init_stream");
    1.73 -        if ( flac.FLAC__stream_decoder_init_stream == NULL ) {
    1.74 -            SDL_UnloadObject(flac.handle);
    1.75 -            return -1;
    1.76 -        }
    1.77 -        flac.FLAC__stream_decoder_finish =
    1.78 -            (FLAC__bool (*)(FLAC__StreamDecoder *))
    1.79 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_finish");
    1.80 -        if ( flac.FLAC__stream_decoder_finish == NULL ) {
    1.81 -            SDL_UnloadObject(flac.handle);
    1.82 -            return -1;
    1.83 -        }
    1.84 -        flac.FLAC__stream_decoder_flush =
    1.85 -            (FLAC__bool (*)(FLAC__StreamDecoder *))
    1.86 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_flush");
    1.87 -        if ( flac.FLAC__stream_decoder_flush == NULL ) {
    1.88 -            SDL_UnloadObject(flac.handle);
    1.89 -            return -1;
    1.90 -        }
    1.91 -        flac.FLAC__stream_decoder_process_single =
    1.92 -            (FLAC__bool (*)(FLAC__StreamDecoder *))
    1.93 -            SDL_LoadFunction(flac.handle,
    1.94 -                        "FLAC__stream_decoder_process_single");
    1.95 -        if ( flac.FLAC__stream_decoder_process_single == NULL ) {
    1.96 -            SDL_UnloadObject(flac.handle);
    1.97 -            return -1;
    1.98 -        }
    1.99 -        flac.FLAC__stream_decoder_process_until_end_of_metadata =
   1.100 -            (FLAC__bool (*)(FLAC__StreamDecoder *))
   1.101 -            SDL_LoadFunction(flac.handle,
   1.102 -                        "FLAC__stream_decoder_process_until_end_of_metadata");
   1.103 -        if ( flac.FLAC__stream_decoder_process_until_end_of_metadata == NULL ) {
   1.104 -            SDL_UnloadObject(flac.handle);
   1.105 -            return -1;
   1.106 -        }
   1.107 -        flac.FLAC__stream_decoder_process_until_end_of_stream =
   1.108 -            (FLAC__bool (*)(FLAC__StreamDecoder *))
   1.109 -            SDL_LoadFunction(flac.handle,
   1.110 -                        "FLAC__stream_decoder_process_until_end_of_stream");
   1.111 -        if ( flac.FLAC__stream_decoder_process_until_end_of_stream == NULL ) {
   1.112 -            SDL_UnloadObject(flac.handle);
   1.113 -            return -1;
   1.114 -        }
   1.115 -        flac.FLAC__stream_decoder_seek_absolute =
   1.116 -            (FLAC__bool (*)(FLAC__StreamDecoder *, FLAC__uint64))
   1.117 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_seek_absolute");
   1.118 -        if ( flac.FLAC__stream_decoder_seek_absolute == NULL ) {
   1.119 -            SDL_UnloadObject(flac.handle);
   1.120 -            return -1;
   1.121 -        }
   1.122 -        flac.FLAC__stream_decoder_get_state =
   1.123 -            (FLAC__StreamDecoderState (*)(const FLAC__StreamDecoder *decoder))
   1.124 -            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_get_state");
   1.125 -        if ( flac.FLAC__stream_decoder_get_state == NULL ) {
   1.126 -            SDL_UnloadObject(flac.handle);
   1.127 -            return -1;
   1.128 -        }
   1.129 -    }
   1.130 -    ++flac.loaded;
   1.131 -
   1.132 -    return 0;
   1.133 -}
   1.134 -void Mix_QuitFLAC()
   1.135 -{
   1.136 -    if ( flac.loaded == 0 ) {
   1.137 -        return;
   1.138 -    }
   1.139 -    if ( flac.loaded == 1 ) {
   1.140 -        SDL_UnloadObject(flac.handle);
   1.141 -    }
   1.142 -    --flac.loaded;
   1.143 -}
   1.144 -#else
   1.145 -int Mix_InitFLAC()
   1.146 -{
   1.147 -    if ( flac.loaded == 0 ) {
   1.148 -#ifdef __MACOSX__
   1.149 -        extern FLAC__StreamDecoder *FLAC__stream_decoder_new(void) __attribute__((weak_import));
   1.150 -        if ( FLAC__stream_decoder_new == NULL )
   1.151 -        {
   1.152 -            /* Missing weakly linked framework */
   1.153 -            Mix_SetError("Missing FLAC.framework");
   1.154 -            return -1;
   1.155 -        }
   1.156 -#endif // __MACOSX__
   1.157 -
   1.158 -        flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
   1.159 -        flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
   1.160 -        flac.FLAC__stream_decoder_init_stream =
   1.161 -                            FLAC__stream_decoder_init_stream;
   1.162 -        flac.FLAC__stream_decoder_finish = FLAC__stream_decoder_finish;
   1.163 -        flac.FLAC__stream_decoder_flush = FLAC__stream_decoder_flush;
   1.164 -        flac.FLAC__stream_decoder_process_single =
   1.165 -                            FLAC__stream_decoder_process_single;
   1.166 -        flac.FLAC__stream_decoder_process_until_end_of_metadata =
   1.167 -                            FLAC__stream_decoder_process_until_end_of_metadata;
   1.168 -        flac.FLAC__stream_decoder_process_until_end_of_stream =
   1.169 -                            FLAC__stream_decoder_process_until_end_of_stream;
   1.170 -        flac.FLAC__stream_decoder_seek_absolute =
   1.171 -                            FLAC__stream_decoder_seek_absolute;
   1.172 -        flac.FLAC__stream_decoder_get_state =
   1.173 -                            FLAC__stream_decoder_get_state;
   1.174 -    }
   1.175 -    ++flac.loaded;
   1.176 -
   1.177 -    return 0;
   1.178 -}
   1.179 -void Mix_QuitFLAC()
   1.180 -{
   1.181 -    if ( flac.loaded == 0 ) {
   1.182 -        return;
   1.183 -    }
   1.184 -    if ( flac.loaded == 1 ) {
   1.185 -    }
   1.186 -    --flac.loaded;
   1.187 -}
   1.188 -#endif /* FLAC_DYNAMIC */
   1.189 -
   1.190 -#endif /* FLAC_MUSIC */