aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--m4/libFLAC.m424
-rw-r--r--src/inputPlugins/flac_plugin.c166
2 files changed, 77 insertions, 113 deletions
diff --git a/m4/libFLAC.m4 b/m4/libFLAC.m4
index a478d7866..9c5f9ecba 100644
--- a/m4/libFLAC.m4
+++ b/m4/libFLAC.m4
@@ -2,10 +2,10 @@
# "Inspired" by ogg.m4
dnl AM_PATH_LIBFLAC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
-dnl Test for libFLAC, and define LIBFLAC_CFLAGS and LIBFLAC_LIBS
+dnl Test for libFLAC, and define LIBFLAC_CFLAGS, LIBFLAC_LIBS, LIBFLAC_LIBDIR
dnl
AC_DEFUN([AM_PATH_LIBFLAC],
-[dnl
+[dnl
dnl Get the cflags and libraries
dnl
AC_ARG_WITH(libFLAC,[ --with-libFLAC=PFX Prefix where libFLAC is installed (optional)], libFLAC_prefix="$withval", libFLAC_prefix="")
@@ -14,21 +14,21 @@ AC_ARG_WITH(libFLAC-includes,[ --with-libFLAC-includes=DIR Directory where li
AC_ARG_ENABLE(libFLACtest, [ --disable-libFLACtest Do not try to compile and run a test libFLAC program],, enable_libFLACtest=yes)
if test "x$libFLAC_libraries" != "x" ; then
- LIBFLAC_LIBS="-L$libFLAC_libraries"
+ LIBFLAC_LIBDIR="$libFLAC_libraries"
elif test "x$libFLAC_prefix" != "x" ; then
- LIBFLAC_LIBS="-L$libFLAC_prefix/lib"
+ LIBFLAC_LIBDIR="$libFLAC_prefix/lib"
elif test "x$prefix" != "xNONE" ; then
- LIBFLAC_LIBS="-L$prefix/lib"
+ LIBFLAC_LIBDIR="$libdir"
fi
- LIBFLAC_LIBS="$LIBFLAC_LIBS -lFLAC -lm"
+ LIBFLAC_LIBS="-L$LIBFLAC_LIBDIR -lFLAC $OGG_LIBS -lm"
if test "x$libFLAC_includes" != "x" ; then
LIBFLAC_CFLAGS="-I$libFLAC_includes"
elif test "x$libFLAC_prefix" != "x" ; then
LIBFLAC_CFLAGS="-I$libFLAC_prefix/include"
elif test "x$prefix" != "xNONE"; then
- LIBFLAC_CFLAGS="-I$prefix/include"
+ LIBFLAC_CFLAGS=""
fi
AC_MSG_CHECKING(for libFLAC)
@@ -39,9 +39,11 @@ AC_ARG_ENABLE(libFLACtest, [ --disable-libFLACtest Do not try to compile
ac_save_CFLAGS="$CFLAGS"
ac_save_CXXFLAGS="$CXXFLAGS"
ac_save_LIBS="$LIBS"
+ ac_save_LDPATH="$LD_LIBRARY_PATH"
CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS"
LIBS="$LIBS $LIBFLAC_LIBS"
+ LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH"
dnl
dnl Now check if the installed libFLAC is sufficiently new.
dnl
@@ -60,7 +62,9 @@ int main ()
],, no_libFLAC=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
+ CXXFLAGS="$ac_save_CXXFLAGS"
LIBS="$ac_save_LIBS"
+ LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH"
fi
if test "x$no_libFLAC" = "x" ; then
@@ -73,7 +77,9 @@ int main ()
else
echo "*** Could not run libFLAC test program, checking why..."
CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
+ CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS"
LIBS="$LIBS $LIBFLAC_LIBS"
+ LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH"
AC_TRY_LINK([
#include <stdio.h>
#include <FLAC/format.h>
@@ -92,13 +98,17 @@ int main ()
echo "*** or that you have moved libFLAC since it was installed. In the latter case, you"
echo "*** may want to edit the libFLAC-config script: $LIBFLAC_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
+ CXXFLAGS="$ac_save_CXXFLAGS"
LIBS="$ac_save_LIBS"
+ LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH"
fi
LIBFLAC_CFLAGS=""
+ LIBFLAC_LIBDIR=""
LIBFLAC_LIBS=""
ifelse([$2], , :, [$2])
fi
AC_SUBST(LIBFLAC_CFLAGS)
+ AC_SUBST(LIBFLAC_LIBDIR)
AC_SUBST(LIBFLAC_LIBS)
rm -f conf.libFLACtest
])
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index e12ee80b9..49ddf82a7 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -33,13 +33,12 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <FLAC/seekable_stream_decoder.h>
+#include <FLAC/stream_decoder.h>
#include <FLAC/metadata.h>
/* this code is based on flac123, from flac-tools */
-static FLAC__SeekableStreamDecoderReadStatus flacRead(const
- FLAC__SeekableStreamDecoder
+static FLAC__StreamDecoderReadStatus flacRead(const FLAC__StreamDecoder
* flacDec,
FLAC__byte buf[],
unsigned *bytes,
@@ -58,14 +57,16 @@ static FLAC__SeekableStreamDecoderReadStatus flacRead(const
}
*bytes = r;
- if (*bytes == 0 && !inputStreamAtEOF(data->inStream) && !data->dc->stop)
- return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
-
- return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
+ if (r == 0 && !data->dc->stop) {
+ if (inputStreamAtEOF(data->inStream))
+ return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ else
+ return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+ }
+ return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
-static FLAC__SeekableStreamDecoderSeekStatus flacSeek(const
- FLAC__SeekableStreamDecoder
+static FLAC__StreamDecoderSeekStatus flacSeek(const FLAC__StreamDecoder
* flacDec,
FLAC__uint64 offset,
void *fdata)
@@ -73,14 +74,13 @@ static FLAC__SeekableStreamDecoderSeekStatus flacSeek(const
FlacData *data = (FlacData *) fdata;
if (seekInputStream(data->inStream, offset, SEEK_SET) < 0) {
- return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
+ return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
- return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
+ return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
}
-static FLAC__SeekableStreamDecoderTellStatus flacTell(const
- FLAC__SeekableStreamDecoder
+static FLAC__StreamDecoderTellStatus flacTell(const FLAC__StreamDecoder
* flacDec,
FLAC__uint64 * offset,
void *fdata)
@@ -89,11 +89,10 @@ static FLAC__SeekableStreamDecoderTellStatus flacTell(const
*offset = (long)(data->inStream->offset);
- return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
+ return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
-static FLAC__SeekableStreamDecoderLengthStatus flacLength(const
- FLAC__SeekableStreamDecoder
+static FLAC__StreamDecoderLengthStatus flacLength(const FLAC__StreamDecoder
* flacDec,
FLAC__uint64 * length,
void *fdata)
@@ -102,11 +101,10 @@ static FLAC__SeekableStreamDecoderLengthStatus flacLength(const
*length = (size_t) (data->inStream->size);
- return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
+ return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}
-static FLAC__bool flacEOF(const FLAC__SeekableStreamDecoder * flacDec,
- void *fdata)
+static FLAC__bool flacEOF(const FLAC__StreamDecoder * flacDec, void *fdata)
{
FlacData *data = (FlacData *) fdata;
@@ -115,51 +113,48 @@ static FLAC__bool flacEOF(const FLAC__SeekableStreamDecoder * flacDec,
return false;
}
-static void flacError(const FLAC__SeekableStreamDecoder * dec,
+static void flacError(const FLAC__StreamDecoder * dec,
FLAC__StreamDecoderErrorStatus status, void *fdata)
{
flac_error_common_cb("flac", status, (FlacData *) fdata);
}
-static void flacPrintErroredState(FLAC__SeekableStreamDecoderState state)
+static void flacPrintErroredState(FLAC__StreamDecoderState state)
{
+ const char *str = ""; /* "" to silence compiler warning */
switch (state) {
- case FLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
- ERROR("flac allocation error\n");
- break;
- case FLAC__SEEKABLE_STREAM_DECODER_READ_ERROR:
- ERROR("flac read error\n");
+ case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
+ case FLAC__STREAM_DECODER_READ_METADATA:
+ case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
+ case FLAC__STREAM_DECODER_READ_FRAME:
+ case FLAC__STREAM_DECODER_END_OF_STREAM:
+ return;
+ case FLAC__STREAM_DECODER_OGG_ERROR:
+ str = "error in the Ogg layer";
break;
- case FLAC__SEEKABLE_STREAM_DECODER_SEEK_ERROR:
- ERROR("flac seek error\n");
+ case FLAC__STREAM_DECODER_SEEK_ERROR:
+ str = "seek error";
break;
- case FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR:
- ERROR("flac seekable stream error\n");
+ case FLAC__STREAM_DECODER_ABORTED:
+ str = "decoder aborted by read";
break;
- case FLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED:
- ERROR("flac decoder already initialized\n");
+ case FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
+ str = "allocation error";
break;
- case FLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK:
- ERROR("invalid flac callback\n");
- break;
- case FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED:
- ERROR("flac decoder uninitialized\n");
- break;
- case FLAC__SEEKABLE_STREAM_DECODER_OK:
- case FLAC__SEEKABLE_STREAM_DECODER_SEEKING:
- case FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM:
+ case FLAC__STREAM_DECODER_UNINITIALIZED:
+ str = "decoder uninitialized";
break;
}
+ ERROR("flac %s\n", str);
}
-static void flacMetadata(const FLAC__SeekableStreamDecoder * dec,
+static void flacMetadata(const FLAC__StreamDecoder * dec,
const FLAC__StreamMetadata * block, void *vdata)
{
flac_metadata_common_cb(block, (FlacData *) vdata);
}
-static FLAC__StreamDecoderWriteStatus flacWrite(const
- FLAC__SeekableStreamDecoder *
+static FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__StreamDecoder *
dec, const FLAC__Frame * frame,
const FLAC__int32 * const buf[],
void *vdata)
@@ -176,7 +171,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const
timeChange = ((float)samples) / frame->header.sample_rate;
data->time += timeChange;
- FLAC__seekable_stream_decoder_get_decode_position(dec, &newPosition);
+ FLAC__stream_decoder_get_decode_position(dec, &newPosition);
if (data->position) {
data->bitRate =
((newPosition - data->position) * 8.0 / timeChange)
@@ -292,65 +287,27 @@ static MpdTag *flacTagDup(char *file)
static int flac_decode(OutputBuffer * cb, DecoderControl * dc,
InputStream * inStream)
{
- FLAC__SeekableStreamDecoder *flacDec = NULL;
+ FLAC__StreamDecoder *flacDec;
FlacData data;
- int status = 1;
int ret = 0;
+ if (!(flacDec = FLAC__stream_decoder_new()))
+ return -1;
init_FlacData(&data, cb, dc, inStream);
-
- if (!(flacDec = FLAC__seekable_stream_decoder_new())) {
- ret = -1;
- goto fail;
- }
- /*status&=FLAC__file_decoder_set_md5_checking(flacDec,1); */
- status &= FLAC__seekable_stream_decoder_set_read_callback(flacDec,
- flacRead);
- status &= FLAC__seekable_stream_decoder_set_seek_callback(flacDec,
- flacSeek);
- status &= FLAC__seekable_stream_decoder_set_tell_callback(flacDec,
- flacTell);
- status &= FLAC__seekable_stream_decoder_set_length_callback(flacDec,
- flacLength);
- status &=
- FLAC__seekable_stream_decoder_set_eof_callback(flacDec, flacEOF);
- status &=
- FLAC__seekable_stream_decoder_set_write_callback(flacDec,
- flacWrite);
- status &=
- FLAC__seekable_stream_decoder_set_metadata_callback(flacDec,
- flacMetadata);
- status &=
- FLAC__seekable_stream_decoder_set_metadata_respond(flacDec,
- FLAC__METADATA_TYPE_VORBIS_COMMENT);
- status &=
- FLAC__seekable_stream_decoder_set_error_callback(flacDec,
- flacError);
- status &=
- FLAC__seekable_stream_decoder_set_client_data(flacDec,
- (void *)&data);
- if (!status) {
- ERROR("flac problem before init()\n");
- flacPrintErroredState(FLAC__seekable_stream_decoder_get_state
- (flacDec));
- ret = -1;
- goto fail;
- }
-
- if (FLAC__seekable_stream_decoder_init(flacDec) !=
- FLAC__SEEKABLE_STREAM_DECODER_OK) {
+ if (FLAC__stream_decoder_init_stream(flacDec, flacRead, flacSeek,
+ flacTell, flacLength, flacEOF,
+ flacWrite, flacMetadata,
+ flacError, (void *)&data)
+ != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
ERROR("flac problem doing init()\n");
- flacPrintErroredState(FLAC__seekable_stream_decoder_get_state
- (flacDec));
+ flacPrintErroredState(FLAC__stream_decoder_get_state(flacDec));
ret = -1;
goto fail;
}
- if (!FLAC__seekable_stream_decoder_process_until_end_of_metadata
- (flacDec)) {
+ if (!FLAC__stream_decoder_process_until_end_of_metadata(flacDec)) {
ERROR("flac problem reading metadata\n");
- flacPrintErroredState(FLAC__seekable_stream_decoder_get_state
- (flacDec));
+ flacPrintErroredState(FLAC__stream_decoder_get_state(flacDec));
ret = -1;
goto fail;
}
@@ -358,16 +315,16 @@ static int flac_decode(OutputBuffer * cb, DecoderControl * dc,
dc->state = DECODE_STATE_DECODE;
while (1) {
- FLAC__seekable_stream_decoder_process_single(flacDec);
- if (FLAC__seekable_stream_decoder_get_state(flacDec) !=
- FLAC__SEEKABLE_STREAM_DECODER_OK) {
+ if (!FLAC__stream_decoder_process_single(flacDec))
+ break;
+ if (FLAC__stream_decoder_get_state(flacDec) ==
+ FLAC__STREAM_DECODER_END_OF_STREAM)
break;
- }
if (dc->seek) {
FLAC__uint64 sampleToSeek = dc->seekWhere *
dc->audioFormat.sampleRate + 0.5;
- if (FLAC__seekable_stream_decoder_seek_absolute(flacDec,
- sampleToSeek))
+ if (FLAC__stream_decoder_seek_absolute(flacDec,
+ sampleToSeek))
{
clearOutputBuffer(cb);
data.time = ((float)sampleToSeek) /
@@ -378,12 +335,9 @@ static int flac_decode(OutputBuffer * cb, DecoderControl * dc,
dc->seek = 0;
}
}
- /* I don't think we need this bit here! -shank */
- /*FLAC__file_decoder_process_until_end_of_file(flacDec); */
if (!dc->stop) {
- flacPrintErroredState(FLAC__seekable_stream_decoder_get_state
- (flacDec));
- FLAC__seekable_stream_decoder_finish(flacDec);
+ flacPrintErroredState(FLAC__stream_decoder_get_state(flacDec));
+ FLAC__stream_decoder_finish(flacDec);
}
/* send last little bit */
if (data.chunk_length > 0 && !dc->stop) {
@@ -404,7 +358,7 @@ fail:
freeReplayGainInfo(data.replayGainInfo);
if (flacDec)
- FLAC__seekable_stream_decoder_delete(flacDec);
+ FLAC__stream_decoder_delete(flacDec);
closeInputStream(inStream);