dynamic_flac.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 14 Jan 2012 19:52:34 -0500
changeset 564 2aee47b6dc73
parent 518 8bc9b5fd2aae
child 601 05123263dab3
permissions -rw-r--r--
Fixed MOD playback on 64-bit Windows
slouken@382
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@518
     3
  Copyright (C) 1997-2012 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@518
    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@382
    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@382
    38
	if ( flac.loaded == 0 ) {
slouken@382
    39
		flac.handle = SDL_LoadObject(FLAC_DYNAMIC);
slouken@382
    40
		if ( flac.handle == NULL ) {
slouken@382
    41
			return -1;
slouken@382
    42
		}
slouken@382
    43
		flac.FLAC__stream_decoder_new =
slouken@382
    44
			(FLAC__StreamDecoder *(*)())
slouken@382
    45
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_new");
slouken@382
    46
		if ( flac.FLAC__stream_decoder_new == NULL ) {
slouken@382
    47
			SDL_UnloadObject(flac.handle);
slouken@382
    48
			return -1;
slouken@382
    49
		}
slouken@382
    50
		flac.FLAC__stream_decoder_delete =
slouken@382
    51
			(void (*)(FLAC__StreamDecoder *))
slouken@382
    52
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_delete");
slouken@382
    53
		if ( flac.FLAC__stream_decoder_delete == NULL ) {
slouken@382
    54
			SDL_UnloadObject(flac.handle);
slouken@382
    55
			return -1;
slouken@382
    56
		}
slouken@382
    57
		flac.FLAC__stream_decoder_init_stream =
slouken@382
    58
			(FLAC__StreamDecoderInitStatus (*)(
slouken@382
    59
						FLAC__StreamDecoder *,
slouken@382
    60
						FLAC__StreamDecoderReadCallback,
slouken@382
    61
						FLAC__StreamDecoderSeekCallback,
slouken@382
    62
						FLAC__StreamDecoderTellCallback,
slouken@382
    63
						FLAC__StreamDecoderLengthCallback,
slouken@382
    64
						FLAC__StreamDecoderEofCallback,
slouken@382
    65
						FLAC__StreamDecoderWriteCallback,
slouken@382
    66
						FLAC__StreamDecoderMetadataCallback,
slouken@382
    67
						FLAC__StreamDecoderErrorCallback,
slouken@382
    68
						void *))
slouken@382
    69
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_init_stream");
slouken@382
    70
		if ( flac.FLAC__stream_decoder_init_stream == NULL ) {
slouken@382
    71
			SDL_UnloadObject(flac.handle);
slouken@382
    72
			return -1;
slouken@382
    73
		}
slouken@382
    74
		flac.FLAC__stream_decoder_finish =
slouken@382
    75
			(FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@382
    76
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_finish");
slouken@382
    77
		if ( flac.FLAC__stream_decoder_finish == NULL ) {
slouken@382
    78
			SDL_UnloadObject(flac.handle);
slouken@382
    79
			return -1;
slouken@382
    80
		}
slouken@382
    81
		flac.FLAC__stream_decoder_flush =
slouken@382
    82
			(FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@382
    83
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_flush");
slouken@382
    84
		if ( flac.FLAC__stream_decoder_flush == NULL ) {
slouken@382
    85
			SDL_UnloadObject(flac.handle);
slouken@382
    86
			return -1;
slouken@382
    87
		}
slouken@382
    88
		flac.FLAC__stream_decoder_process_single =
slouken@382
    89
			(FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@382
    90
			SDL_LoadFunction(flac.handle,
slouken@382
    91
						"FLAC__stream_decoder_process_single");
slouken@382
    92
		if ( flac.FLAC__stream_decoder_process_single == NULL ) {
slouken@382
    93
			SDL_UnloadObject(flac.handle);
slouken@382
    94
			return -1;
slouken@382
    95
		}
slouken@382
    96
		flac.FLAC__stream_decoder_process_until_end_of_metadata =
slouken@382
    97
			(FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@382
    98
			SDL_LoadFunction(flac.handle,
slouken@382
    99
						"FLAC__stream_decoder_process_until_end_of_metadata");
slouken@382
   100
		if ( flac.FLAC__stream_decoder_process_until_end_of_metadata == NULL ) {
slouken@382
   101
			SDL_UnloadObject(flac.handle);
slouken@382
   102
			return -1;
slouken@382
   103
		}
slouken@382
   104
		flac.FLAC__stream_decoder_process_until_end_of_stream =
slouken@382
   105
			(FLAC__bool (*)(FLAC__StreamDecoder *))
slouken@382
   106
			SDL_LoadFunction(flac.handle,
slouken@382
   107
						"FLAC__stream_decoder_process_until_end_of_stream");
slouken@382
   108
		if ( flac.FLAC__stream_decoder_process_until_end_of_stream == NULL ) {
slouken@382
   109
			SDL_UnloadObject(flac.handle);
slouken@382
   110
			return -1;
slouken@382
   111
		}
slouken@382
   112
		flac.FLAC__stream_decoder_seek_absolute =
slouken@382
   113
			(FLAC__bool (*)(FLAC__StreamDecoder *, FLAC__uint64))
slouken@382
   114
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_seek_absolute");
slouken@382
   115
		if ( flac.FLAC__stream_decoder_seek_absolute == NULL ) {
slouken@382
   116
			SDL_UnloadObject(flac.handle);
slouken@382
   117
			return -1;
slouken@382
   118
		}
slouken@382
   119
		flac.FLAC__stream_decoder_get_state =
slouken@382
   120
			(FLAC__StreamDecoderState (*)(const FLAC__StreamDecoder *decoder))
slouken@382
   121
			SDL_LoadFunction(flac.handle, "FLAC__stream_decoder_get_state");
slouken@382
   122
		if ( flac.FLAC__stream_decoder_get_state == NULL ) {
slouken@382
   123
			SDL_UnloadObject(flac.handle);
slouken@382
   124
			return -1;
slouken@382
   125
		}
slouken@382
   126
	}
slouken@382
   127
	++flac.loaded;
slouken@382
   128
slouken@382
   129
	return 0;
slouken@382
   130
}
slouken@470
   131
void Mix_QuitFLAC()
slouken@470
   132
{
slouken@382
   133
	if ( flac.loaded == 0 ) {
slouken@382
   134
		return;
slouken@382
   135
	}
slouken@382
   136
	if ( flac.loaded == 1 ) {
slouken@382
   137
		SDL_UnloadObject(flac.handle);
slouken@382
   138
	}
slouken@382
   139
	--flac.loaded;
slouken@382
   140
}
slouken@382
   141
#else
slouken@470
   142
int Mix_InitFLAC()
slouken@470
   143
{
slouken@382
   144
	if ( flac.loaded == 0 ) {
slouken@382
   145
		flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
slouken@382
   146
		flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
slouken@382
   147
		flac.FLAC__stream_decoder_init_stream =
slouken@382
   148
							FLAC__stream_decoder_init_stream;
slouken@382
   149
		flac.FLAC__stream_decoder_finish = FLAC__stream_decoder_finish;
slouken@382
   150
		flac.FLAC__stream_decoder_flush = FLAC__stream_decoder_flush;
slouken@382
   151
		flac.FLAC__stream_decoder_process_single =
slouken@382
   152
							FLAC__stream_decoder_process_single;
slouken@382
   153
		flac.FLAC__stream_decoder_process_until_end_of_metadata =
slouken@382
   154
							FLAC__stream_decoder_process_until_end_of_metadata;
slouken@382
   155
		flac.FLAC__stream_decoder_process_until_end_of_stream =
slouken@382
   156
							FLAC__stream_decoder_process_until_end_of_stream;
slouken@382
   157
		flac.FLAC__stream_decoder_seek_absolute =
slouken@382
   158
							FLAC__stream_decoder_seek_absolute;
slouken@382
   159
		flac.FLAC__stream_decoder_get_state =
slouken@382
   160
							FLAC__stream_decoder_get_state;
slouken@382
   161
	}
slouken@382
   162
	++flac.loaded;
slouken@382
   163
slouken@382
   164
	return 0;
slouken@382
   165
}
slouken@470
   166
void Mix_QuitFLAC()
slouken@470
   167
{
slouken@382
   168
	if ( flac.loaded == 0 ) {
slouken@382
   169
		return;
slouken@382
   170
	}
slouken@382
   171
	if ( flac.loaded == 1 ) {
slouken@382
   172
	}
slouken@382
   173
	--flac.loaded;
slouken@382
   174
}
slouken@470
   175
#endif /* FLAC_DYNAMIC */
slouken@382
   176
slouken@470
   177
#endif /* FLAC_MUSIC */