dynamic_ogg.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 15 Mar 2011 23:11:29 -0700
changeset 505 5b24d089d9f5
parent 472 463ba3222193
child 518 8bc9b5fd2aae
permissions -rw-r--r--
Fixed ov_time_seek signature for Tremor
slouken@312
     1
/*
slouken@312
     2
    SDL_mixer:  An audio mixer library based on the SDL library
slouken@386
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@312
     4
slouken@312
     5
    This library is free software; you can redistribute it and/or
slouken@312
     6
    modify it under the terms of the GNU Library General Public
slouken@312
     7
    License as published by the Free Software Foundation; either
slouken@312
     8
    version 2 of the License, or (at your option) any later version.
slouken@312
     9
slouken@312
    10
    This library is distributed in the hope that it will be useful,
slouken@312
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@312
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@312
    13
    Library General Public License for more details.
slouken@312
    14
slouken@312
    15
    You should have received a copy of the GNU Library General Public
slouken@312
    16
    License along with this library; if not, write to the Free
slouken@312
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@312
    18
slouken@312
    19
    Sam Lantinga
slouken@312
    20
    slouken@libsdl.org
slouken@312
    21
*/
slouken@312
    22
slouken@312
    23
#ifdef OGG_MUSIC
slouken@312
    24
slouken@312
    25
#include "SDL_loadso.h"
slouken@312
    26
slouken@312
    27
#include "dynamic_ogg.h"
slouken@312
    28
slouken@312
    29
vorbis_loader vorbis = {
slouken@312
    30
	0, NULL
slouken@312
    31
};
slouken@312
    32
slouken@312
    33
#ifdef OGG_DYNAMIC
slouken@312
    34
int Mix_InitOgg()
slouken@312
    35
{
slouken@312
    36
	if ( vorbis.loaded == 0 ) {
slouken@312
    37
		vorbis.handle = SDL_LoadObject(OGG_DYNAMIC);
slouken@312
    38
		if ( vorbis.handle == NULL ) {
slouken@312
    39
			return -1;
slouken@312
    40
		}
slouken@312
    41
		vorbis.ov_clear =
slouken@312
    42
			(int (*)(OggVorbis_File *))
slouken@312
    43
			SDL_LoadFunction(vorbis.handle, "ov_clear");
slouken@312
    44
		if ( vorbis.ov_clear == NULL ) {
slouken@312
    45
			SDL_UnloadObject(vorbis.handle);
slouken@312
    46
			return -1;
slouken@312
    47
		}
slouken@312
    48
		vorbis.ov_info =
slouken@312
    49
			(vorbis_info *(*)(OggVorbis_File *,int))
slouken@312
    50
			SDL_LoadFunction(vorbis.handle, "ov_info");
slouken@312
    51
		if ( vorbis.ov_info == NULL ) {
slouken@312
    52
			SDL_UnloadObject(vorbis.handle);
slouken@312
    53
			return -1;
slouken@312
    54
		}
slouken@312
    55
		vorbis.ov_open_callbacks =
slouken@312
    56
			(int (*)(void *, OggVorbis_File *, char *, long, ov_callbacks))
slouken@312
    57
			SDL_LoadFunction(vorbis.handle, "ov_open_callbacks");
slouken@312
    58
		if ( vorbis.ov_open_callbacks == NULL ) {
slouken@312
    59
			SDL_UnloadObject(vorbis.handle);
slouken@312
    60
			return -1;
slouken@312
    61
		}
slouken@312
    62
		vorbis.ov_pcm_total =
slouken@312
    63
			(ogg_int64_t (*)(OggVorbis_File *,int))
slouken@312
    64
			SDL_LoadFunction(vorbis.handle, "ov_pcm_total");
slouken@312
    65
		if ( vorbis.ov_pcm_total == NULL ) {
slouken@312
    66
			SDL_UnloadObject(vorbis.handle);
slouken@312
    67
			return -1;
slouken@312
    68
		}
slouken@312
    69
		vorbis.ov_read =
slouken@367
    70
#ifdef OGG_USE_TREMOR
slouken@367
    71
			(long (*)(OggVorbis_File *,char *,int,int *))
slouken@367
    72
#else
slouken@367
    73
			(long (*)(OggVorbis_File *,char *,int,int,int,int,int *))
slouken@367
    74
#endif
slouken@312
    75
			SDL_LoadFunction(vorbis.handle, "ov_read");
slouken@312
    76
		if ( vorbis.ov_read == NULL ) {
slouken@312
    77
			SDL_UnloadObject(vorbis.handle);
slouken@312
    78
			return -1;
slouken@312
    79
		}
slouken@312
    80
		vorbis.ov_time_seek =
slouken@505
    81
#ifdef OGG_USE_TREMOR
slouken@505
    82
			(long (*)(OggVorbis_File *,ogg_int64_t))
slouken@505
    83
#else
slouken@312
    84
			(int (*)(OggVorbis_File *,double))
slouken@505
    85
#endif
slouken@312
    86
			SDL_LoadFunction(vorbis.handle, "ov_time_seek");
slouken@312
    87
		if ( vorbis.ov_time_seek == NULL ) {
slouken@312
    88
			SDL_UnloadObject(vorbis.handle);
slouken@312
    89
			return -1;
slouken@312
    90
		}
slouken@312
    91
	}
slouken@312
    92
	++vorbis.loaded;
slouken@312
    93
slouken@312
    94
	return 0;
slouken@312
    95
}
slouken@312
    96
void Mix_QuitOgg()
slouken@312
    97
{
slouken@312
    98
	if ( vorbis.loaded == 0 ) {
slouken@312
    99
		return;
slouken@312
   100
	}
slouken@312
   101
	if ( vorbis.loaded == 1 ) {
slouken@312
   102
		SDL_UnloadObject(vorbis.handle);
slouken@312
   103
	}
slouken@312
   104
	--vorbis.loaded;
slouken@312
   105
}
slouken@312
   106
#else
slouken@312
   107
int Mix_InitOgg()
slouken@312
   108
{
slouken@312
   109
	if ( vorbis.loaded == 0 ) {
slouken@312
   110
		vorbis.ov_clear = ov_clear;
slouken@312
   111
		vorbis.ov_info = ov_info;
slouken@312
   112
		vorbis.ov_open_callbacks = ov_open_callbacks;
slouken@312
   113
		vorbis.ov_pcm_total = ov_pcm_total;
slouken@312
   114
		vorbis.ov_read = ov_read;
slouken@312
   115
		vorbis.ov_time_seek = ov_time_seek;
slouken@312
   116
	}
slouken@312
   117
	++vorbis.loaded;
slouken@314
   118
slouken@314
   119
	return 0;
slouken@312
   120
}
slouken@312
   121
void Mix_QuitOgg()
slouken@312
   122
{
slouken@312
   123
	if ( vorbis.loaded == 0 ) {
slouken@312
   124
		return;
slouken@312
   125
	}
slouken@312
   126
	if ( vorbis.loaded == 1 ) {
slouken@312
   127
	}
slouken@312
   128
	--vorbis.loaded;
slouken@312
   129
}
slouken@312
   130
#endif /* OGG_DYNAMIC */
slouken@312
   131
slouken@312
   132
#endif /* OGG_MUSIC */