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