Added support for dynamically loading Ogg Vorbis library
authorSam Lantinga <slouken@libsdl.org>
Fri, 12 May 2006 06:14:15 +0000
changeset 3128a536296ef3d
parent 311 9c32dbc9e383
child 313 db79bfffb09b
Added support for dynamically loading Ogg Vorbis library
CHANGES
configure.in
dynamic_ogg.c
dynamic_ogg.h
load_ogg.c
music_ogg.c
     1.1 --- a/CHANGES	Fri May 12 02:58:31 2006 +0000
     1.2 +++ b/CHANGES	Fri May 12 06:14:15 2006 +0000
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.7:
     1.5 +Sam Lantinga - Thu May 11 22:22:43 PDT 2006
     1.6 + * Added support for dynamically loading Ogg Vorbis library
     1.7  Sam Lantinga - Sun Apr 30 09:01:44 PDT 2006
     1.8   * Removed automake dependency, to allow Universal binaries on Mac OS X
     1.9   * Added gcc-fat.sh for generating Universal binaries on Mac OS X
     2.1 --- a/configure.in	Fri May 12 02:58:31 2006 +0000
     2.2 +++ b/configure.in	Fri May 12 06:14:15 2006 +0000
     2.3 @@ -109,16 +109,16 @@
     2.4  
     2.5  dnl Check command-line options
     2.6  
     2.7 -AC_ARG_ENABLE(music-cmd,
     2.8 -[  --enable-music-cmd      support an external music player [default=yes]],
     2.9 -              , enable_music_cmd=yes)
    2.10 +AC_ARG_ENABLE([music-cmd],
    2.11 +AC_HELP_STRING([--enable-music-cmd], [support an external music player [[default=yes]]]),
    2.12 +              [], [enable_music_cmd=yes])
    2.13  if test x$enable_music_cmd = xyes; then
    2.14      SOURCES="$SOURCES $srcdir/music_cmd.c"
    2.15      EXTRA_CFLAGS="$EXTRA_CFLAGS -DCMD_MUSIC"
    2.16  fi
    2.17 -AC_ARG_ENABLE(music-wave,
    2.18 -[  --enable-music-wave     enable streaming WAVE music [default=yes]],
    2.19 -              , enable_music_wave=yes)
    2.20 +AC_ARG_ENABLE([music-wave],
    2.21 +AC_HELP_STRING([--enable-music-wave], [enable streaming WAVE music [[default=yes]]]),
    2.22 +              [], [enable_music_wave=yes])
    2.23  if test x$enable_music_wave = xyes; then
    2.24      SOURCES="$SOURCES $srcdir/wavestream.c"
    2.25      EXTRA_CFLAGS="$EXTRA_CFLAGS -DWAV_MUSIC"
    2.26 @@ -128,9 +128,9 @@
    2.27  libmikmod_min=1
    2.28  libmikmod_rev=10
    2.29  libmikmod_ver="$libmikmod_maj.$libmikmod_min.$libmikmod_rev"
    2.30 -AC_ARG_ENABLE(music-libmikmod,
    2.31 -[  --enable-music-libmikmod  enable MOD music via external libmikmod [default=no]],
    2.32 -              , enable_music_libmikmod=no)
    2.33 +AC_ARG_ENABLE([music-libmikmod],
    2.34 +AC_HELP_STRING([--enable-music-libmikmod], [enable MOD music via external libmikmod [[default=no]]]),
    2.35 +              [], [enable_music_libmikmod=no])
    2.36  if test x$enable_music_libmikmod = xyes; then
    2.37  	AC_PATH_PROG(LIBMIKMOD_CONFIG, libmikmod-config, no, [$PATH])
    2.38  	if test "$LIBMIKMOD_CONFIG" != "no" ; then
    2.39 @@ -160,28 +160,28 @@
    2.40  	fi
    2.41  fi
    2.42  
    2.43 -AC_ARG_ENABLE(music-mod,
    2.44 -[  --enable-music-mod      enable MOD music via mikmod [default=yes]],
    2.45 -, enable_music_mod=$no_libmikmod)
    2.46 +AC_ARG_ENABLE([music-mod],
    2.47 +AC_HELP_STRING([--enable-music-mod], [enable MOD music via mikmod [[default=yes]]]),
    2.48 +              [], [enable_music_mod=$no_libmikmod])
    2.49  if test x$enable_music_mod = xyes; then
    2.50      EXTRA_CFLAGS="$EXTRA_CFLAGS -DMOD_MUSIC -I\$(srcdir)/mikmod"
    2.51      SOURCES="$SOURCES $srcdir/mikmod/*.c"
    2.52  fi
    2.53 -AC_ARG_ENABLE(music-midi,
    2.54 -[  --enable-music-midi     enable MIDI music via timidity [default=yes]],
    2.55 -              , enable_music_midi=yes)
    2.56 +AC_ARG_ENABLE([music-midi],
    2.57 +AC_HELP_STRING([--enable-music-midi], [enable MIDI music via timidity [[default=yes]]]),
    2.58 +              [], [enable_music_midi=yes])
    2.59  if test x$enable_music_midi = xyes; then
    2.60      EXTRA_CFLAGS="$EXTRA_CFLAGS -DMID_MUSIC"
    2.61 -    AC_ARG_ENABLE(music-timidity-midi,
    2.62 -[  --enable-music-timidity-midi  enable timidity MIDI output [default=yes]],
    2.63 -                  , enable_music_timidity_midi=yes)
    2.64 +    AC_ARG_ENABLE([music-timidity-midi],
    2.65 +AC_HELP_STRING([--enable-music-timidity-midi], [enable timidity MIDI output [[default=yes]]]),
    2.66 +                  [], [enable_music_timidity_midi=yes])
    2.67      if test x$enable_music_timidity_midi = xyes; then
    2.68          EXTRA_CFLAGS="$EXTRA_CFLAGS -DUSE_TIMIDITY_MIDI -I\$(srcdir)/timidity"
    2.69          SOURCES="$SOURCES $srcdir/timidity/*.c"
    2.70      fi
    2.71 -    AC_ARG_ENABLE(music-native-midi,
    2.72 -[  --enable-music-native-midi  enable native MIDI music output [default=yes]],
    2.73 -                  , enable_music_native_midi=yes)
    2.74 +    AC_ARG_ENABLE([music-native-midi],
    2.75 +AC_HELP_STRING([--enable-music-native-midi], [enable native MIDI music output [[default=yes]]]),
    2.76 +                  [], [enable_music_native_midi=yes])
    2.77      if test x$enable_music_native_midi = xyes; then
    2.78          use_music_native_midi=no
    2.79          case "$host" in
    2.80 @@ -199,9 +199,9 @@
    2.81              SOURCES="$SOURCES $srcdir/native_midi/*.c"
    2.82          fi
    2.83      fi
    2.84 -    AC_ARG_ENABLE(music-native-midi-gpl,
    2.85 -[  --enable-music-native-midi-gpl  enable native MIDI on UNIX using GPL code [default=no]],
    2.86 -                  , enable_music_native_midi_gpl=no)
    2.87 +    AC_ARG_ENABLE([music-native-midi-gpl],
    2.88 +AC_HELP_STRING([--enable-music-native-midi-gpl], [enable native MIDI on UNIX using GPL code [[default=no]]]),
    2.89 +                  [], [enable_music_native_midi_gpl=no])
    2.90      if test x$enable_music_native_midi_gpl = xyes; then
    2.91          use_music_native_midi_gpl=no
    2.92          case "$host" in
    2.93 @@ -215,9 +215,9 @@
    2.94          fi
    2.95      fi
    2.96  fi
    2.97 -AC_ARG_ENABLE(music-ogg,
    2.98 -[  --enable-music-ogg      enable Ogg Vorbis music [default=yes]],
    2.99 -              , enable_music_ogg=yes)
   2.100 +AC_ARG_ENABLE([music-ogg],
   2.101 +AC_HELP_STRING([--enable-music-ogg], [enable Ogg Vorbis music [[default=yes]]]),
   2.102 +              [], [enable_music_ogg=yes])
   2.103  if test x$enable_music_ogg = xyes; then
   2.104      AC_MSG_CHECKING(for Ogg Vorbis headers and libraries)
   2.105      have_vorbis=no
   2.106 @@ -229,13 +229,36 @@
   2.107      ])
   2.108      AC_MSG_RESULT($have_vorbis)
   2.109      if test x$have_vorbis = xyes; then
   2.110 -        SOURCES="$SOURCES $srcdir/load_ogg.c $srcdir/music_ogg.c"
   2.111 +        AC_ARG_ENABLE([music-ogg-shared],
   2.112 +AC_HELP_STRING([--enable-music-ogg-shared], [dynamically load Ogg Vorbis support [[default=yes]]]),
   2.113 +                      [], [enable_music_ogg_shared=yes])
   2.114 +        case "$host" in
   2.115 +            *-*-darwin*) # FIXME when Mac OS X ships with Ogg Vorbis
   2.116 +                ogg_lib=''
   2.117 +                ;;
   2.118 +            *-*-cygwin* | *-*-mingw32*)
   2.119 +                ogg_lib='vorbisfile.dll'
   2.120 +                ;;
   2.121 +            *)
   2.122 +                for path in /usr/lib /usr/local/lib; do
   2.123 +                    if test x$ogg_lib = x; then
   2.124 +                        ogg_lib=[`ls -- $path/libvorbisfile.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   2.125 +                    fi
   2.126 +                done
   2.127 +                ;;
   2.128 +        esac
   2.129 +        SOURCES="$SOURCES $srcdir/*_ogg.c"
   2.130          EXTRA_CFLAGS="$EXTRA_CFLAGS -DOGG_MUSIC"
   2.131 -        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvorbisfile -lvorbis -logg"
   2.132 +        if test x$enable_music_ogg_shared = xyes && test x$ogg_lib != x; then
   2.133 +            echo "-- dynamic libvorbisfile -> $ogg_lib"
   2.134 +            EXTRA_CFLAGS="$EXTRA_CFLAGS -DOGG_DYNAMIC=\\\"$ogg_lib\\\""
   2.135 +        else
   2.136 +            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvorbisfile -lvorbis -logg"
   2.137 +        fi
   2.138      fi
   2.139  fi
   2.140  AC_ARG_ENABLE(music-mp3,
   2.141 -[  --enable-music-mp3      enable MP3 music via smpeg [default=yes]],
   2.142 +[  --enable-music-mp3      enable MP3 music via smpeg [[default=yes]]],
   2.143                , enable_music_mp3=yes)
   2.144  if test x$enable_music_mp3 = xyes; then
   2.145      SMPEG_VERSION=0.4.3
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/dynamic_ogg.c	Fri May 12 06:14:15 2006 +0000
     3.3 @@ -0,0 +1,130 @@
     3.4 +/*
     3.5 +    SDL_mixer:  An audio mixer library based on the SDL library
     3.6 +    Copyright (C) 1997-2004 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Library General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Library General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Library General Public
    3.19 +    License along with this library; if not, write to the Free
    3.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +
    3.26 +#ifdef OGG_MUSIC
    3.27 +
    3.28 +#include "SDL_loadso.h"
    3.29 +
    3.30 +#include "dynamic_ogg.h"
    3.31 +
    3.32 +vorbis_loader vorbis = {
    3.33 +	0, NULL
    3.34 +};
    3.35 +
    3.36 +#ifdef OGG_DYNAMIC
    3.37 +int Mix_InitOgg()
    3.38 +{
    3.39 +	if ( vorbis.loaded == 0 ) {
    3.40 +		vorbis.handle = SDL_LoadObject(OGG_DYNAMIC);
    3.41 +		if ( vorbis.handle == NULL ) {
    3.42 +			return -1;
    3.43 +		}
    3.44 +		vorbis.ov_clear =
    3.45 +			(int (*)(OggVorbis_File *))
    3.46 +			SDL_LoadFunction(vorbis.handle, "ov_clear");
    3.47 +		if ( vorbis.ov_clear == NULL ) {
    3.48 +			SDL_UnloadObject(vorbis.handle);
    3.49 +			return -1;
    3.50 +		}
    3.51 +		vorbis.ov_info =
    3.52 +			(vorbis_info *(*)(OggVorbis_File *,int))
    3.53 +			SDL_LoadFunction(vorbis.handle, "ov_info");
    3.54 +		if ( vorbis.ov_info == NULL ) {
    3.55 +			SDL_UnloadObject(vorbis.handle);
    3.56 +			return -1;
    3.57 +		}
    3.58 +		vorbis.ov_open =
    3.59 +			(int (*)(FILE *,OggVorbis_File *,char *,long))
    3.60 +			SDL_LoadFunction(vorbis.handle, "ov_open");
    3.61 +		if ( vorbis.ov_open == NULL ) {
    3.62 +			SDL_UnloadObject(vorbis.handle);
    3.63 +			return -1;
    3.64 +		}
    3.65 +		vorbis.ov_open_callbacks =
    3.66 +			(int (*)(void *, OggVorbis_File *, char *, long, ov_callbacks))
    3.67 +			SDL_LoadFunction(vorbis.handle, "ov_open_callbacks");
    3.68 +		if ( vorbis.ov_open_callbacks == NULL ) {
    3.69 +			SDL_UnloadObject(vorbis.handle);
    3.70 +			return -1;
    3.71 +		}
    3.72 +		vorbis.ov_pcm_total =
    3.73 +			(ogg_int64_t (*)(OggVorbis_File *,int))
    3.74 +			SDL_LoadFunction(vorbis.handle, "ov_pcm_total");
    3.75 +		if ( vorbis.ov_pcm_total == NULL ) {
    3.76 +			SDL_UnloadObject(vorbis.handle);
    3.77 +			return -1;
    3.78 +		}
    3.79 +		vorbis.ov_read =
    3.80 +			(long (*)(OggVorbis_File *,char *,int, int,int,int,int *))
    3.81 +			SDL_LoadFunction(vorbis.handle, "ov_read");
    3.82 +		if ( vorbis.ov_read == NULL ) {
    3.83 +			SDL_UnloadObject(vorbis.handle);
    3.84 +			return -1;
    3.85 +		}
    3.86 +		vorbis.ov_time_seek =
    3.87 +			(int (*)(OggVorbis_File *,double))
    3.88 +			SDL_LoadFunction(vorbis.handle, "ov_time_seek");
    3.89 +		if ( vorbis.ov_time_seek == NULL ) {
    3.90 +			SDL_UnloadObject(vorbis.handle);
    3.91 +			return -1;
    3.92 +		}
    3.93 +	}
    3.94 +	++vorbis.loaded;
    3.95 +
    3.96 +	return 0;
    3.97 +}
    3.98 +void Mix_QuitOgg()
    3.99 +{
   3.100 +	if ( vorbis.loaded == 0 ) {
   3.101 +		return;
   3.102 +	}
   3.103 +	if ( vorbis.loaded == 1 ) {
   3.104 +		SDL_UnloadObject(vorbis.handle);
   3.105 +	}
   3.106 +	--vorbis.loaded;
   3.107 +}
   3.108 +#else
   3.109 +int Mix_InitOgg()
   3.110 +{
   3.111 +	if ( vorbis.loaded == 0 ) {
   3.112 +		vorbis.ov_clear = ov_clear;
   3.113 +		vorbis.ov_info = ov_info;
   3.114 +		vorbis.ov_open = ov_open;
   3.115 +		vorbis.ov_open_callbacks = ov_open_callbacks;
   3.116 +		vorbis.ov_pcm_total = ov_pcm_total;
   3.117 +		vorbis.ov_read = ov_read;
   3.118 +		vorbis.ov_time_seek = ov_time_seek;
   3.119 +	}
   3.120 +	++vorbis.loaded;
   3.121 +}
   3.122 +void Mix_QuitOgg()
   3.123 +{
   3.124 +	if ( vorbis.loaded == 0 ) {
   3.125 +		return;
   3.126 +	}
   3.127 +	if ( vorbis.loaded == 1 ) {
   3.128 +	}
   3.129 +	--vorbis.loaded;
   3.130 +}
   3.131 +#endif /* OGG_DYNAMIC */
   3.132 +
   3.133 +#endif /* OGG_MUSIC */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/dynamic_ogg.h	Fri May 12 06:14:15 2006 +0000
     4.3 @@ -0,0 +1,43 @@
     4.4 +/*
     4.5 +    SDL_mixer:  An audio mixer library based on the SDL library
     4.6 +    Copyright (C) 1997-2004 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Library General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Library General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Library General Public
    4.19 +    License along with this library; if not, write to the Free
    4.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +
    4.26 +#ifdef OGG_MUSIC
    4.27 +#include <vorbis/vorbisfile.h>
    4.28 +
    4.29 +typedef struct {
    4.30 +	int loaded;
    4.31 +	void *handle;
    4.32 +	int (*ov_clear)(OggVorbis_File *vf);
    4.33 +	vorbis_info *(*ov_info)(OggVorbis_File *vf,int link);
    4.34 +	int (*ov_open)(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
    4.35 +	int (*ov_open_callbacks)(void *datasource, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks);
    4.36 +	ogg_int64_t (*ov_pcm_total)(OggVorbis_File *vf,int i);
    4.37 +	long (*ov_read)(OggVorbis_File *vf,char *buffer,int length, int bigendianp,int word,int sgned,int *bitstream);
    4.38 +	int (*ov_time_seek)(OggVorbis_File *vf,double pos);
    4.39 +} vorbis_loader;
    4.40 +
    4.41 +extern vorbis_loader vorbis;
    4.42 +
    4.43 +extern int Mix_InitOgg();
    4.44 +extern void Mix_QuitOgg();
    4.45 +
    4.46 +#endif
     5.1 --- a/load_ogg.c	Fri May 12 02:58:31 2006 +0000
     5.2 +++ b/load_ogg.c	Fri May 12 06:14:15 2006 +0000
     5.3 @@ -27,13 +27,13 @@
     5.4  #include <stdio.h>
     5.5  #include <stdlib.h>
     5.6  #include <string.h>
     5.7 -#include <vorbis/vorbisfile.h>
     5.8  
     5.9  #include "SDL_mutex.h"
    5.10  #include "SDL_endian.h"
    5.11  #include "SDL_timer.h"
    5.12  
    5.13  #include "SDL_mixer.h"
    5.14 +#include "dynamic_ogg.h"
    5.15  #include "load_ogg.h"
    5.16  
    5.17  static size_t sdl_read_func(void *ptr, size_t size, size_t nmemb, void *datasource)
    5.18 @@ -80,13 +80,16 @@
    5.19      if ( (!src) || (!audio_buf) || (!audio_len) )   /* sanity checks. */
    5.20          goto done;
    5.21  
    5.22 +    if ( Mix_InitOgg() < 0 )
    5.23 +        goto done;
    5.24 +
    5.25      callbacks.read_func = sdl_read_func;
    5.26      callbacks.seek_func = sdl_seek_func;
    5.27      callbacks.tell_func = sdl_tell_func;
    5.28      callbacks.close_func = freesrc ? 
    5.29                             sdl_close_func_freesrc : sdl_close_func_nofreesrc;
    5.30  
    5.31 -    if (ov_open_callbacks(src, &vf, NULL, 0, callbacks) != 0)
    5.32 +    if (vorbis.ov_open_callbacks(src, &vf, NULL, 0, callbacks) != 0)
    5.33      {
    5.34          SDL_SetError("OGG bitstream is not valid Vorbis stream!");
    5.35          goto done;
    5.36 @@ -94,7 +97,7 @@
    5.37  
    5.38      must_close = 0;
    5.39      
    5.40 -    info = ov_info(&vf, -1);
    5.41 +    info = vorbis.ov_info(&vf, -1);
    5.42      
    5.43      *audio_buf = NULL;
    5.44      *audio_len = 0;
    5.45 @@ -105,7 +108,7 @@
    5.46      spec->freq = info->rate;
    5.47      spec->samples = 4096; /* buffer size */
    5.48      
    5.49 -    samples = (long)ov_pcm_total(&vf, -1);
    5.50 +    samples = (long)vorbis.ov_pcm_total(&vf, -1);
    5.51  
    5.52      *audio_len = spec->size = samples * spec->channels * 2;
    5.53      *audio_buf = malloc(*audio_len);
    5.54 @@ -114,9 +117,9 @@
    5.55  
    5.56      buf = *audio_buf;
    5.57      to_read = *audio_len;
    5.58 -    for (read = ov_read(&vf, buf, to_read, 0/*LE*/, 2/*16bit*/, 1/*signed*/, &bitstream);
    5.59 +    for (read = vorbis.ov_read(&vf, (char *)buf, to_read, 0/*LE*/, 2/*16bit*/, 1/*signed*/, &bitstream);
    5.60           read > 0;
    5.61 -         read = ov_read(&vf, buf, to_read, 0, 2, 1, &bitstream))
    5.62 +         read = vorbis.ov_read(&vf, (char *)buf, to_read, 0, 2, 1, &bitstream))
    5.63      {
    5.64          if (read == OV_HOLE || read == OV_EBADLINK)
    5.65              break; /* error */
    5.66 @@ -125,7 +128,7 @@
    5.67          buf += read;
    5.68      }
    5.69  
    5.70 -    ov_clear(&vf);
    5.71 +    vorbis.ov_clear(&vf);
    5.72      was_error = 0;
    5.73  
    5.74      /* Don't return a buffer that isn't a multiple of samplesize */
    5.75 @@ -144,6 +147,8 @@
    5.76      if ( was_error )
    5.77          spec = NULL;
    5.78  
    5.79 +    Mix_QuitOgg();
    5.80 +
    5.81      return(spec);
    5.82  } /* Mix_LoadOGG_RW */
    5.83  
     6.1 --- a/music_ogg.c	Fri May 12 02:58:31 2006 +0000
     6.2 +++ b/music_ogg.c	Fri May 12 06:14:15 2006 +0000
     6.3 @@ -31,6 +31,7 @@
     6.4  #include <string.h>
     6.5  
     6.6  #include "SDL_mixer.h"
     6.7 +#include "dynamic_ogg.h"
     6.8  #include "music_ogg.h"
     6.9  
    6.10  /* This is the format of the audio mixer data */
    6.11 @@ -65,20 +66,25 @@
    6.12  		OGG_setvolume(music, MIX_MAX_VOLUME);
    6.13  		music->section = -1;
    6.14  
    6.15 +		if ( Mix_InitOgg() < 0 ) {
    6.16 +			return(NULL);
    6.17 +		}
    6.18  		fp = fopen(file, "rb");
    6.19  		if ( fp == NULL ) {
    6.20 +			free(music);
    6.21 +			Mix_QuitOgg();
    6.22  			SDL_SetError("Couldn't open %s", file);
    6.23 -			free(music);
    6.24  			return(NULL);
    6.25  		}
    6.26 -		if ( ov_open(fp, &music->vf, NULL, 0) < 0 ) {
    6.27 +		if ( vorbis.ov_open(fp, &music->vf, NULL, 0) < 0 ) {
    6.28 +			fclose(fp);
    6.29 +			free(music);
    6.30 +			Mix_QuitOgg();
    6.31  			SDL_SetError("Not an Ogg Vorbis audio stream");
    6.32 -			free(music);
    6.33 -			fclose(fp);
    6.34  			return(NULL);
    6.35  		}
    6.36  	} else {
    6.37 -		SDL_SetError("Out of memory");
    6.38 +		SDL_OutOfMemory();
    6.39  	}
    6.40  	return(music);
    6.41  }
    6.42 @@ -123,14 +129,18 @@
    6.43  		OGG_setvolume(music, MIX_MAX_VOLUME);
    6.44  		music->section = -1;
    6.45  
    6.46 -		if ( ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
    6.47 -			SDL_SetError("Not an Ogg Vorbis audio stream");
    6.48 +		if ( Mix_InitOgg() < 0 ) {
    6.49 +			return(NULL);
    6.50 +		}
    6.51 +		if ( vorbis.ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
    6.52  			free(music);
    6.53  			SDL_RWclose(rw);
    6.54 +			Mix_QuitOgg();
    6.55 +			SDL_SetError("Not an Ogg Vorbis audio stream");
    6.56  			return(NULL);
    6.57  		}
    6.58  	} else {
    6.59 -		SDL_SetError("Out of memory");
    6.60 +		SDL_OutOfMemory();
    6.61  	}
    6.62  	return(music);
    6.63  }
    6.64 @@ -155,7 +165,7 @@
    6.65  	char data[4096];
    6.66  	SDL_AudioCVT *cvt;
    6.67  
    6.68 -	len = ov_read(&music->vf, data, sizeof(data), 0, 2, 1, &section);
    6.69 +	len = vorbis.ov_read(&music->vf, data, sizeof(data), 0, 2, 1, &section);
    6.70  	if ( len <= 0 ) {
    6.71  		if ( len == 0 ) {
    6.72  			music->playing = 0;
    6.73 @@ -166,7 +176,7 @@
    6.74  	if ( section != music->section ) {
    6.75  		vorbis_info *vi;
    6.76  
    6.77 -		vi = ov_info(&music->vf, -1);
    6.78 +		vi = vorbis.ov_info(&music->vf, -1);
    6.79  		SDL_BuildAudioCVT(cvt, AUDIO_S16, vi->channels, vi->rate,
    6.80  		                       mixer.format,mixer.channels,mixer.freq);
    6.81  		if ( cvt->buf ) {
    6.82 @@ -232,15 +242,16 @@
    6.83  		if ( music->cvt.buf ) {
    6.84  			free(music->cvt.buf);
    6.85  		}
    6.86 -		ov_clear(&music->vf);
    6.87 +		vorbis.ov_clear(&music->vf);
    6.88  		free(music);
    6.89 +		Mix_QuitOgg();
    6.90  	}
    6.91  }
    6.92  
    6.93  /* Jump (seek) to a given position (time is in seconds) */
    6.94  void OGG_jump_to_time(OGG_music *music, double time)
    6.95  {
    6.96 -       ov_time_seek( &music->vf, time );
    6.97 +       vorbis.ov_time_seek( &music->vf, time );
    6.98  }
    6.99  
   6.100  #endif /* OGG_MUSIC */