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

ext/wavpack/gstwavpackdec.c: Add debug category, use boilerplate macros, fix...

ext/wavpack/gstwavpackdec.c: Add debug category, use boilerplate macros, fix handling of widths of 32 bits.

Original commit message from CVS:
* ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_setcaps),
(gst_wavpack_dec_base_init), (gst_wavpack_dec_dispose),
(gst_wavpack_dec_class_init), (gst_wavpack_dec_sink_event),
(gst_wavpack_dec_init), (gst_wavpack_dec_format_samples),
(gst_wavpack_dec_chain), (gst_wavpack_dec_plugin_init):
Add debug category, use boilerplate macros, fix handling
of widths of 32 bits.
* ext/wavpack/gstwavpackparse.c: (gst_wavpack_parse_base_init),
(gst_wavpack_parse_dispose), (gst_wavpack_parse_class_init),
(gst_wavpack_parse_index_get_last_entry),
(gst_wavpack_parse_index_get_entry_from_sample),
(gst_wavpack_parse_index_append_entry), (gst_wavpack_parse_reset),
(gst_wavpack_parse_src_query),
(gst_wavpack_parse_scan_to_find_sample),
(gst_wavpack_parse_send_newsegment),
(gst_wavpack_parse_handle_seek_event),
(gst_wavpack_parse_src_event), (gst_wavpack_parse_init),
(gst_wavpack_parse_get_upstream_length),
(gst_wavpack_parse_pull_buffer),
(gst_wavpack_parse_create_src_pad), (gst_wavpack_parse_loop),
(gst_wavpack_parse_change_state),
(gst_wavepack_parse_sink_activate),
(gst_wavepack_parse_sink_activate_pull),
(gst_wavpack_parse_plugin_init):
* ext/wavpack/gstwavpackparse.h:
Rewrite a bit, mostly to fix flow logic and to make seeking work.
Fix buffer/event refcounting. Add some debug statements. Add
width of 32 to source pad template caps. Use boilerplate macros.
parent 24994159
2006-01-29 Tim-Philipp Müller <tim at centricular dot net>
* ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_setcaps),
(gst_wavpack_dec_base_init), (gst_wavpack_dec_dispose),
(gst_wavpack_dec_class_init), (gst_wavpack_dec_sink_event),
(gst_wavpack_dec_init), (gst_wavpack_dec_format_samples),
(gst_wavpack_dec_chain), (gst_wavpack_dec_plugin_init):
Add debug category, use boilerplate macros, fix handling
of widths of 32 bits.
* ext/wavpack/gstwavpackparse.c: (gst_wavpack_parse_base_init),
(gst_wavpack_parse_dispose), (gst_wavpack_parse_class_init),
(gst_wavpack_parse_index_get_last_entry),
(gst_wavpack_parse_index_get_entry_from_sample),
(gst_wavpack_parse_index_append_entry), (gst_wavpack_parse_reset),
(gst_wavpack_parse_src_query),
(gst_wavpack_parse_scan_to_find_sample),
(gst_wavpack_parse_send_newsegment),
(gst_wavpack_parse_handle_seek_event),
(gst_wavpack_parse_src_event), (gst_wavpack_parse_init),
(gst_wavpack_parse_get_upstream_length),
(gst_wavpack_parse_pull_buffer),
(gst_wavpack_parse_create_src_pad), (gst_wavpack_parse_loop),
(gst_wavpack_parse_change_state),
(gst_wavepack_parse_sink_activate),
(gst_wavepack_parse_sink_activate_pull),
(gst_wavpack_parse_plugin_init):
* ext/wavpack/gstwavpackparse.h:
Rewrite a bit, mostly to fix flow logic and to make seeking work.
Fix buffer/event refcounting. Add some debug statements. Add
width of 32 to source pad template caps. Use boilerplate macros.
2006-01-28 Edward Hervey <edward@fluendo.com>
* sys/glsink/Makefile.am:
......@@ -17,7 +49,7 @@
* ext/faad/gstfaad.c: (gst_faad_setcaps),
(gst_faad_chanpos_to_gst), (gst_faad_sync), (gst_faad_chain):
Handle 'framed' field in caps; Port syncing for raw streams
from 0.8 branch (for AAC+ radio streams) (#328722).
from 0.8 branch (for AAC+ radio streams) (#328854, #328721).
2006-01-27 Jan Schmidt <thaytan@mad.scientist.com>
......
......@@ -28,16 +28,8 @@
#include "gstwavpackdec.h"
#include "gstwavpackcommon.h"
/* Filter signals and args */
enum
{
LAST_SIGNAL
};
enum
{
ARG_0
};
GST_DEBUG_CATEGORY_STATIC (gst_wavpack_dec_debug);
#define GST_CAT_DEFAULT gst_wavpack_dec_debug
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
......@@ -59,63 +51,66 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
"width = (int) { 8, 16, 24 }, "
"depth = (int) { 8, 16, 24 }, "
"width = (int) { 8, 16, 24, 32 }, "
"depth = (int) { 8, 16, 24, 32 }, "
"channels = (int) { 1, 2 }, "
"rate = (int) [ 6000, 192000 ], "
"endianness = (int) LITTLE_ENDIAN, "
"signed = (boolean) true;"
"endianness = (int) LITTLE_ENDIAN, " "signed = (boolean) true")
/*
"audio/x-raw-float, "
"width = (int) 32, "
"channels = (int) { 1, 2 }, "
"rate = (int) [ 6000, 192000 ], " "endianness = (int) LITTLE_ENDIAN")
"rate = (int) [ 6000, 192000 ], " "endianness = (int) LITTLE_ENDIAN"
*/
);
static void gst_wavpack_dec_class_init (GstWavpackDecClass * klass);
static void gst_wavpack_dec_base_init (GstWavpackDecClass * klass);
static void gst_wavpack_dec_init (GstWavpackDec * wavpackdec);
static GstFlowReturn gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buffer);
static gboolean gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event);
static GstElementClass *parent = NULL;
GST_BOILERPLATE (GstWavpackDec, gst_wavpack_dec, GstElement, GST_TYPE_ELEMENT)
static GstPadLinkReturn
gst_wavpack_dec_link (GstPad * pad, GstPad * peer)
static gboolean gst_wavpack_dec_setcaps (GstPad * pad, GstCaps * caps)
{
GstWavpackDec *wavpackdec = GST_WAVPACK_DEC (gst_pad_get_parent (pad));
GstStructure *structure;
GstCaps *srccaps;
gint bits;
gint bits, rate, channels;
if (!gst_caps_is_fixed (GST_PAD_CAPS (peer)))
return GST_PAD_LINK_REFUSED;
structure = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int (structure, "rate", &rate) ||
!gst_structure_get_int (structure, "channels", &channels) ||
!gst_structure_get_int (structure, "width", &bits)) {
return FALSE;
}
structure = gst_caps_get_structure (GST_PAD_CAPS (peer), 0);
gst_structure_get_int (structure, "rate",
(gint32 *) & wavpackdec->samplerate);
gst_structure_get_int (structure, "channels",
(gint *) & wavpackdec->channels);
gst_structure_get_int (structure, "width", &bits);
wavpackdec->samplerate = rate;
wavpackdec->channels = channels;
wavpackdec->width = bits;
if (bits != 32) {
srccaps = gst_caps_new_simple ("audio/x-raw-int",
"rate", G_TYPE_INT, wavpackdec->samplerate,
"channels", G_TYPE_INT, wavpackdec->channels,
"depth", G_TYPE_INT, bits,
"width", G_TYPE_INT, bits,
"endianness", G_TYPE_INT, LITTLE_ENDIAN,
"signed", G_TYPE_BOOLEAN, TRUE, NULL);
/* 32-bit output seems to be in fact 32 bit int (e.g. Prod_Girls.wv) */
/* if (bits != 32) { */
srccaps = gst_caps_new_simple ("audio/x-raw-int",
"rate", G_TYPE_INT, wavpackdec->samplerate,
"channels", G_TYPE_INT, wavpackdec->channels,
"depth", G_TYPE_INT, bits,
"width", G_TYPE_INT, bits,
"endianness", G_TYPE_INT, G_LITTLE_ENDIAN,
"signed", G_TYPE_BOOLEAN, TRUE, NULL);
/*
} else {
srccaps = gst_caps_new_simple ("audio/x-raw-float",
"rate", G_TYPE_INT, wavpackdec->samplerate,
"channels", G_TYPE_INT, wavpackdec->channels,
"width", G_TYPE_INT, 32, "endianness", G_TYPE_INT, LITTLE_ENDIAN, NULL);
"width", G_TYPE_INT, 32,
"endianness", G_TYPE_INT, G_LITTLE_ENDIAN, NULL);
}
*/
/* gst_pad_set_caps (wavpackdec->sinkpad, caps); */
gst_pad_set_caps (wavpackdec->srcpad, srccaps);
gst_pad_use_fixed_caps (wavpackdec->srcpad);
return GST_PAD_LINK_OK;
return TRUE;
}
#if 0
......@@ -129,31 +124,8 @@ gst_wavpack_dec_wvclink (GstPad * pad, GstPad * peer)
}
#endif
GType
gst_wavpack_dec_get_type (void)
{
static GType plugin_type = 0;
if (!plugin_type) {
static const GTypeInfo plugin_info = {
sizeof (GstWavpackDecClass),
(GBaseInitFunc) gst_wavpack_dec_base_init,
NULL,
(GClassInitFunc) gst_wavpack_dec_class_init,
NULL,
NULL,
sizeof (GstWavpackDec),
0,
(GInstanceInitFunc) gst_wavpack_dec_init,
};
plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
"GstWavpackDec", &plugin_info, 0);
}
return plugin_type;
}
static void
gst_wavpack_dec_base_init (GstWavpackDecClass * klass)
gst_wavpack_dec_base_init (gpointer klass)
{
static GstElementDetails plugin_details = {
"WAVPACK decoder",
......@@ -178,8 +150,11 @@ gst_wavpack_dec_dispose (GObject * object)
GstWavpackDec *wavpackdec = GST_WAVPACK_DEC (object);
g_free (wavpackdec->decodebuf);
wavpackdec->decodebuf = NULL;
G_OBJECT_CLASS (parent)->dispose (object);
/* FIXME: what about wavpackdec->stream and wavpackdec->context? (tpm) */
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
......@@ -191,8 +166,6 @@ gst_wavpack_dec_class_init (GstWavpackDecClass * klass)
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->dispose = gst_wavpack_dec_dispose;
}
......@@ -202,8 +175,31 @@ gst_wavpack_dec_src_query (GstPad * pad, GstQuery * query)
return gst_pad_query_default (pad, query);
}
static gboolean
gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event)
{
GstWavpackDec *dec;
dec = GST_WAVPACK_DEC (gst_pad_get_parent (pad));
GST_LOG_OBJECT (dec, "Received %s event", GST_EVENT_TYPE_NAME (event));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NEWSEGMENT:{
/* TODO: save current segment so we can do clipping, for now
* we'll just leave the clipping to the audio sink */
break;
}
default:
break;
}
gst_object_unref (dec);
return gst_pad_event_default (pad, event);
}
static void
gst_wavpack_dec_init (GstWavpackDec * wavpackdec)
gst_wavpack_dec_init (GstWavpackDec * wavpackdec, GstWavpackDecClass * gklass)
{
GstElementClass *klass = GST_ELEMENT_GET_CLASS (wavpackdec);
......@@ -212,8 +208,12 @@ gst_wavpack_dec_init (GstWavpackDec * wavpackdec)
"sink"), "sink");
gst_element_add_pad (GST_ELEMENT (wavpackdec), wavpackdec->sinkpad);
gst_pad_set_chain_function (wavpackdec->sinkpad, gst_wavpack_dec_chain);
gst_pad_set_link_function (wavpackdec->sinkpad, gst_wavpack_dec_link);
gst_pad_set_chain_function (wavpackdec->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_dec_chain));
gst_pad_set_setcaps_function (wavpackdec->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_dec_setcaps));
gst_pad_set_event_function (wavpackdec->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_dec_sink_event));
#if 0
wavpackdec->wvcsinkpad =
......@@ -229,7 +229,8 @@ gst_wavpack_dec_init (GstWavpackDec * wavpackdec)
"src"), "src");
gst_pad_use_fixed_caps (wavpackdec->srcpad);
gst_pad_set_query_function (wavpackdec->srcpad, gst_wavpack_dec_src_query);
gst_pad_set_query_function (wavpackdec->srcpad,
GST_DEBUG_FUNCPTR (gst_wavpack_dec_src_query));
gst_element_add_pad (GST_ELEMENT (wavpackdec), wavpackdec->srcpad);
......@@ -290,6 +291,7 @@ gst_wavpack_dec_format_samples (GstWavpackDec * wavpackdec, int32_t * samples,
buf =
gst_buffer_new_and_alloc (num_samples * wavpackdec->width / 8 *
wavpackdec->channels);
dst = (guint8 *) GST_BUFFER_DATA (buf);
switch (wavpackdec->width) {
......@@ -353,8 +355,7 @@ gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buf)
gst_wavpack_dec_format_samples (wavpackdec, wavpackdec->decodebuf,
wavpackdec->context->streams[0]->wphdr.block_samples);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
gst_buffer_stamp (outbuf, buf);
gst_buffer_unref (buf);
if (cbuf) {
......@@ -362,17 +363,27 @@ gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buf)
}
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (wavpackdec->srcpad));
if (GST_FLOW_OK != (ret = gst_pad_push (wavpackdec->srcpad, outbuf))) {
gst_buffer_unref (outbuf);
GST_LOG_OBJECT (wavpackdec, "pushing buffer with time %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
ret = gst_pad_push (wavpackdec->srcpad, outbuf);
if (ret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (wavpackdec, "pad_push: %s", gst_flow_get_name (ret));
}
return ret;
}
gboolean
gst_wavpack_dec_plugin_init (GstPlugin * plugin)
{
return gst_element_register (plugin, "wavpackdec",
GST_RANK_PRIMARY, GST_TYPE_WAVPACK_DEC);
if (!gst_element_register (plugin, "wavpackdec",
GST_RANK_PRIMARY, GST_TYPE_WAVPACK_DEC))
return FALSE;
GST_DEBUG_CATEGORY_INIT (gst_wavpack_dec_debug, "wavpackdec", 0,
"wavpack decoder");
return TRUE;
}
/* GStreamer wavpack plugin
* (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
* (c) 2006 Tim-Philipp Müller <tim centricular net>
*
* gstwavpackparse.c: wavpack file parser
*
......@@ -31,17 +32,6 @@
GST_DEBUG_CATEGORY_STATIC (gst_wavpack_parse_debug);
#define GST_CAT_DEFAULT gst_wavpack_parse_debug
/* Filter signals and args */
enum
{
LAST_SIGNAL
};
enum
{
ARG_0
};
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
......@@ -54,7 +44,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS ("audio/x-wavpack, "
"width = (int) { 8, 16, 24 }, "
"width = (int) { 8, 16, 24, 32 }, "
"channels = (int) { 1, 2 }, "
"rate = (int) [ 6000, 192000 ], " "framed = (boolean) true")
);
......@@ -65,47 +55,22 @@ static GstStaticPadTemplate wvc_src_factory = GST_STATIC_PAD_TEMPLATE ("wvcsrc",
GST_STATIC_CAPS ("audio/x-wavpack-correction, " "framed = (boolean) true")
);
static void gst_wavpack_parse_class_init (GstWavpackParseClass * klass);
static void gst_wavpack_parse_base_init (GstWavpackParseClass * klass);
static void gst_wavpack_parse_init (GstWavpackParse * wavpackparse);
static gboolean gst_wavepack_parse_sink_activate (GstPad * sinkpad);
static gboolean
gst_wavepack_parse_sink_activate_pull (GstPad * sinkpad, gboolean active);
static gboolean gst_wavpack_parse_sink_event (GstPad * pad, GstEvent * event);
static void gst_wavpack_parse_loop (GstElement * element);
static GstStateChangeReturn gst_wavpack_parse_change_state (GstElement *
element, GstStateChange transition);
static void gst_wavpack_parse_reset (GstWavpackParse * wavpackparse);
static gint64 gst_wavpack_parse_get_upstream_length (GstWavpackParse * wvparse);
static GstBuffer *gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse,
gint64 offset, guint size, GstFlowReturn * flow);
static GstElementClass *parent = NULL;
GType
gst_wavpack_parse_get_type (void)
{
static GType plugin_type = 0;
if (!plugin_type) {
static const GTypeInfo plugin_info = {
sizeof (GstWavpackParseClass),
(GBaseInitFunc) gst_wavpack_parse_base_init,
NULL,
(GClassInitFunc) gst_wavpack_parse_class_init,
NULL,
NULL,
sizeof (GstWavpackParse),
0,
(GInstanceInitFunc) gst_wavpack_parse_init,
};
plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
"GstWavpackParse", &plugin_info, 0);
}
return plugin_type;
}
GST_BOILERPLATE (GstWavpackParse, gst_wavpack_parse, GstElement,
GST_TYPE_ELEMENT)
static void
gst_wavpack_parse_base_init (GstWavpackParseClass * klass)
static void gst_wavpack_parse_base_init (gpointer klass)
{
static GstElementDetails plugin_details = {
"Wavpack file parser",
......@@ -127,7 +92,8 @@ gst_wavpack_parse_base_init (GstWavpackParseClass * klass)
static void
gst_wavpack_parse_dispose (GObject * object)
{
G_OBJECT_CLASS (parent)->dispose (object);
gst_wavpack_parse_reset (GST_WAVPACK_PARSE (object));
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
......@@ -139,513 +105,703 @@ gst_wavpack_parse_class_init (GstWavpackParseClass * klass)
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->dispose = gst_wavpack_parse_dispose;
gstelement_class->change_state = gst_wavpack_parse_change_state;
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_wavpack_parse_change_state);
}
static GstWavpackParseIndexEntry *
gst_wavpack_parse_index_get_last_entry (GstWavpackParse * wvparse)
{
gint last;
g_assert (wvparse->entries != NULL);
g_assert (wvparse->entries->len > 0);
last = wvparse->entries->len - 1;
return &g_array_index (wvparse->entries, GstWavpackParseIndexEntry, last);
}
static GstWavpackParseIndexEntry *
gst_wavpack_parse_index_get_entry_from_sample (GstWavpackParse * wvparse,
gint64 sample_offset)
{
gint i;
if (wvparse->entries == NULL || wvparse->entries->len == 0)
return NULL;
for (i = wvparse->entries->len - 1; i >= 0; --i) {
GstWavpackParseIndexEntry *entry;
entry = &g_array_index (wvparse->entries, GstWavpackParseIndexEntry, i);
GST_LOG_OBJECT (wvparse, "Index entry %03u: sample %" G_GINT64_FORMAT " @"
" byte %" G_GINT64_FORMAT, entry->sample_offset, entry->byte_offset);
if (entry->sample_offset <= sample_offset &&
sample_offset < entry->sample_offset_end) {
GST_LOG_OBJECT (wvparse, "found match");
return entry;
}
}
GST_LOG_OBJECT (wvparse, "no match in index");
return NULL;
}
static void
gst_wavpack_parse_index_append_entry (GstWavpackParse * wvparse,
gint64 byte_offset, gint64 sample_offset, gint64 num_samples)
{
GstWavpackParseIndexEntry entry;
if (wvparse->entries == NULL) {
wvparse->entries = g_array_new (FALSE, TRUE,
sizeof (GstWavpackParseIndexEntry));
} else {
/* do we have this one already? */
entry = *gst_wavpack_parse_index_get_last_entry (wvparse);
if (entry.byte_offset >= byte_offset)
return;
}
GST_LOG_OBJECT (wvparse, "Adding index entry %8" G_GINT64_FORMAT " - %"
GST_TIME_FORMAT " @ offset 0x%08" G_GINT64_MODIFIER "x", sample_offset,
GST_TIME_ARGS (gst_util_uint64_scale_int (sample_offset,
GST_SECOND, wvparse->samplerate)), byte_offset);
entry.byte_offset = byte_offset;
entry.sample_offset = sample_offset;
entry.sample_offset_end = sample_offset + num_samples;
g_array_append_val (wvparse->entries, entry);
}
static void
gst_wavpack_parse_reset (GstWavpackParse * wavpackparse)
{
wavpackparse->total_samples = 0;
wavpackparse->samplerate = 0;
wavpackparse->channels = 0;
gst_segment_init (&wavpackparse->segment, GST_FORMAT_UNDEFINED);
wavpackparse->current_offset = 0;
wavpackparse->need_newsegment = TRUE;
wavpackparse->upstream_length = -1;
if (wavpackparse->entries) {
g_array_free (wavpackparse->entries, TRUE);
wavpackparse->entries = NULL;
}
if (wavpackparse->srcpad != NULL) {
gboolean res;
GST_DEBUG_OBJECT (wavpackparse, "Removing src pad");
res = gst_element_remove_pad (GST_ELEMENT (wavpackparse),
wavpackparse->srcpad);
g_return_if_fail (res != FALSE);
gst_object_unref (wavpackparse->srcpad);
wavpackparse->srcpad = NULL;
}
}
static gboolean
gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
{
GstWavpackParse *wavpackparse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
GstFormat format = GST_FORMAT_DEFAULT;
gint64 value;
GstFormat format;
gboolean ret = FALSE;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
gst_query_parse_position (query, &format, &value);
if (format == GST_FORMAT_TIME) {
value = wavpackparse->timestamp;
gst_query_set_duration (query, format, value);
gst_object_unref (wavpackparse);
ret = TRUE;
case GST_QUERY_POSITION:{
gint64 cur, len;
guint rate;
GST_OBJECT_LOCK (wavpackparse);
cur = wavpackparse->segment.last_stop;
len = wavpackparse->total_samples;
rate = wavpackparse->samplerate;
GST_OBJECT_UNLOCK (wavpackparse);
if (len <= 0 || rate == 0) {
GST_DEBUG_OBJECT (wavpackparse, "haven't read header yet");
break;
}
break;
case GST_QUERY_DURATION:
gst_query_parse_duration (query, &format, &value);
if (format == GST_FORMAT_TIME) {
if (wavpackparse->total_samples == 0) {
value = 0;
gst_query_set_duration (query, format, value);
gst_object_unref (wavpackparse);
ret = FALSE;
gst_query_parse_position (query, &format, NULL);
switch (format) {
case GST_FORMAT_TIME:
cur = gst_util_uint64_scale_int (cur, GST_SECOND, rate);
gst_query_set_position (query, GST_FORMAT_TIME, cur);
ret = TRUE;
break;
case GST_FORMAT_DEFAULT:
gst_query_set_position (query, GST_FORMAT_DEFAULT, cur);
ret = TRUE;
break;
}
value = ((gdouble) wavpackparse->total_samples /
(gdouble) wavpackparse->samplerate) * GST_SECOND;
gst_query_set_duration (query, format, value);
gst_object_unref (wavpackparse);
ret = TRUE;
default:
GST_DEBUG_OBJECT (wavpackparse, "cannot handle position query in "
"%s format", gst_format_get_name (format));
break;
}
break;
}
case GST_QUERY_DURATION:{
gint64 len;
guint rate;
GST_OBJECT_LOCK (wavpackparse);
rate = wavpackparse->samplerate;
len = wavpackparse->total_samples;
GST_OBJECT_UNLOCK (wavpackparse);
if (len <= 0 || rate == 0) {
GST_DEBUG_OBJECT (wavpackparse, "haven't read header yet");
break;
}
gst_query_parse_duration (query, &format, NULL);
switch (format) {
case GST_FORMAT_TIME:
len = gst_util_uint64_scale_int (len, GST_SECOND, rate);
gst_query_set_duration (query, GST_FORMAT_TIME, len);
ret = TRUE;
break;
case GST_FORMAT_DEFAULT:
gst_query_set_duration (query, GST_FORMAT_DEFAULT, len);
ret = TRUE;
break;
default:
GST_DEBUG_OBJECT (wavpackparse, "cannot handle duration query in "
"%s format", gst_format_get_name (format));
break;
}
break;
default:
gst_object_unref (wavpackparse);