dynamic_flac.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 01 Jun 2013 22:30:04 -0700
changeset 627 438fb12df34f
parent 617 87116a42526e
child 629 87c536d57d92
permissions -rw-r--r--
Updated iOS project to include OGG support directly
slouken@382
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@601
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@382
     4
slouken@518
     5
  This software is provided 'as-is', without any express or implied
slouken@518
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@518
     7
  arising from the use of this software.
slouken@382
     8
slouken@518
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@518
    10
  including commercial applications, and to alter it and redistribute it
slouken@518
    11
  freely, subject to the following restrictions:
slouken@382
    12
slouken@518
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@518
    14
     claim that you wrote the original software. If you use this software
slouken@518
    15
     in a product, an acknowledgment in the product documentation would be
slouken@518
    16
     appreciated but is not required.
slouken@518
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@518
    18
     misrepresented as being the original software.
slouken@518
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@382
    20
slouken@518
    21
  Implementation of the dynamic loading functionality for libFLAC.
slouken@617
    22
    ~ Austen Dicken (admin@cvpcs.org)
slouken@382
    23
*/
slouken@382
    24
slouken@382
    25
#ifdef FLAC_MUSIC
slouken@382
    26
slouken@382
    27
#include "SDL_loadso.h"
slouken@382
    28
slouken@382
    29
#include "dynamic_flac.h"
slouken@382
    30
slouken@382
    31
flac_loader flac = {
slouken@617
    32
    0, NULL
slouken@382
    33
};
slouken@382
    34
slouken@382
    35
#ifdef FLAC_DYNAMIC
slouken@470
    36
int Mix_InitFLAC()
slouken@470
    37
{
slouken@617
    38
    if ( flac.loaded == 0 ) {
slouken@617
    39
        flac.handle = SDL_LoadObject(FLAC_DYNAMIC);
slouken@617
    40
        if ( flac.handle == NULL ) {
slouken@617
    41
            return -1;
slouken@617
    42
        }
slouken@617
    43
        flac.FLAC__stream_decoder_new =
slouken@617
    44
            (FLAC__StreamDecoder *(*)())
slouken@617
    45
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_new");
slouken@617
    46
        if ( flac.FLAC__stream_decoder_new == NULL ) {
slouken@617
    47
            SDL_UnloadObject(flac.handle);
slouken@617
    48
            return -1;
slouken@617
    49
        }
slouken@617
    50
        flac.FLAC__stream_decoder_delete =
slouken@617
    51
            (void (*)(FLAC__StreamDecoder *))
slouken@617
    52
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_delete");
slouken@617
    53
        if ( flac.FLAC__stream_decoder_delete == NULL ) {
slouken@617
    54
            SDL_UnloadObject(flac.handle);
slouken@617
    55
            return -1;
slouken@617
    56
        }
slouken@617
    57
        flac.FLAC__stream_decoder_init_stream =
slouken@617
    58
            (FLAC__StreamDecoderInitStatus (*)(
slouken@617
    59
                        FLAC__StreamDecoder *,
slouken@617
    60
                        FLAC__StreamDecoderReadCallback,
slouken@617
    61
                        FLAC__StreamDecoderSeekCallback,
slouken@617
    62
                        FLAC__StreamDecoderTellCallback,
slouken@617
    63
                        FLAC__StreamDecoderLengthCallback,
slouken@617
    64
                        FLAC__StreamDecoderEofCallback,
slouken@617
    65
                        FLAC__StreamDecoderWriteCallback,
slouken@617
    66
                        FLAC__StreamDecoderMetadataCallback,
slouken@617
    67
                        FLAC__StreamDecoderErrorCallback,
slouken@617
    68
                        void *))
slouken@617
    69
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_init_stream");
slouken@617
    70
        if ( flac.FLAC__stream_decoder_init_stream == NULL ) {
slouken@617
    71
            SDL_UnloadObject(flac.handle);
slouken@617
    72
            return -1;
slouken@617
    73
        }
slouken@617
    74
        flac.FLAC__stream_decoder_finish =
slouken@617
    75
            (FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@617
    76
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_finish");
slouken@617
    77
        if ( flac.FLAC__stream_decoder_finish == NULL ) {
slouken@617
    78
            SDL_UnloadObject(flac.handle);
slouken@617
    79
            return -1;
slouken@617
    80
        }
slouken@617
    81
        flac.FLAC__stream_decoder_flush =
slouken@617
    82
            (FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@617
    83
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_flush");
slouken@617
    84
        if ( flac.FLAC__stream_decoder_flush == NULL ) {
slouken@617
    85
            SDL_UnloadObject(flac.handle);
slouken@617
    86
            return -1;
slouken@617
    87
        }
slouken@617
    88
        flac.FLAC__stream_decoder_process_single =
slouken@617
    89
            (FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@617
    90
            SDL_LoadFunction(flac.handle,
slouken@617
    91
                        "FLAC__stream_decoder_process_single");
slouken@617
    92
        if ( flac.FLAC__stream_decoder_process_single == NULL ) {
slouken@617
    93
            SDL_UnloadObject(flac.handle);
slouken@617
    94
            return -1;
slouken@617
    95
        }
slouken@617
    96
        flac.FLAC__stream_decoder_process_until_end_of_metadata =
slouken@617
    97
            (FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@617
    98
            SDL_LoadFunction(flac.handle,
slouken@617
    99
                        "FLAC__stream_decoder_process_until_end_of_metadata");
slouken@617
   100
        if ( flac.FLAC__stream_decoder_process_until_end_of_metadata == NULL ) {
slouken@617
   101
            SDL_UnloadObject(flac.handle);
slouken@617
   102
            return -1;
slouken@617
   103
        }
slouken@617
   104
        flac.FLAC__stream_decoder_process_until_end_of_stream =
slouken@617
   105
            (FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@617
   106
            SDL_LoadFunction(flac.handle,
slouken@617
   107
                        "FLAC__stream_decoder_process_until_end_of_stream");
slouken@617
   108
        if ( flac.FLAC__stream_decoder_process_until_end_of_stream == NULL ) {
slouken@617
   109
            SDL_UnloadObject(flac.handle);
slouken@617
   110
            return -1;
slouken@617
   111
        }
slouken@617
   112
        flac.FLAC__stream_decoder_seek_absolute =
slouken@617
   113
            (FLAC__bool (*)(FLAC__StreamDecoder *, FLAC__uint64))
slouken@617
   114
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_seek_absolute");
slouken@617
   115
        if ( flac.FLAC__stream_decoder_seek_absolute == NULL ) {
slouken@617
   116
            SDL_UnloadObject(flac.handle);
slouken@617
   117
            return -1;
slouken@617
   118
        }
slouken@617
   119
        flac.FLAC__stream_decoder_get_state =
slouken@617
   120
            (FLAC__StreamDecoderState (*)(const FLAC__StreamDecoder *decoder))
slouken@617
   121
            SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_get_state");
slouken@617
   122
        if ( flac.FLAC__stream_decoder_get_state == NULL ) {
slouken@617
   123
            SDL_UnloadObject(flac.handle);
slouken@617
   124
            return -1;
slouken@617
   125
        }
slouken@617
   126
    }
slouken@617
   127
    ++flac.loaded;
slouken@382
   128
slouken@617
   129
    return 0;
slouken@382
   130
}
slouken@470
   131
void Mix_QuitFLAC()
slouken@470
   132
{
slouken@617
   133
    if ( flac.loaded == 0 ) {
slouken@617
   134
        return;
slouken@617
   135
    }
slouken@617
   136
    if ( flac.loaded == 1 ) {
slouken@617
   137
        SDL_UnloadObject(flac.handle);
slouken@617
   138
    }
slouken@617
   139
    --flac.loaded;
slouken@382
   140
}
slouken@382
   141
#else
slouken@470
   142
int Mix_InitFLAC()
slouken@470
   143
{
slouken@617
   144
    if ( flac.loaded == 0 ) {
slouken@617
   145
        flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
slouken@617
   146
        flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
slouken@617
   147
        flac.FLAC__stream_decoder_init_stream =
slouken@617
   148
                            FLAC__stream_decoder_init_stream;
slouken@617
   149
        flac.FLAC__stream_decoder_finish = FLAC__stream_decoder_finish;
slouken@617
   150
        flac.FLAC__stream_decoder_flush = FLAC__stream_decoder_flush;
slouken@617
   151
        flac.FLAC__stream_decoder_process_single =
slouken@617
   152
                            FLAC__stream_decoder_process_single;
slouken@617
   153
        flac.FLAC__stream_decoder_process_until_end_of_metadata =
slouken@617
   154
                            FLAC__stream_decoder_process_until_end_of_metadata;
slouken@617
   155
        flac.FLAC__stream_decoder_process_until_end_of_stream =
slouken@617
   156
                            FLAC__stream_decoder_process_until_end_of_stream;
slouken@617
   157
        flac.FLAC__stream_decoder_seek_absolute =
slouken@617
   158
                            FLAC__stream_decoder_seek_absolute;
slouken@617
   159
        flac.FLAC__stream_decoder_get_state =
slouken@617
   160
                            FLAC__stream_decoder_get_state;
slouken@617
   161
    }
slouken@617
   162
    ++flac.loaded;
slouken@382
   163
slouken@617
   164
    return 0;
slouken@382
   165
}
slouken@470
   166
void Mix_QuitFLAC()
slouken@470
   167
{
slouken@617
   168
    if ( flac.loaded == 0 ) {
slouken@617
   169
        return;
slouken@617
   170
    }
slouken@617
   171
    if ( flac.loaded == 1 ) {
slouken@617
   172
    }
slouken@617
   173
    --flac.loaded;
slouken@382
   174
}
slouken@470
   175
#endif /* FLAC_DYNAMIC */
slouken@382
   176
slouken@470
   177
#endif /* FLAC_MUSIC */