Navigation Menu

Skip to content

Commit

Permalink
Updated to libFLAC 1.1.3 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 28, 2006
1 parent fcfda5b commit 9f6a01e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 28 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Expand Up @@ -2,7 +2,9 @@
* CHANGELOG.
*/

05122005 - Patched to get mpglib compiling again (thanks, Sam!).
10272006 - FLAC 1.1.3 breaks their API _again_, so we try to do the right
thing at build time. (Thanks, Josh!).
05122006 - Patched to get mpglib compiling again (thanks, Sam!).
12172005 - Fixed gcc4 whining in playsound_simple.c.
12062005 - Trimmed a bunch of junk out of the build system, and now it works
on Mac OS X again.
Expand Down
3 changes: 3 additions & 0 deletions CREDITS
Expand Up @@ -53,6 +53,9 @@ Initial Borland C++ project files:
Bugfixes and stuff:
Eric Wing

FLAC 1.1.3 updates:
Josh Coalson

Other stuff:
Your name here! Patches go to icculus@clutteredmind.org ...

Expand Down
65 changes: 38 additions & 27 deletions configure.in
Expand Up @@ -151,28 +151,6 @@ if test x$enable_midi = xyes; then
AC_DEFINE(SOUND_SUPPORTS_MIDI, 1, [Define if MIDI support is desired.])
fi


dnl Note that we intentionally look for a symbol in FLAC 1.0.4, since the
dnl FLAC developers tend to break their API with every release, so we're
dnl checking for the latest-and-greatest here so we don't have to support
dnl obsolete versions.

dnl Hooray for shitty autoconf bugs!
x="C__seekable_stream_decoder_process_single"
flcsym="FLA$x"
dnl Check for libFLAC
AC_ARG_ENABLE(flac,
[ --enable-flac enable FLAC decoding via libFLAC [default=yes]],
, enable_flac=yes)
if test x$enable_flac = xyes; then
AC_CHECK_HEADER(FLAC/stream_decoder.h, have_flac_hdr=yes)
AC_CHECK_LIB(FLAC, $flcsym, have_flac_lib=yes)
if test x$have_flac_hdr = xyes -a x$have_flac_lib = xyes; then
LIBS="$LIBS -lFLAC"
AC_DEFINE(SOUND_SUPPORTS_FLAC, 1, [Define if FLAC support is desired.])
fi
fi

dnl Check for SMPEG
AC_ARG_ENABLE(smpeg,
[ --enable-smpeg enable MP3 decoding via smpeg [default=yes]],
Expand Down Expand Up @@ -230,20 +208,25 @@ if test x$enable_modplug = xyes; then
fi
fi

dnl Check for ogg
AC_CHECK_HEADER(ogg/ogg.h, have_ogg_hdr=yes)
AC_CHECK_LIB(ogg, ogg_sync_init, have_ogg_lib=yes)
have_ogg=no
if test x$have_ogg_hdr = xyes -a x$have_ogg_lib = xyes; then
have_ogg=yes
fi

dnl !!! FIXME: should be --enable-vorbis.
dnl Check for Ogg Vorbis
AC_ARG_ENABLE(ogg,
[ --enable-ogg enable OGG decoding via libvorbis [default=yes]],
, enable_ogg=yes)
if test x$enable_ogg = xyes; then
AC_CHECK_HEADER(ogg/ogg.h, have_ogg_hdr=yes)
AC_CHECK_LIB(ogg, ogg_sync_init, have_ogg_lib=yes)
AC_CHECK_HEADER(vorbis/codec.h, have_vorbis_hdr=yes)
AC_CHECK_LIB(vorbis, vorbis_info_init, have_vorbis_lib=yes)
AC_CHECK_HEADER(vorbis/vorbisfile.h, have_vorbisfile_hdr=yes)
AC_CHECK_LIB(vorbisfile, ov_open_callbacks, have_vorbisfile_lib=yes)

have_vorbis=no
if test x$have_ogg_hdr = xyes -a x$have_ogg_lib = xyes; then
if test x$have_ogg = xyes; then
if test x$have_vorbis_hdr = xyes -a x$have_vorbis_lib = xyes; then
if test x$have_vorbisfile_hdr = xyes -a x$have_vorbisfile_lib = xyes; then
have_vorbis=yes
Expand All @@ -258,6 +241,34 @@ if test x$enable_ogg = xyes; then
fi
fi


dnl Note that we intentionally look for a symbol in FLAC 1.0.4, since the
dnl FLAC developers tend to break their API with every release, so we're
dnl checking for the latest-and-greatest here so we don't have to support
dnl obsolete versions.
dnl Starting with FLAC 1.1.3:
dnl libFLAC supports Ogg FLAC (no more libOggFLAC) so we also need -logg
dnl the libFLAC .so version is also #defined in FLAC/export.h

dnl Hooray for shitty autoconf bugs!
x="C__stream_decoder_process_single"
flcsym="FLA$x"
dnl Check for libFLAC
AC_ARG_ENABLE(flac,
[ --enable-flac enable FLAC decoding via libFLAC [default=yes]],
, enable_flac=yes)
if test x$enable_flac = xyes; then
AC_CHECK_HEADER(FLAC/stream_decoder.h, have_flac_hdr=yes)
AC_CHECK_LIB(FLAC, $flcsym, have_flac_lib=yes)
if test x$have_ogg = xyes; then
if test x$have_flac_hdr = xyes -a x$have_flac_lib = xyes; then
LIBS="$LIBS -lFLAC -logg"
AC_DEFINE(SOUND_SUPPORTS_FLAC, 1, [Define if FLAC support is desired.])
fi
fi
fi


dnl Check for speex
AC_ARG_ENABLE(speex,
[ --enable-speex enable SPX decoding via libspeex [default=yes]],
Expand Down
54 changes: 54 additions & 0 deletions decoders/flac.c
Expand Up @@ -44,6 +44,16 @@
#define __SDL_SOUND_INTERNAL__
#include "SDL_sound_internal.h"

#include <FLAC/export.h>

/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8
#define LEGACY_FLAC
#else
#undef LEGACY_FLAC
#endif

#ifdef LEGACY_FLAC
#include <FLAC/seekable_stream_decoder.h>

#define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM
Expand Down Expand Up @@ -80,6 +90,34 @@ typedef FLAC__SeekableStreamDecoderReadStatus d_read_status_t;
typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t;
typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t;
typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t;
#else
#include <FLAC/stream_decoder.h>

#define D_END_OF_STREAM FLAC__STREAM_DECODER_END_OF_STREAM

#define d_new() FLAC__stream_decoder_new()
#define d_process_metadata(x) FLAC__stream_decoder_process_until_end_of_metadata(x)
#define d_process_one_frame(x) FLAC__stream_decoder_process_single(x)
#define d_get_state(x) FLAC__stream_decoder_get_state(x)
#define d_finish(x) FLAC__stream_decoder_finish(x)
#define d_delete(x) FLAC__stream_decoder_delete(x)

typedef FLAC__StreamDecoder decoder_t;
typedef FLAC__StreamDecoderReadStatus d_read_status_t;

#define D_SEEK_STATUS_OK FLAC__STREAM_DECODER_SEEK_STATUS_OK
#define D_SEEK_STATUS_ERROR FLAC__STREAM_DECODER_SEEK_STATUS_ERROR
#define D_TELL_STATUS_OK FLAC__STREAM_DECODER_TELL_STATUS_OK
#define D_TELL_STATUS_ERROR FLAC__STREAM_DECODER_TELL_STATUS_ERROR
#define D_LENGTH_STATUS_OK FLAC__STREAM_DECODER_LENGTH_STATUS_OK
#define D_LENGTH_STATUS_ERROR FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR

#define d_seek_absolute(x, y) FLAC__stream_decoder_seek_absolute(x, y)

typedef FLAC__StreamDecoderSeekStatus d_seek_status_t;
typedef FLAC__StreamDecoderTellStatus d_tell_status_t;
typedef FLAC__StreamDecoderLengthStatus d_length_status_t;
#endif

#define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE
#define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM
Expand Down Expand Up @@ -141,9 +179,15 @@ static void free_flac(flac_t *f)
} /* free_flac */


#ifdef LEGACY_FLAC
static d_read_status_t read_callback(
const decoder_t *decoder, FLAC__byte buffer[],
unsigned int *bytes, void *client_data)
#else
static d_read_status_t read_callback(
const decoder_t *decoder, FLAC__byte buffer[],
size_t *bytes, void *client_data)
#endif
{
flac_t *f = (flac_t *) client_data;
Uint32 retval;
Expand Down Expand Up @@ -400,6 +444,7 @@ static int FLAC_open(Sound_Sample *sample, const char *ext)
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
} /* if */

#ifdef LEGACY_FLAC
d_set_read_callback(decoder, read_callback);
d_set_write_callback(decoder, write_callback);
d_set_metadata_callback(decoder, metadata_callback);
Expand All @@ -410,6 +455,7 @@ static int FLAC_open(Sound_Sample *sample, const char *ext)
d_set_eof_callback(decoder, eof_callback);

d_set_client_data(decoder, f);
#endif

f->rw = internal->rw;
f->sample = sample;
Expand All @@ -418,7 +464,15 @@ static int FLAC_open(Sound_Sample *sample, const char *ext)
f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */;

internal->decoder_private = f;
/* really should check the init return value here: */
#ifdef LEGACY_FLAC
d_init(decoder);
#else
FLAC__stream_decoder_init_stream(decoder, read_callback, seek_callback,
tell_callback, length_callback,
eof_callback, write_callback,
metadata_callback, error_callback, f);
#endif

sample->flags = SOUND_SAMPLEFLAG_NONE;

Expand Down

0 comments on commit 9f6a01e

Please sign in to comment.