diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2008-04-24 22:19:48 +0000 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2008-04-24 22:19:48 +0000 |
commit | 01bcb096c75d8f4264390b8afb6f307ca97e23f0 (patch) | |
tree | 13bd3fd207bbeca69c3186ffc991510cbc0cbf1e /ext/musepack | |
parent | 36d15d78686e14036677ccb1e6c4a98f287b6073 (diff) | |
download | gst-plugins-bad-01bcb096c75d8f4264390b8afb6f307ca97e23f0.tar.gz gst-plugins-bad-01bcb096c75d8f4264390b8afb6f307ca97e23f0.tar.bz2 gst-plugins-bad-01bcb096c75d8f4264390b8afb6f307ca97e23f0.zip |
Add support for the new libmpcdec API which magically gets us support for SV8 files. Also do some random cleanup. Fix...
Original commit message from CVS:
* configure.ac:
* ext/musepack/gstmusepackdec.c: (gst_musepackdec_base_init),
(gst_musepackdec_init), (gst_musepackdec_dispose),
(gst_musepackdec_handle_seek_event), (gst_musepack_stream_init),
(gst_musepackdec_loop), (plugin_init):
* ext/musepack/gstmusepackdec.h:
* ext/musepack/gstmusepackreader.c:
* ext/musepack/gstmusepackreader.h:
Add support for the new libmpcdec API which magically gets us support
for SV8 files. Also do some random cleanup. Fixes bug #526905.
Diffstat (limited to 'ext/musepack')
-rw-r--r-- | ext/musepack/gstmusepackdec.c | 73 | ||||
-rw-r--r-- | ext/musepack/gstmusepackdec.h | 9 | ||||
-rw-r--r-- | ext/musepack/gstmusepackreader.c | 65 | ||||
-rw-r--r-- | ext/musepack/gstmusepackreader.h | 5 |
4 files changed, 128 insertions, 24 deletions
diff --git a/ext/musepack/gstmusepackdec.c b/ext/musepack/gstmusepackdec.c index caba5f17..fea4bc05 100644 --- a/ext/musepack/gstmusepackdec.c +++ b/ext/musepack/gstmusepackdec.c @@ -1,6 +1,7 @@ /* GStreamer Musepack decoder plugin * Copyright (C) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net> * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> + * Copyright (C) 2008 Sebastian Dröge <slomo@circular-chaos.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,16 +29,14 @@ GST_DEBUG_CATEGORY (musepackdec_debug); #define GST_CAT_DEFAULT musepackdec_debug -static const GstElementDetails gst_musepackdec_details = -GST_ELEMENT_DETAILS ("Musepack decoder", - "Codec/Decoder/Audio", - "Musepack decoder", - "Ronald Bultje <rbultje@ronald.bitfreak.net>"); - static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-musepack") +#ifdef MPC_IS_OLD_API + GST_STATIC_CAPS ("audio/x-musepack, streamversion = (int) 7") +#else + GST_STATIC_CAPS ("audio/x-musepack, streamversion = (int) { 7, 8 }") +#endif ); #ifdef MPC_FIXED_POINT @@ -85,9 +84,9 @@ gst_musepackdec_base_init (gpointer klass) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_template)); - gst_element_class_set_details (element_class, &gst_musepackdec_details); - - GST_DEBUG_CATEGORY_INIT (musepackdec_debug, "musepackdec", 0, "mpc decoder"); + gst_element_class_set_details_simple (element_class, "Musepack decoder", + "Codec/Decoder/Audio", + "Musepack decoder", "Ronald Bultje <rbultje@ronald.bitfreak.net>"); } static void @@ -107,7 +106,9 @@ gst_musepackdec_init (GstMusepackDec * musepackdec, GstMusepackDecClass * klass) musepackdec->bps = 0; musepackdec->r = g_new (mpc_reader, 1); +#ifdef MPC_IS_OLD_API musepackdec->d = g_new (mpc_decoder, 1); +#endif musepackdec->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); @@ -135,8 +136,16 @@ gst_musepackdec_dispose (GObject * obj) g_free (musepackdec->r); musepackdec->r = NULL; + +#ifdef MPC_IS_OLD_API g_free (musepackdec->d); musepackdec->d = NULL; +#else + if (musepackdec->d) { + mpc_demux_exit (musepackdec->d); + musepackdec->d = NULL; + } +#endif G_OBJECT_CLASS (parent_class)->dispose (obj); } @@ -221,9 +230,13 @@ gst_musepackdec_handle_seek_event (GstMusepackDec * dec, GstEvent * event) GST_WARNING_OBJECT (dec, "seek out of bounds"); goto failed; } - +#ifdef MPC_IS_OLD_API if (!mpc_decoder_seek_sample (dec->d, segment.start)) goto failed; +#else + if (mpc_demux_seek_sample (dec->d, segment.start) != MPC_STATUS_OK) + goto failed; +#endif if ((flags & GST_SEEK_FLAG_SEGMENT) == GST_SEEK_FLAG_SEGMENT) { GST_DEBUG_OBJECT (dec, "posting SEGMENT_START message"); @@ -365,6 +378,7 @@ gst_musepack_stream_init (GstMusepackDec * musepackdec) /* set up reading */ gst_musepack_init_reader (musepackdec->r, musepackdec); +#ifdef MPC_IS_OLD_API /* streaminfo */ mpc_streaminfo_init (&i); if (mpc_streaminfo_read (&i, musepackdec->r) < 0) { @@ -379,6 +393,15 @@ gst_musepack_stream_init (GstMusepackDec * musepackdec) GST_ELEMENT_ERROR (musepackdec, STREAM, WRONG_TYPE, (NULL), (NULL)); return FALSE; } +#else + musepackdec->d = mpc_demux_init (musepackdec->r); + if (!musepackdec->d) { + GST_ELEMENT_ERROR (musepackdec, STREAM, WRONG_TYPE, (NULL), (NULL)); + return FALSE; + } + + mpc_demux_get_info (musepackdec->d, &i); +#endif /* capsnego */ caps = gst_caps_from_string (BASE_CAPS); @@ -392,8 +415,8 @@ gst_musepack_stream_init (GstMusepackDec * musepackdec) return FALSE; } - gst_atomic_int_set (&musepackdec->bps, 4 * i.channels); - gst_atomic_int_set (&musepackdec->rate, i.sample_freq); + g_atomic_int_set (&musepackdec->bps, 4 * i.channels); + g_atomic_int_set (&musepackdec->rate, i.sample_freq); gst_segment_set_last_stop (&musepackdec->segment, GST_FORMAT_DEFAULT, 0); gst_segment_set_duration (&musepackdec->segment, GST_FORMAT_DEFAULT, @@ -467,7 +490,13 @@ gst_musepackdec_loop (GstPad * sinkpad) GstMusepackDec *musepackdec; GstFlowReturn flow; GstBuffer *out; + +#ifdef MPC_IS_OLD_API guint32 update_acc, update_bits; +#else + mpc_frame_info frame; + mpc_status err; +#endif gint num_samples, samplerate, bitspersample; musepackdec = GST_MUSEPACK_DEC (GST_PAD_PARENT (sinkpad)); @@ -491,7 +520,7 @@ gst_musepackdec_loop (GstPad * sinkpad) GST_DEBUG_OBJECT (musepackdec, "Flow: %s", gst_flow_get_name (flow)); goto pause_task; } - +#ifdef MPC_IS_OLD_API num_samples = mpc_decoder_decode (musepackdec->d, (MPC_SAMPLE_FORMAT *) GST_BUFFER_DATA (out), &update_acc, &update_bits); @@ -502,6 +531,20 @@ gst_musepackdec_loop (GstPad * sinkpad) } else if (num_samples == 0) { goto eos_and_pause; } +#else + frame.buffer = (MPC_SAMPLE_FORMAT *) GST_BUFFER_DATA (out); + err = mpc_demux_decode (musepackdec->d, &frame); + + if (err != MPC_STATUS_OK) { + GST_ERROR_OBJECT (musepackdec, "Failed to decode sample"); + GST_ELEMENT_ERROR (musepackdec, STREAM, DECODE, (NULL), (NULL)); + goto pause_task; + } else if (frame.bits == -1) { + goto eos_and_pause; + } + + num_samples = frame.samples; +#endif GST_BUFFER_SIZE (out) = num_samples * bitspersample; @@ -598,6 +641,8 @@ gst_musepackdec_change_state (GstElement * element, GstStateChange transition) static gboolean plugin_init (GstPlugin * plugin) { + GST_DEBUG_CATEGORY_INIT (musepackdec_debug, "musepackdec", 0, "mpc decoder"); + return gst_element_register (plugin, "musepackdec", GST_RANK_PRIMARY, GST_TYPE_MUSEPACK_DEC); } diff --git a/ext/musepack/gstmusepackdec.h b/ext/musepack/gstmusepackdec.h index 858372fd..517861d1 100644 --- a/ext/musepack/gstmusepackdec.h +++ b/ext/musepack/gstmusepackdec.h @@ -20,7 +20,12 @@ #ifndef __GST_MUSEPACK_DEC_H__ #define __GST_MUSEPACK_DEC_H__ +#ifdef MPC_IS_OLD_API #include <mpcdec/mpcdec.h> +#else +#include <mpc/mpcdec.h> +#endif + #include <gst/gst.h> G_BEGIN_DECLS @@ -46,7 +51,11 @@ typedef struct _GstMusepackDec { guint64 offset; /* MUSEPACK_DEC object */ +#ifdef MPC_IS_OLD_API mpc_decoder *d; +#else + mpc_demux *d; +#endif mpc_reader *r; gint bps; /* bytes per sample */ /* ATOMIC */ diff --git a/ext/musepack/gstmusepackreader.c b/ext/musepack/gstmusepackreader.c index 10de6b0d..8a43f760 100644 --- a/ext/musepack/gstmusepackreader.c +++ b/ext/musepack/gstmusepackreader.c @@ -29,6 +29,7 @@ GST_DEBUG_CATEGORY_EXTERN (musepackdec_debug); #define GST_CAT_DEFAULT musepackdec_debug +#ifdef MPC_IS_OLD_API static mpc_int32_t gst_musepack_reader_peek (void *this, void *ptr, mpc_int32_t size); static mpc_int32_t gst_musepack_reader_read (void *this, void *ptr, @@ -37,11 +38,29 @@ static mpc_bool_t gst_musepack_reader_seek (void *this, mpc_int32_t offset); static mpc_int32_t gst_musepack_reader_tell (void *this); static mpc_int32_t gst_musepack_reader_get_size (void *this); static mpc_bool_t gst_musepack_reader_canseek (void *this); +#else +static mpc_int32_t gst_musepack_reader_peek (mpc_reader * this, void *ptr, + mpc_int32_t size); +static mpc_int32_t gst_musepack_reader_read (mpc_reader * this, void *ptr, + mpc_int32_t size); +static mpc_bool_t gst_musepack_reader_seek (mpc_reader * this, + mpc_int32_t offset); +static mpc_int32_t gst_musepack_reader_tell (mpc_reader * this); +static mpc_int32_t gst_musepack_reader_get_size (mpc_reader * this); +static mpc_bool_t gst_musepack_reader_canseek (mpc_reader * this); +#endif +#ifdef MPC_IS_OLD_API static mpc_int32_t gst_musepack_reader_peek (void *this, void *ptr, mpc_int32_t size) { GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); +#else +static mpc_int32_t +gst_musepack_reader_peek (mpc_reader * this, void *ptr, mpc_int32_t size) +{ + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data); +#endif GstFlowReturn flow_ret; GstBuffer *buf = NULL; guint read; @@ -72,10 +91,17 @@ gst_musepack_reader_peek (void *this, void *ptr, mpc_int32_t size) return read; } +#ifdef MPC_IS_OLD_API static mpc_int32_t gst_musepack_reader_read (void *this, void *ptr, mpc_int32_t size) { GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); +#else +static mpc_int32_t +gst_musepack_reader_read (mpc_reader * this, void *ptr, mpc_int32_t size) +{ + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data); +#endif gint read; /* read = peek + flush */ @@ -86,10 +112,17 @@ gst_musepack_reader_read (void *this, void *ptr, mpc_int32_t size) return read; } +#ifdef MPC_IS_OLD_API static mpc_bool_t gst_musepack_reader_seek (void *this, mpc_int32_t offset) { GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); +#else +static mpc_bool_t +gst_musepack_reader_seek (mpc_reader * this, mpc_int32_t offset) +{ + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data); +#endif mpc_int32_t length; length = gst_musepack_reader_get_size (this); @@ -103,35 +136,47 @@ gst_musepack_reader_seek (void *this, mpc_int32_t offset) } } +#ifdef MPC_IS_OLD_API static mpc_int32_t gst_musepack_reader_tell (void *this) { GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); - +#else +static mpc_int32_t +gst_musepack_reader_tell (mpc_reader * this) +{ + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this->data); +#endif return musepackdec->offset; } +#ifdef MPC_IS_OLD_API static mpc_int32_t gst_musepack_reader_get_size (void *this) { GstMusepackDec *dec = GST_MUSEPACK_DEC (this); +#else +static mpc_int32_t +gst_musepack_reader_get_size (mpc_reader * this) +{ + GstMusepackDec *dec = GST_MUSEPACK_DEC (this->data); +#endif GstFormat format = GST_FORMAT_BYTES; gint64 length = -1; - GstPad *peer; - - peer = gst_pad_get_peer (dec->sinkpad); - if (peer) { - if (!gst_pad_query_duration (peer, &format, &length) || length <= 0) { - length = -1; - } - gst_object_unref (peer); - } + + if (!gst_pad_query_peer_duration (dec->sinkpad, &format, &length)) + length = -1; return (mpc_int32_t) length; } +#ifdef MPC_IS_OLD_API static mpc_bool_t gst_musepack_reader_canseek (void *this) +#else +static mpc_bool_t +gst_musepack_reader_canseek (mpc_reader * this) +#endif { return TRUE; } diff --git a/ext/musepack/gstmusepackreader.h b/ext/musepack/gstmusepackreader.h index 77a6bb06..382e6f87 100644 --- a/ext/musepack/gstmusepackreader.h +++ b/ext/musepack/gstmusepackreader.h @@ -20,7 +20,12 @@ #ifndef __GST_MUSEPACK_READER_H__ #define __GST_MUSEPACK_READER_H__ +#ifdef MPC_IS_OLD_API #include <mpcdec/mpcdec.h> +#else +#include <mpc/mpcdec.h> +#endif + #include "gstmusepackdec.h" void gst_musepack_init_reader (mpc_reader * r, GstMusepackDec * musepackdec); |