Commit 68fd0eca authored by Josh Coalson's avatar Josh Coalson Committed by Sebastian Dröge
Browse files

Add support for flac >= 1.1.3 which changed the API. Fixes bug #385887.

Original commit message from CVS:
Patch by: Josh Coalson <xflac at yahoo dot com>,
updated by Alexis Ballier <aballier at gentoo dot org>:
* configure.ac:
* ext/flac/gstflacdec.c: (gst_flac_dec_reset_decoders),
(gst_flac_dec_setup_seekable_decoder),
(gst_flac_dec_setup_stream_decoder), (gst_flac_dec_seek),
(gst_flac_dec_tell), (gst_flac_dec_length), (gst_flac_dec_eof),
(gst_flac_dec_read_seekable), (gst_flac_dec_read_stream):
* ext/flac/gstflacdec.h:
* ext/flac/gstflacenc.c: (gst_flac_enc_init),
(gst_flac_enc_finalize), (gst_flac_enc_set_metadata),
(gst_flac_enc_sink_setcaps), (gst_flac_enc_update_quality),
(gst_flac_enc_seek_callback), (gst_flac_enc_write_callback),
(gst_flac_enc_tell_callback), (gst_flac_enc_sink_event),
(gst_flac_enc_chain), (gst_flac_enc_set_property),
(gst_flac_enc_get_property), (gst_flac_enc_change_state):
* ext/flac/gstflacenc.h:
Add support for flac >= 1.1.3 which changed the API. Fixes bug #385887.
parent f2fa0a91
2007-06-10 Sebastian Dröge <slomo@circular-chaos.org>
Patch by: Josh Coalson <xflac at yahoo dot com>,
updated by Alexis Ballier <aballier at gentoo dot org>:
* configure.ac:
* ext/flac/gstflacdec.c: (gst_flac_dec_reset_decoders),
(gst_flac_dec_setup_seekable_decoder),
(gst_flac_dec_setup_stream_decoder), (gst_flac_dec_seek),
(gst_flac_dec_tell), (gst_flac_dec_length), (gst_flac_dec_eof),
(gst_flac_dec_read_seekable), (gst_flac_dec_read_stream):
* ext/flac/gstflacdec.h:
* ext/flac/gstflacenc.c: (gst_flac_enc_init),
(gst_flac_enc_finalize), (gst_flac_enc_set_metadata),
(gst_flac_enc_sink_setcaps), (gst_flac_enc_update_quality),
(gst_flac_enc_seek_callback), (gst_flac_enc_write_callback),
(gst_flac_enc_tell_callback), (gst_flac_enc_sink_event),
(gst_flac_enc_chain), (gst_flac_enc_set_property),
(gst_flac_enc_get_property), (gst_flac_enc_change_state):
* ext/flac/gstflacenc.h:
Add support for flac >= 1.1.3 which changed the API. Fixes bug #385887.
2007-06-09 Sebastian Dröge <slomo@circular-chaos.org>
* ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_sink_set_caps):
......
......@@ -652,11 +652,16 @@ AG_GST_CHECK_FEATURE(ESD, [ESounD sound daemon], esdsink, [
dnl *** FLAC ***
translit(dnm, m, l) AM_CONDITIONAL(USE_FLAC, true)
AC_TRY_RUN([
#include <FLAC/export.h>
int main () { return FLAC_API_VERSION_CURRENT<8; }
],legacy_flac=no,legacy_flac=yes,legacy_flac=no)
if test "x$legacy_flac" = "xyes"; then
AG_GST_CHECK_FEATURE(FLAC, [FLAC lossless audio], flac, [
AG_GST_CHECK_LIBHEADER(FLAC, FLAC, FLAC__seekable_stream_encoder_new, -lm, FLAC/all.h, FLAC_LIBS="-lFLAC -lm")
dnl API change in FLAC 1.1.1, so require that...
dnl (this check will also fail with FLAC 1.1.3 which changed API again
dnl and with which our plugin does not compile or work yet)
dnl (this check will also fail with FLAC 1.1.3 which changed API again)
if test x$HAVE_FLAC = xyes; then
AC_CHECK_DECL(FLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR,
HAVE_FLAC="yes", HAVE_FLAC="no", [
......@@ -665,6 +670,19 @@ AG_GST_CHECK_FEATURE(FLAC, [FLAC lossless audio], flac, [
fi
AC_SUBST(FLAC_LIBS)
])
else
AG_GST_CHECK_FEATURE(FLAC, [FLAC lossless audio], flac, [
AG_GST_CHECK_LIBHEADER(FLAC, FLAC, FLAC__stream_encoder_new, -lm, FLAC/all.h, FLAC_LIBS="-lFLAC -lm")
dnl API change in FLAC 1.1.3, so require that...
if test x$HAVE_FLAC = xyes; then
AC_CHECK_DECL(FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
HAVE_FLAC="yes", HAVE_FLAC="no", [
#include <FLAC/stream_encoder.h>
])
fi
AC_SUBST(FLAC_LIBS)
])
fi
dnl *** GConf ***
translit(dnm, m, l) AM_CONDITIONAL(USE_GCONF, true)
......
......@@ -94,6 +94,7 @@ static void gst_flac_dec_reset_decoders (GstFlacDec * flacdec);
static void gst_flac_dec_setup_seekable_decoder (GstFlacDec * flacdec);
static void gst_flac_dec_setup_stream_decoder (GstFlacDec * flacdec);
#ifdef LEGACY_FLAC
static FLAC__SeekableStreamDecoderReadStatus
gst_flac_dec_read_seekable (const FLAC__SeekableStreamDecoder * decoder,
FLAC__byte buffer[], unsigned *bytes, void *client_data);
......@@ -131,6 +132,33 @@ static void gst_flac_dec_error_callback_seekable (const
FLAC__StreamDecoderErrorStatus status, void *client_data);
static void gst_flac_dec_error_callback_stream (const FLAC__StreamDecoder *
decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
#else
static FLAC__StreamDecoderReadStatus
gst_flac_dec_read_seekable (const FLAC__StreamDecoder * decoder,
FLAC__byte buffer[], size_t * bytes, void *client_data);
static FLAC__StreamDecoderReadStatus
gst_flac_dec_read_stream (const FLAC__StreamDecoder * decoder,
FLAC__byte buffer[], size_t * bytes, void *client_data);
static FLAC__StreamDecoderSeekStatus
gst_flac_dec_seek (const FLAC__StreamDecoder * decoder,
FLAC__uint64 position, void *client_data);
static FLAC__StreamDecoderTellStatus
gst_flac_dec_tell (const FLAC__StreamDecoder * decoder,
FLAC__uint64 * position, void *client_data);
static FLAC__StreamDecoderLengthStatus
gst_flac_dec_length (const FLAC__StreamDecoder * decoder,
FLAC__uint64 * length, void *client_data);
static FLAC__bool gst_flac_dec_eof (const FLAC__StreamDecoder * decoder,
void *client_data);
static FLAC__StreamDecoderWriteStatus
gst_flac_dec_write_stream (const FLAC__StreamDecoder * decoder,
const FLAC__Frame * frame,
const FLAC__int32 * const buffer[], void *client_data);
static void gst_flac_dec_metadata_callback_stream (const FLAC__StreamDecoder *
decoder, const FLAC__StreamMetadata * metadata, void *client_data);
static void gst_flac_dec_error_callback_stream (const FLAC__StreamDecoder *
decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
#endif
GST_BOILERPLATE (GstFlacDec, gst_flac_dec, GstElement, GST_TYPE_ELEMENT);
#define GST_FLAC_DEC_SRC_CAPS \
......@@ -213,7 +241,11 @@ static void
gst_flac_dec_reset_decoders (GstFlacDec * flacdec)
{
if (flacdec->seekable_decoder) {
#ifdef LEGACY_FLAC
FLAC__seekable_stream_decoder_delete (flacdec->seekable_decoder);
#else
FLAC__stream_decoder_delete (flacdec->seekable_decoder);
#endif
flacdec->seekable_decoder = NULL;
}
......@@ -239,6 +271,7 @@ gst_flac_dec_setup_seekable_decoder (GstFlacDec * dec)
{
gst_flac_dec_reset_decoders (dec);
#ifdef LEGACY_FLAC
dec->seekable_decoder = FLAC__seekable_stream_decoder_new ();
FLAC__seekable_stream_decoder_set_read_callback (dec->seekable_decoder,
......@@ -260,6 +293,12 @@ gst_flac_dec_setup_seekable_decoder (GstFlacDec * dec)
FLAC__seekable_stream_decoder_set_error_callback (dec->seekable_decoder,
gst_flac_dec_error_callback_seekable);
FLAC__seekable_stream_decoder_set_client_data (dec->seekable_decoder, dec);
#else
dec->seekable_decoder = FLAC__stream_decoder_new ();
FLAC__stream_decoder_set_metadata_respond (dec->seekable_decoder,
FLAC__METADATA_TYPE_VORBIS_COMMENT);
FLAC__stream_decoder_set_md5_checking (dec->seekable_decoder, false); /* no point calculating since it's never checked here */
#endif
}
static void
......@@ -271,6 +310,7 @@ gst_flac_dec_setup_stream_decoder (GstFlacDec * dec)
dec->stream_decoder = FLAC__stream_decoder_new ();
#ifdef LEGACY_FLAC
FLAC__stream_decoder_set_read_callback (dec->stream_decoder,
gst_flac_dec_read_stream);
FLAC__stream_decoder_set_write_callback (dec->stream_decoder,
......@@ -282,6 +322,11 @@ gst_flac_dec_setup_stream_decoder (GstFlacDec * dec)
FLAC__stream_decoder_set_error_callback (dec->stream_decoder,
gst_flac_dec_error_callback_stream);
FLAC__stream_decoder_set_client_data (dec->stream_decoder, dec);
#else
FLAC__stream_decoder_set_md5_checking (dec->stream_decoder, false); /* no point calculating since it's never checked here */
FLAC__stream_decoder_set_metadata_respond (dec->stream_decoder,
FLAC__METADATA_TYPE_VORBIS_COMMENT);
#endif
}
static void
......@@ -545,6 +590,7 @@ gst_flac_dec_metadata_callback (GstFlacDec * flacdec,
}
}
#ifdef LEGACY_FLAC
static void
gst_flac_dec_metadata_callback_seekable (const FLAC__SeekableStreamDecoder * d,
const FLAC__StreamMetadata * metadata, void *client_data)
......@@ -553,6 +599,7 @@ gst_flac_dec_metadata_callback_seekable (const FLAC__SeekableStreamDecoder * d,
gst_flac_dec_metadata_callback (dec, metadata);
}
#endif
static void
gst_flac_dec_metadata_callback_stream (const FLAC__StreamDecoder * decoder,
......@@ -588,12 +635,14 @@ gst_flac_dec_error_callback (GstFlacDec * dec,
dec->last_flow = GST_FLOW_ERROR;
}
#ifdef LEGACY_FLAC
static void
gst_flac_dec_error_callback_seekable (const FLAC__SeekableStreamDecoder * d,
FLAC__StreamDecoderErrorStatus status, void *client_data)
{
gst_flac_dec_error_callback (GST_FLAC_DEC (client_data), status);
}
#endif
static void
gst_flac_dec_error_callback_stream (const FLAC__StreamDecoder * d,
......@@ -602,9 +651,15 @@ gst_flac_dec_error_callback_stream (const FLAC__StreamDecoder * d,
gst_flac_dec_error_callback (GST_FLAC_DEC (client_data), status);
}
#ifdef LEGACY_FLAC
static FLAC__SeekableStreamDecoderSeekStatus
gst_flac_dec_seek (const FLAC__SeekableStreamDecoder * decoder,
FLAC__uint64 position, void *client_data)
#else
static FLAC__StreamDecoderSeekStatus
gst_flac_dec_seek (const FLAC__StreamDecoder * decoder,
FLAC__uint64 position, void *client_data)
#endif
{
GstFlacDec *flacdec;
......@@ -613,12 +668,22 @@ gst_flac_dec_seek (const FLAC__SeekableStreamDecoder * decoder,
GST_DEBUG ("seek %" G_GINT64_FORMAT, position);
flacdec->offset = position;
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
#else
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
#endif
}
#ifdef LEGACY_FLAC
static FLAC__SeekableStreamDecoderTellStatus
gst_flac_dec_tell (const FLAC__SeekableStreamDecoder * decoder,
FLAC__uint64 * position, void *client_data)
#else
static FLAC__StreamDecoderTellStatus
gst_flac_dec_tell (const FLAC__StreamDecoder * decoder,
FLAC__uint64 * position, void *client_data)
#endif
{
GstFlacDec *flacdec;
......@@ -628,12 +693,22 @@ gst_flac_dec_tell (const FLAC__SeekableStreamDecoder * decoder,
GST_DEBUG ("tell %" G_GINT64_FORMAT, *position);
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
#else
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
#endif
}
#ifdef LEGACY_FLAC
static FLAC__SeekableStreamDecoderLengthStatus
gst_flac_dec_length (const FLAC__SeekableStreamDecoder * decoder,
FLAC__uint64 * length, void *client_data)
#else
static FLAC__StreamDecoderLengthStatus
gst_flac_dec_length (const FLAC__StreamDecoder * decoder,
FLAC__uint64 * length, void *client_data)
#endif
{
GstFlacDec *flacdec;
GstFormat fmt = GST_FORMAT_BYTES;
......@@ -643,22 +718,39 @@ gst_flac_dec_length (const FLAC__SeekableStreamDecoder * decoder,
flacdec = GST_FLAC_DEC (client_data);
if (!(peer = gst_pad_get_peer (flacdec->sinkpad)))
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
#else
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
#endif
gst_pad_query_duration (peer, &fmt, &len);
gst_object_unref (peer);
if (fmt != GST_FORMAT_BYTES || len == -1)
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
#else
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
#endif
*length = len;
GST_DEBUG ("length %" G_GINT64_FORMAT, *length);
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
#else
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
#endif
}
#ifdef LEGACY_FLAC
static FLAC__bool
gst_flac_dec_eof (const FLAC__SeekableStreamDecoder * decoder,
void *client_data)
#else
static FLAC__bool
gst_flac_dec_eof (const FLAC__StreamDecoder * decoder, void *client_data)
#endif
{
GstFlacDec *flacdec;
GstFormat fmt;
......@@ -686,9 +778,15 @@ gst_flac_dec_eof (const FLAC__SeekableStreamDecoder * decoder,
return ret;
}
#ifdef LEGACY_FLAC
static FLAC__SeekableStreamDecoderReadStatus
gst_flac_dec_read_seekable (const FLAC__SeekableStreamDecoder * decoder,
FLAC__byte buffer[], unsigned *bytes, void *client_data)
#else
static FLAC__StreamDecoderReadStatus
gst_flac_dec_read_seekable (const FLAC__StreamDecoder * decoder,
FLAC__byte buffer[], size_t * bytes, void *client_data)
#endif
{
GstFlacDec *flacdec;
GstBuffer *buf;
......@@ -697,7 +795,11 @@ gst_flac_dec_read_seekable (const FLAC__SeekableStreamDecoder * decoder,
if (gst_pad_pull_range (flacdec->sinkpad, flacdec->offset, *bytes,
&buf) != GST_FLOW_OK)
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
#else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
#endif
GST_DEBUG ("Read %d bytes at %" G_GUINT64_FORMAT,
GST_BUFFER_SIZE (buf), flacdec->offset);
......@@ -706,12 +808,22 @@ gst_flac_dec_read_seekable (const FLAC__SeekableStreamDecoder * decoder,
gst_buffer_unref (buf);
flacdec->offset += *bytes;
#ifdef LEGACY_FLAC
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
#else
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
#endif
}
#ifdef LEGACY_FLAC
static FLAC__StreamDecoderReadStatus
gst_flac_dec_read_stream (const FLAC__StreamDecoder * decoder,
FLAC__byte buffer[], unsigned *bytes, void *client_data)
#else
static FLAC__StreamDecoderReadStatus
gst_flac_dec_read_stream (const FLAC__StreamDecoder * decoder,
FLAC__byte buffer[], size_t * bytes, void *client_data)
#endif
{
GstFlacDec *dec = GST_FLAC_DEC (client_data);
guint len;
......@@ -881,6 +993,7 @@ done:
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
#ifdef LEGACY_FLAC
static FLAC__StreamDecoderWriteStatus
gst_flac_dec_write_seekable (const FLAC__SeekableStreamDecoder * decoder,
const FLAC__Frame * frame,
......@@ -888,6 +1001,7 @@ gst_flac_dec_write_seekable (const FLAC__SeekableStreamDecoder * decoder,
{
return gst_flac_dec_write (GST_FLAC_DEC (client_data), frame, buffer);
}
#endif
static FLAC__StreamDecoderWriteStatus
gst_flac_dec_write_stream (const FLAC__StreamDecoder * decoder,
......@@ -901,7 +1015,13 @@ static void
gst_flac_dec_loop (GstPad * sinkpad)
{
GstFlacDec *flacdec;
#ifdef LEGACY_FLAC
FLAC__SeekableStreamDecoderState s;
#else
FLAC__StreamDecoderState s;
FLAC__StreamDecoderInitStatus is;
#endif
flacdec = GST_FLAC_DEC (GST_OBJECT_PARENT (sinkpad));
......@@ -909,9 +1029,19 @@ gst_flac_dec_loop (GstPad * sinkpad)
if (flacdec->init) {
GST_DEBUG_OBJECT (flacdec, "initializing decoder");
#ifdef LEGACY_FLAC
s = FLAC__seekable_stream_decoder_init (flacdec->seekable_decoder);
if (s != FLAC__SEEKABLE_STREAM_DECODER_OK)
goto analyze_state;
#else
is = FLAC__stream_decoder_init_stream (flacdec->seekable_decoder,
gst_flac_dec_read_seekable, gst_flac_dec_seek, gst_flac_dec_tell,
gst_flac_dec_length, gst_flac_dec_eof, gst_flac_dec_write_stream,
gst_flac_dec_metadata_callback_stream,
gst_flac_dec_error_callback_stream, flacdec);
if (is != FLAC__STREAM_DECODER_INIT_STATUS_OK)
goto analyze_state;
#endif
/* FLAC__seekable_stream_decoder_process_metadata (flacdec->seekable_decoder); */
flacdec->init = FALSE;
}
......@@ -921,15 +1051,30 @@ gst_flac_dec_loop (GstPad * sinkpad)
flacdec->last_flow = GST_FLOW_OK;
GST_LOG_OBJECT (flacdec, "processing single");
#ifdef LEGACY_FLAC
FLAC__seekable_stream_decoder_process_single (flacdec->seekable_decoder);
#else
FLAC__stream_decoder_process_single (flacdec->seekable_decoder);
#endif
analyze_state:
GST_LOG_OBJECT (flacdec, "done processing, checking encoder state");
#ifdef LEGACY_FLAC
s = FLAC__seekable_stream_decoder_get_state (flacdec->seekable_decoder);
#else
s = FLAC__stream_decoder_get_state (flacdec->seekable_decoder);
#endif
switch (s) {
#ifdef LEGACY_FLAC
case FLAC__SEEKABLE_STREAM_DECODER_OK:
case FLAC__SEEKABLE_STREAM_DECODER_SEEKING:{
case FLAC__SEEKABLE_STREAM_DECODER_SEEKING:
#else
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:
#endif
{
GST_DEBUG_OBJECT (flacdec, "everything ok");
if (GST_FLOW_IS_FATAL (flacdec->last_flow) ||
......@@ -961,9 +1106,17 @@ analyze_state:
return;
}
#ifdef LEGACY_FLAC
case FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM:{
#else
case FLAC__STREAM_DECODER_END_OF_STREAM:{
#endif
GST_DEBUG_OBJECT (flacdec, "EOS");
#ifdef LEGACY_FLAC
FLAC__seekable_stream_decoder_reset (flacdec->seekable_decoder);
#else
FLAC__stream_decoder_reset (flacdec->seekable_decoder);
#endif
if ((flacdec->segment.flags & GST_SEEK_FLAG_SEGMENT) != 0) {
if (flacdec->segment.duration > 0) {
......@@ -977,6 +1130,7 @@ analyze_state:
goto eos_and_pause;
}
#ifdef LEGACY_FLAC
case FLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
case FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR:
case FLAC__SEEKABLE_STREAM_DECODER_READ_ERROR:
......@@ -984,11 +1138,23 @@ analyze_state:
case FLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED:
case FLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK:
case FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED:
#else
case FLAC__STREAM_DECODER_OGG_ERROR:
case FLAC__STREAM_DECODER_SEEK_ERROR:
case FLAC__STREAM_DECODER_ABORTED:
case FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
case FLAC__STREAM_DECODER_UNINITIALIZED:
#endif
default:{
/* fixme: this error sucks -- should try to figure out when/if an more
specific error was already sent via the callback */
#ifdef LEGACY_FLAC
GST_ELEMENT_ERROR (flacdec, STREAM, DECODE, (NULL),
("%s", FLAC__SeekableStreamDecoderStateString[s]));
#else
GST_ELEMENT_ERROR (flacdec, STREAM, DECODE, (NULL),
("%s", FLAC__StreamDecoderStateString[s]));
#endif
goto eos_and_pause;
}
}
......@@ -1106,7 +1272,11 @@ gst_flac_dec_sink_event (GstPad * pad, GstEvent * event)
static GstFlowReturn
gst_flac_dec_chain (GstPad * pad, GstBuffer * buf)
{
#ifdef LEGACY_FLAC
FLAC__StreamDecoderState s;
#else
FLAC__StreamDecoderInitStatus s;
#endif
GstFlacDec *dec;
gboolean got_audio_frame;
......@@ -1118,11 +1288,22 @@ gst_flac_dec_chain (GstPad * pad, GstBuffer * buf)
if (dec->init) {
GST_DEBUG_OBJECT (dec, "initializing decoder");
#ifdef LEGACY_FLAC
s = FLAC__stream_decoder_init (dec->stream_decoder);
if (s != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) {
GST_ELEMENT_ERROR (GST_ELEMENT (dec), LIBRARY, INIT, (NULL), (NULL));
return GST_FLOW_ERROR;
}
#else
s = FLAC__stream_decoder_init_stream (dec->stream_decoder,
gst_flac_dec_read_stream, NULL, NULL, NULL, NULL,
gst_flac_dec_write_stream, gst_flac_dec_metadata_callback_stream,
gst_flac_dec_error_callback_stream, dec);
if (s != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
GST_ELEMENT_ERROR (GST_ELEMENT (dec), LIBRARY, INIT, (NULL), (NULL));
return GST_FLOW_ERROR;
}
#endif
GST_DEBUG_OBJECT (dec, "initialized (framed=%d)", dec->framed);
dec->init = FALSE;
}
......@@ -1603,8 +1784,13 @@ gst_flac_dec_handle_seek_event (GstFlacDec * flacdec, GstEvent * event)
flacdec->seeking = TRUE;
seek_ok =
#ifdef LEGACY_FLAC
FLAC__seekable_stream_decoder_seek_absolute (flacdec->seekable_decoder,
segment.start);
#else
FLAC__stream_decoder_seek_absolute (flacdec->seekable_decoder,
segment.start);
#endif
flacdec->seeking = FALSE;
......
......@@ -27,6 +27,12 @@
#include <FLAC/all.h>
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8
#define LEGACY_FLAC
#else
#undef LEGACY_FLAC
#endif
G_BEGIN_DECLS
#define GST_TYPE_FLAC_DEC gst_flac_dec_get_type()
......@@ -41,7 +47,11 @@ typedef struct _GstFlacDecClass GstFlacDecClass;
struct _GstFlacDec {
GstElement element;
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8
FLAC__SeekableStreamDecoder *seekable_decoder; /* for pull-based operation */
#else
FLAC__StreamDecoder *seekable_decoder; /* for pull-based operation */
#endif
FLAC__StreamDecoder *stream_decoder; /* for chain-based operation */
GstAdapter *adapter;
......
......@@ -113,6 +113,7 @@ static void gst_flac_enc_get_property (GObject * object, guint prop_id,
static GstStateChangeReturn gst_flac_enc_change_state (GstElement * element,
GstStateChange transition);
#ifdef LEGACY_FLAC
static FLAC__StreamEncoderWriteStatus
gst_flac_enc_write_callback (const FLAC__SeekableStreamEncoder * encoder,
const FLAC__byte buffer[], unsigned bytes,
......@@ -123,6 +124,18 @@ gst_flac_enc_seek_callback (const FLAC__SeekableStreamEncoder * encoder,
static FLAC__SeekableStreamEncoderTellStatus
gst_flac_enc_tell_callback (const FLAC__SeekableStreamEncoder * encoder,
FLAC__uint64 * absolute_byte_offset, void *client_data);
#else
static FLAC__StreamEncoderWriteStatus
gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
const FLAC__byte buffer[], size_t bytes,
unsigned samples, unsigned current_frame, void *client_data);
static FLAC__StreamEncoderSeekStatus
gst_flac_enc_seek_callback (const FLAC__StreamEncoder * encoder,
FLAC__uint64 absolute_byte_offset, void *client_data);
static FLAC__StreamEncoderTellStatus
gst_flac_enc_tell_callback (const FLAC__StreamEncoder * encoder,
FLAC__uint64 * absolute_byte_offset, void *client_data);
#endif
typedef struct
{
......@@ -307,7 +320,11 @@ gst_flac_enc_init (GstFlacEnc * flacenc, GstFlacEncClass * klass)
gst_pad_use_fixed_caps (flacenc->srcpad);
gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->srcpad);
#ifdef LEGACY_FLAC
flacenc->encoder = FLAC__seekable_stream_encoder_new ();
#else
flacenc->encoder = FLAC__stream_encoder_new ();
#endif
flacenc->offset = 0;
flacenc->samples_written = 0;
......@@ -323,7 +340,11 @@ gst_flac_enc_finalize (GObject * object)
GstFlacEnc *flacenc = GST_FLAC_ENC (object);
gst_tag_list_free (flacenc->tags);
#ifdef LEGACY_FLAC
FLAC__seekable_stream_encoder_delete (flacenc->encoder);
#else
FLAC__stream_encoder_delete (flacenc->encoder);
#endif
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -368,8 +389,13 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc)
FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT);
gst_tag_list_foreach (copy, add_one_tag, flacenc);
#ifdef LEGACY_FLAC
if (FLAC__seekable_stream_encoder_set_metadata (flacenc->encoder,
flacenc->meta, 1) != true)
#else
if (FLAC__stream_encoder_set_metadata (flacenc->encoder,
flacenc->meta, 1) != true)
#endif
g_warning ("Dude, i'm already initialized!");
gst_tag_list_free (copy);
}
......@@ -379,13 +405,24 @@ gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
{
GstFlacEnc *flacenc;
GstStructure *structure;
#ifdef LEGACY_FLAC
FLAC__SeekableStreamEncoderState state;
#else
FLAC__StreamEncoderInitStatus init_status;
#endif
gint depth, chans, rate, width;
flacenc = GST_FLAC_ENC (gst_pad_get_parent (pad));
#ifdef LEGACY_FLAC
if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) !=
FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED)
#else
if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
FLAC__STREAM_ENCODER_UNINITIALIZED)
#endif
goto encoder_already_initialized;
structure = gst_caps_get_structure (caps, 0);
......@@ -411,6 +448,7 @@ gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
gst_caps_unref (caps);
#ifdef LEGACY_FLAC
FLAC__seekable_stream_encoder_set_bits_per_sample (flacenc->encoder,
flacenc->depth);
FLAC__seekable_stream_encoder_set_sample_rate (flacenc->encoder,
......@@ -426,12 +464,25 @@ gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
gst_flac_enc_tell_callback);
FLAC__seekable_stream_encoder_set_client_data (flacenc->encoder, flacenc);
#else
FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder, flacenc->depth);
FLAC__stream_encoder_set_sample_rate (flacenc->encoder, flacenc->sample_rate);