dynamic_ogg.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 28 Jan 2012 13:15:19 -0500
changeset 580 5d5483acd03d
parent 518 8bc9b5fd2aae
child 601 05123263dab3
child 894 77d5b8c518e7
permissions -rw-r--r--
Updated framework project for SDL2
slouken@312
     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@312
     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@312
     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@312
    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@312
    20
*/
slouken@312
    21
slouken@312
    22
#ifdef OGG_MUSIC
slouken@312
    23
slouken@312
    24
#include "SDL_loadso.h"
slouken@312
    25
slouken@312
    26
#include "dynamic_ogg.h"
slouken@312
    27
slouken@312
    28
vorbis_loader vorbis = {
slouken@312
    29
	0, NULL
slouken@312
    30
};
slouken@312
    31
slouken@312
    32
#ifdef OGG_DYNAMIC
slouken@312
    33
int Mix_InitOgg()
slouken@312
    34
{
slouken@312
    35
	if ( vorbis.loaded == 0 ) {
slouken@312
    36
		vorbis.handle = SDL_LoadObject(OGG_DYNAMIC);
slouken@312
    37
		if ( vorbis.handle == NULL ) {
slouken@312
    38
			return -1;
slouken@312
    39
		}
slouken@312
    40
		vorbis.ov_clear =
slouken@312
    41
			(int (*)(OggVorbis_File *))
slouken@312
    42
			SDL_LoadFunction(vorbis.handle, "ov_clear");
slouken@312
    43
		if ( vorbis.ov_clear == NULL ) {
slouken@312
    44
			SDL_UnloadObject(vorbis.handle);
slouken@312
    45
			return -1;
slouken@312
    46
		}
slouken@312
    47
		vorbis.ov_info =
slouken@312
    48
			(vorbis_info *(*)(OggVorbis_File *,int))
slouken@312
    49
			SDL_LoadFunction(vorbis.handle, "ov_info");
slouken@312
    50
		if ( vorbis.ov_info == NULL ) {
slouken@312
    51
			SDL_UnloadObject(vorbis.handle);
slouken@312
    52
			return -1;
slouken@312
    53
		}
slouken@312
    54
		vorbis.ov_open_callbacks =
slouken@312
    55
			(int (*)(void *, OggVorbis_File *, char *, long, ov_callbacks))
slouken@312
    56
			SDL_LoadFunction(vorbis.handle, "ov_open_callbacks");
slouken@312
    57
		if ( vorbis.ov_open_callbacks == NULL ) {
slouken@312
    58
			SDL_UnloadObject(vorbis.handle);
slouken@312
    59
			return -1;
slouken@312
    60
		}
slouken@312
    61
		vorbis.ov_pcm_total =
slouken@312
    62
			(ogg_int64_t (*)(OggVorbis_File *,int))
slouken@312
    63
			SDL_LoadFunction(vorbis.handle, "ov_pcm_total");
slouken@312
    64
		if ( vorbis.ov_pcm_total == NULL ) {
slouken@312
    65
			SDL_UnloadObject(vorbis.handle);
slouken@312
    66
			return -1;
slouken@312
    67
		}
slouken@312
    68
		vorbis.ov_read =
slouken@367
    69
#ifdef OGG_USE_TREMOR
slouken@367
    70
			(long (*)(OggVorbis_File *,char *,int,int *))
slouken@367
    71
#else
slouken@367
    72
			(long (*)(OggVorbis_File *,char *,int,int,int,int,int *))
slouken@367
    73
#endif
slouken@312
    74
			SDL_LoadFunction(vorbis.handle, "ov_read");
slouken@312
    75
		if ( vorbis.ov_read == NULL ) {
slouken@312
    76
			SDL_UnloadObject(vorbis.handle);
slouken@312
    77
			return -1;
slouken@312
    78
		}
slouken@312
    79
		vorbis.ov_time_seek =
slouken@505
    80
#ifdef OGG_USE_TREMOR
slouken@505
    81
			(long (*)(OggVorbis_File *,ogg_int64_t))
slouken@505
    82
#else
slouken@312
    83
			(int (*)(OggVorbis_File *,double))
slouken@505
    84
#endif
slouken@312
    85
			SDL_LoadFunction(vorbis.handle, "ov_time_seek");
slouken@312
    86
		if ( vorbis.ov_time_seek == NULL ) {
slouken@312
    87
			SDL_UnloadObject(vorbis.handle);
slouken@312
    88
			return -1;
slouken@312
    89
		}
slouken@312
    90
	}
slouken@312
    91
	++vorbis.loaded;
slouken@312
    92
slouken@312
    93
	return 0;
slouken@312
    94
}
slouken@312
    95
void Mix_QuitOgg()
slouken@312
    96
{
slouken@312
    97
	if ( vorbis.loaded == 0 ) {
slouken@312
    98
		return;
slouken@312
    99
	}
slouken@312
   100
	if ( vorbis.loaded == 1 ) {
slouken@312
   101
		SDL_UnloadObject(vorbis.handle);
slouken@312
   102
	}
slouken@312
   103
	--vorbis.loaded;
slouken@312
   104
}
slouken@312
   105
#else
slouken@312
   106
int Mix_InitOgg()
slouken@312
   107
{
slouken@312
   108
	if ( vorbis.loaded == 0 ) {
slouken@312
   109
		vorbis.ov_clear = ov_clear;
slouken@312
   110
		vorbis.ov_info = ov_info;
slouken@312
   111
		vorbis.ov_open_callbacks = ov_open_callbacks;
slouken@312
   112
		vorbis.ov_pcm_total = ov_pcm_total;
slouken@312
   113
		vorbis.ov_read = ov_read;
slouken@312
   114
		vorbis.ov_time_seek = ov_time_seek;
slouken@312
   115
	}
slouken@312
   116
	++vorbis.loaded;
slouken@314
   117
slouken@314
   118
	return 0;
slouken@312
   119
}
slouken@312
   120
void Mix_QuitOgg()
slouken@312
   121
{
slouken@312
   122
	if ( vorbis.loaded == 0 ) {
slouken@312
   123
		return;
slouken@312
   124
	}
slouken@312
   125
	if ( vorbis.loaded == 1 ) {
slouken@312
   126
	}
slouken@312
   127
	--vorbis.loaded;
slouken@312
   128
}
slouken@312
   129
#endif /* OGG_DYNAMIC */
slouken@312
   130
slouken@312
   131
#endif /* OGG_MUSIC */