Commit b92a9c4e authored by Tim-Philipp Müller's avatar Tim-Philipp Müller 🐠

ext/musepack/: Fix seeking in musepack files (it's still incredibly slow, but...

ext/musepack/: Fix seeking in musepack files (it's still incredibly slow, but I don't think that is our plugin's faul...

Original commit message from CVS:
* ext/musepack/gstmusepackdec.c: (gst_musepackdec_base_init),
(gst_musepackdec_class_init), (gst_musepackdec_init),
(gst_musepackdec_send_newsegment),
(gst_musepackdec_handle_seek_event), (gst_musepackdec_src_event),
(gst_musepackdec_src_query), (gst_musepackdec_src_convert),
(gst_musepack_stream_init), (gst_musepackdec_sink_activate_pull),
(gst_musepackdec_loop), (gst_musepackdec_change_state):
* ext/musepack/gstmusepackdec.h:
* ext/musepack/gstmusepackreader.c: (gst_musepack_reader_peek),
(gst_musepack_reader_seek), (gst_musepack_reader_tell),
(gst_musepack_reader_get_size):
* ext/musepack/gstmusepackreader.h:
Fix seeking in musepack files (it's still incredibly slow, but I
don't think that is our plugin's fault). Clean up code and get
rid of old cruft. Post tags with all kind of neat information like
replay gain and such on the bus, if it is available. Add a
'musepackdec' debug category.
parent 883bcdaf
2006-01-24 Tim-Philipp Müller <tim at centricular dot net>
* ext/musepack/gstmusepackdec.c: (gst_musepackdec_base_init),
(gst_musepackdec_class_init), (gst_musepackdec_init),
(gst_musepackdec_send_newsegment),
(gst_musepackdec_handle_seek_event), (gst_musepackdec_src_event),
(gst_musepackdec_src_query), (gst_musepackdec_src_convert),
(gst_musepack_stream_init), (gst_musepackdec_sink_activate_pull),
(gst_musepackdec_loop), (gst_musepackdec_change_state):
* ext/musepack/gstmusepackdec.h:
* ext/musepack/gstmusepackreader.c: (gst_musepack_reader_peek),
(gst_musepack_reader_seek), (gst_musepack_reader_tell),
(gst_musepack_reader_get_size):
* ext/musepack/gstmusepackreader.h:
Fix seeking in musepack files (it's still incredibly slow, but I
don't think that is our plugin's fault). Clean up code and get
rid of old cruft. Post tags with all kind of neat information like
replay gain and such on the bus, if it is available. Add a
'musepackdec' debug category.
2006-01-24 Edward Hervey <edward@fluendo.com>
* gst/qtdemux/qtdemux.c: (gst_qtdemux_loop_header),
......
This diff is collapsed.
......@@ -21,9 +21,7 @@
#define __GST_MUSEPACK_DEC_H__
#include <gst/gst.h>
//#include <gst/bytestream/bytestream.h>
#include <mpcdec/mpcdec.h>
//#include "gstmusepackreader.h"
G_BEGIN_DECLS
......@@ -37,7 +35,7 @@ G_BEGIN_DECLS
GstMusepackDecClass))
#define GST_IS_MUSEPACK_DEC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MUSEPACK_DEC))
#define GST_IS_MUSEPACK_DEC_CLASS(obj) \
#define GST_IS_MUSEPACK_DEC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MUSEPACK_DEC))
typedef struct _GstMusepackDec {
......@@ -45,7 +43,6 @@ typedef struct _GstMusepackDec {
/* pads */
GstPad *srcpad, *sinkpad;
// GstByteStream *bs;
guint64 offset;
/* MUSEPACK_DEC object */
......@@ -53,15 +50,12 @@ typedef struct _GstMusepackDec {
mpc_reader *r;
gboolean init;
/* bytes-per-sample */
int bps, rate;
/* bytes per sample and sample rate */
guint bps;
guint rate;
/* position and length, in samples */
guint64 pos, len;
/* seeks */
gdouble flush_pending, seek_pending, eos;
guint64 seek_time;
/* currently configured segment, in samples (DEFAULT format) */
GstSegment segment;
} GstMusepackDec;
typedef struct _GstMusepackDecClass {
......@@ -70,10 +64,6 @@ typedef struct _GstMusepackDecClass {
GType gst_musepackdec_get_type (void);
extern gboolean gst_musepackdec_src_convert (GstPad * pad,
GstFormat src_format,
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
G_END_DECLS
#endif /* __GST_MUSEPACK_DEC_H__ */
......@@ -26,72 +26,48 @@
#include "gstmusepackreader.h"
GST_DEBUG_CATEGORY_EXTERN (musepackdec_debug);
#define GST_CAT_DEFAULT musepackdec_debug
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,
mpc_int32_t size);
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);
static mpc_int32_t
gst_musepack_reader_peek (void *this, void *ptr, mpc_int32_t size)
{
GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
GstFlowReturn flow_ret;
GstBuffer *buf = NULL;
gint read;
guint read;
if (musepackdec->eos) {
return 0;
}
g_return_val_if_fail (size > 0, 0);
do {
if (GST_FLOW_OK != gst_pad_pull_range (musepackdec->sinkpad,
musepackdec->offset, size, &buf)) {
return 0;
}
/* GST_LOG_OBJECT (musepackdec, "size=%d", size); */
read = GST_BUFFER_SIZE (buf);
flow_ret = gst_pad_pull_range (musepackdec->sinkpad, musepackdec->offset,
size, &buf);
if (musepackdec->eos ||
musepackdec->flush_pending || musepackdec->seek_pending) {
break;
}
if (flow_ret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (musepackdec, "Flow: %s", gst_flow_get_name (flow_ret));
return 0;
}
read = MIN (GST_BUFFER_SIZE (buf), size);
/* FIX ME: do i have to handle those event in sink_event? */
/* we pipeline doesnt stop after receive EOS */
/*
if (read != size) {
GstEvent *event;
guint32 remaining;
gst_bytestream_get_status (bs, &remaining, &event);
if (!event) {
GST_ELEMENT_ERROR (gst_pad_get_parent (bs->pad),
RESOURCE, READ, (NULL), (NULL));
goto done;
}
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_INTERRUPT:
gst_event_unref (event);
goto done;
case GST_EVENT_EOS:
gst_event_unref (event);
goto done;
case GST_EVENT_FLUSH:
gst_event_unref (event);
break;
case GST_EVENT_DISCONTINUOUS:
gst_event_unref (event);
break;
default:
gst_pad_event_default (bs->pad, event);
break;
}
}
*/
} while (read != size);
if (read != 0) {
memcpy (ptr, GST_BUFFER_DATA (buf), read);
if (read < size) {
GST_WARNING_OBJECT (musepackdec, "Short read: got only %u bytes of %u "
"bytes requested", read, size);
/* GST_ELEMENT_ERROR (musepackdec, RESOURCE, READ, (NULL), (NULL)); */
}
gst_buffer_unref (buf);
memcpy (ptr, GST_BUFFER_DATA (buf), read);
gst_buffer_unref (buf);
return read;
}
......@@ -113,83 +89,44 @@ static mpc_bool_t
gst_musepack_reader_seek (void *this, mpc_int32_t offset)
{
GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
guint8 dummy;
/* hacky hack - if we're after typefind, we'll fail because
* typefind is still typefinding (heh :) ). So read first. */
gst_musepack_reader_peek (this, &dummy, 1);
mpc_int32_t length;
/* seek */
musepackdec->offset = offset;
/* get discont */
if (gst_musepack_reader_peek (this, &dummy, 1) != 1)
length = gst_musepack_reader_get_size (this);
if (length > 0 && offset >= 0 && offset < length) {
musepackdec->offset = offset;
GST_LOG_OBJECT (musepackdec, "Seek'ed to byte offset %d", (gint) offset);
return TRUE;
} else {
GST_DEBUG_OBJECT (musepackdec, "Cannot seek to offset %d", (gint) offset);
return FALSE;
return TRUE;
}
}
static mpc_int32_t
gst_musepack_reader_tell (void *this)
{
GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
GstQuery *query;
gint64 position;
GstFormat format = GST_FORMAT_BYTES;
query = gst_query_new_position (GST_FORMAT_BYTES);
if (gst_pad_query (musepackdec->sinkpad, query)) {
gst_query_parse_position (query, &format, &position);
if (format != GST_FORMAT_BYTES) {
GstFormat dest_format = GST_FORMAT_BYTES;
if (!gst_musepackdec_src_convert (musepackdec->srcpad,
format, position, &dest_format, &position)) {
position = -1;
}
}
} else {
position = -1;
}
gst_query_unref (query);
return position;
return musepackdec->offset;
}
static mpc_int32_t
gst_musepack_reader_get_size (void *this)
{
GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this);
GstQuery *query;
gint64 duration;
GstMusepackDec *dec = GST_MUSEPACK_DEC (this);
GstFormat format = GST_FORMAT_BYTES;
gint64 length = -1;
GstPad *peer;
query = gst_query_new_duration (GST_FORMAT_BYTES);
if (gst_pad_query (musepackdec->sinkpad, query)) {
gst_query_parse_duration (query, &format, &duration);
if (format != GST_FORMAT_BYTES) {
GstFormat dest_format = GST_FORMAT_BYTES;
if (!gst_musepackdec_src_convert (musepackdec->srcpad,
format, duration, &dest_format, &duration)) {
duration = -1;
}
peer = gst_pad_get_peer (dec->sinkpad);
if (peer) {
if (!gst_pad_query_duration (peer, &format, &length) || length <= 0) {
length = -1;
}
} else {
duration = -1;
gst_object_unref (peer);
}
gst_query_unref (query);
return duration;
return (mpc_int32_t) length;
}
static mpc_bool_t
......
......@@ -21,7 +21,6 @@
#define __GST_MUSEPACK_READER_H__
#include <mpcdec/mpcdec.h>
//#include <gst/bytestream/bytestream.h>
#include "gstmusepackdec.h"
void gst_musepack_init_reader (mpc_reader * r, GstMusepackDec * musepackdec);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment