dynamic_mp3.c
author Ozkan Sezer <sezeroz@gmail.com>
Thu, 11 Oct 2018 11:50:10 +0300
branchSDL-1.2
changeset 902 6c862e733898
parent 542 3de4970b36d4
child 908 6b860486ce24
permissions -rw-r--r--
remove smpeg support completely and backport libmpg123 support instead.
slouken@314
     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@314
     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@314
     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@314
    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@314
    20
*/
slouken@314
    21
slouken@314
    22
#ifdef MP3_MUSIC
slouken@314
    23
slouken@314
    24
#include "SDL_loadso.h"
slouken@314
    25
slouken@314
    26
#include "dynamic_mp3.h"
slouken@314
    27
sezeroz@902
    28
mpg123_loader mpg123 = {
slouken@314
    29
	0, NULL
slouken@314
    30
};
slouken@314
    31
sezeroz@902
    32
#ifdef MPG123_DYNAMIC
sezeroz@902
    33
#define FUNCTION_LOADER(FUNC, SIG) \
sezeroz@902
    34
	mpg123.FUNC = (SIG) SDL_LoadFunction(mpg123.handle, #FUNC); \
sezeroz@902
    35
	if (mpg123.FUNC == NULL) { SDL_UnloadObject(mpg123.handle); return -1; }
sezeroz@902
    36
#else
sezeroz@902
    37
#define FUNCTION_LOADER(FUNC, SIG) \
sezeroz@902
    38
	mpg123.FUNC = FUNC;
sezeroz@902
    39
#endif
sezeroz@902
    40
sezeroz@902
    41
int Mix_InitMP3(void)
slouken@314
    42
{
sezeroz@902
    43
	if (mpg123.loaded == 0) {
sezeroz@902
    44
#ifdef MPG123_DYNAMIC
sezeroz@902
    45
		mpg123.handle = SDL_LoadObject(MPG123_DYNAMIC);
sezeroz@902
    46
		if (mpg123.handle == NULL) {
slouken@314
    47
			return -1;
slouken@314
    48
		}
sezeroz@902
    49
#endif
sezeroz@902
    50
		FUNCTION_LOADER(mpg123_close, int (*)(mpg123_handle *mh))
sezeroz@902
    51
		FUNCTION_LOADER(mpg123_delete, void (*)(mpg123_handle *mh))
sezeroz@902
    52
		FUNCTION_LOADER(mpg123_exit, void (*)(void))
sezeroz@902
    53
		FUNCTION_LOADER(mpg123_format, int (*)( mpg123_handle *mh, long rate, int channels, int encodings ))
sezeroz@902
    54
		FUNCTION_LOADER(mpg123_format_none, int (*)(mpg123_handle *mh))
sezeroz@902
    55
		FUNCTION_LOADER(mpg123_getformat, int (*)( mpg123_handle *mh, long *rate, int *channels, int *encoding ))
sezeroz@902
    56
		FUNCTION_LOADER(mpg123_init, int (*)(void))
sezeroz@902
    57
		FUNCTION_LOADER(mpg123_new, mpg123_handle *(*)(const char* decoder, int *error))
sezeroz@902
    58
		FUNCTION_LOADER(mpg123_open_handle, int (*)(mpg123_handle *mh, void *iohandle))
sezeroz@902
    59
		FUNCTION_LOADER(mpg123_plain_strerror, const char* (*)(int errcode))
sezeroz@902
    60
		FUNCTION_LOADER(mpg123_rates, void (*)(const long **list, size_t *number));
sezeroz@902
    61
		FUNCTION_LOADER(mpg123_read, int (*)(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done ))
sezeroz@902
    62
		FUNCTION_LOADER(mpg123_replace_reader_handle, int (*)( mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), off_t (*r_lseek)(void *, off_t, int), void (*cleanup)(void*) ))
sezeroz@902
    63
		FUNCTION_LOADER(mpg123_seek, off_t (*)( mpg123_handle *mh, off_t sampleoff, int whence ))
sezeroz@902
    64
		FUNCTION_LOADER(mpg123_strerror, const char* (*)(mpg123_handle *mh))
sezeroz@902
    65
		if (mpg123.mpg123_init() != MPG123_OK) {
slouken@314
    66
			return -1;
slouken@314
    67
		}
slouken@314
    68
	}
sezeroz@902
    69
	++mpg123.loaded;
slouken@314
    70
slouken@314
    71
	return 0;
slouken@314
    72
}
sezeroz@902
    73
sezeroz@902
    74
void Mix_QuitMP3(void)
slouken@314
    75
{
sezeroz@902
    76
	if (mpg123.loaded == 0) {
slouken@314
    77
		return;
slouken@314
    78
	}
sezeroz@902
    79
	if (mpg123.loaded == 1) {
sezeroz@902
    80
		mpg123.mpg123_exit();
sezeroz@902
    81
#ifdef MPG123_DYNAMIC
sezeroz@902
    82
		SDL_UnloadObject(mpg123.handle);
sezeroz@902
    83
#endif
slouken@314
    84
	}
sezeroz@902
    85
	--mpg123.loaded;
slouken@314
    86
}
slouken@314
    87
slouken@314
    88
#endif /* MP3_MUSIC */