From a5ef8aef56c1639abcc23b7ba19c00225a041e89 Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Tue, 22 Nov 2005 15:09:28 +0000 Subject: Musepackdec ported to 0.9. There is still a small problem to be solved, after the end of file, the pipeline doens't s... Original commit message from CVS: Musepackdec ported to 0.9. There is still a small problem to be solved, after the end of file, the pipeline doens't stop. --- ext/musepack/gstmusepackreader.c | 156 ++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 45 deletions(-) (limited to 'ext/musepack/gstmusepackreader.c') diff --git a/ext/musepack/gstmusepackreader.c b/ext/musepack/gstmusepackreader.c index 230d7a3c..6595c637 100644 --- a/ext/musepack/gstmusepackreader.c +++ b/ext/musepack/gstmusepackreader.c @@ -29,48 +29,68 @@ static mpc_int32_t gst_musepack_reader_peek (void *this, void *ptr, mpc_int32_t size) { - GstByteStream *bs = this; - guint8 *data; + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); + GstBuffer *buf = NULL; gint read; + if (musepackdec->eos) { + return 0; + } + do { - read = gst_bytestream_peek_bytes (bs, &data, size); + if (GST_FLOW_OK != gst_pad_pull_range (musepackdec->sinkpad, + musepackdec->offset, size, &buf)) { + return 0; + } - if (read != size) { - GstEvent *event; - guint32 remaining; + read = GST_BUFFER_SIZE (buf); - 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; - } + if (musepackdec->eos || + musepackdec->flush_pending || musepackdec->seek_pending) { + break; } + + + /* 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); -done: if (read != 0) { - memcpy (ptr, data, read); + memcpy (ptr, GST_BUFFER_DATA (buf), read); } + gst_buffer_unref (buf); return read; } @@ -78,21 +98,21 @@ done: static mpc_int32_t gst_musepack_reader_read (void *this, void *ptr, mpc_int32_t size) { - GstByteStream *bs = this; + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); gint read; /* read = peek + flush */ if ((read = gst_musepack_reader_peek (this, ptr, size)) > 0) { - gst_bytestream_flush_fast (bs, read); + musepackdec->offset += read; } return read; } -static BOOL +static mpc_bool_t gst_musepack_reader_seek (void *this, mpc_int32_t offset) { - GstByteStream *bs = this; + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); guint8 dummy; /* hacky hack - if we're after typefind, we'll fail because @@ -100,8 +120,7 @@ gst_musepack_reader_seek (void *this, mpc_int32_t offset) gst_musepack_reader_peek (this, &dummy, 1); /* seek */ - if (!gst_bytestream_seek (bs, offset, GST_SEEK_METHOD_SET)) - return FALSE; + musepackdec->offset = offset; /* get discont */ if (gst_musepack_reader_peek (this, &dummy, 1) != 1) @@ -113,29 +132,76 @@ gst_musepack_reader_seek (void *this, mpc_int32_t offset) static mpc_int32_t gst_musepack_reader_tell (void *this) { - GstByteStream *bs = 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; + } - return gst_bytestream_tell (bs); + } + + } else { + position = -1; + } + gst_query_unref (query); + + return position; } static mpc_int32_t gst_musepack_reader_get_size (void *this) { - GstByteStream *bs = this; + GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (this); + GstQuery *query; + gint64 duration; + GstFormat format = GST_FORMAT_BYTES; + + 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; + } + + } + + } else { + duration = -1; + } + gst_query_unref (query); + - return gst_bytestream_length (bs); + return duration; } -static BOOL +static mpc_bool_t gst_musepack_reader_canseek (void *this) { return TRUE; } void -gst_musepack_init_reader (mpc_reader * r, GstByteStream * bs) +gst_musepack_init_reader (mpc_reader * r, GstMusepackDec * musepackdec) { - r->data = bs; + r->data = musepackdec; r->read = gst_musepack_reader_read; r->seek = gst_musepack_reader_seek; -- cgit v1.2.1