ext/wavpack/gstwavpackparse.c: Use G_GINT64_CONSTANT, this fixes the duration query on files without known length.

Original commit message from CVS:
* ext/wavpack/gstwavpackparse.c: (gst_wavpack_parse_reset),
(gst_wavpack_parse_src_query), (gst_wavpack_parse_create_src_pad):
Use G_GINT64_CONSTANT, this fixes the duration query on files without
known length.
This commit is contained in:
Sebastian Dröge 2008-06-19 10:58:57 +00:00
parent 96da520095
commit 14d7abc27a
2 changed files with 63 additions and 4 deletions

View file

@ -1,3 +1,10 @@
2008-06-19 Sebastian Dröge <slomo@circular-chaos.org>
* ext/wavpack/gstwavpackparse.c: (gst_wavpack_parse_reset),
(gst_wavpack_parse_src_query), (gst_wavpack_parse_create_src_pad):
Use G_GINT64_CONSTANT, this fixes the duration query on files without
known length.
2008-06-19 Sebastian Dröge <slomo@circular-chaos.org> 2008-06-19 Sebastian Dröge <slomo@circular-chaos.org>
* gst/matroska/matroska-demux.c: * gst/matroska/matroska-demux.c:

View file

@ -93,14 +93,18 @@ static GstStaticPadTemplate wvc_src_factory = GST_STATIC_PAD_TEMPLATE ("wvcsrc",
); );
static gboolean gst_wavpack_parse_sink_activate (GstPad * sinkpad); static gboolean gst_wavpack_parse_sink_activate (GstPad * sinkpad);
static gboolean static gboolean
gst_wavpack_parse_sink_activate_pull (GstPad * sinkpad, gboolean active); gst_wavpack_parse_sink_activate_pull (GstPad * sinkpad, gboolean active);
static void gst_wavpack_parse_loop (GstElement * element); static void gst_wavpack_parse_loop (GstElement * element);
static GstStateChangeReturn gst_wavpack_parse_change_state (GstElement * static GstStateChangeReturn gst_wavpack_parse_change_state (GstElement *
element, GstStateChange transition); element, GstStateChange transition);
static void gst_wavpack_parse_reset (GstWavpackParse * parse); static void gst_wavpack_parse_reset (GstWavpackParse * parse);
static gint64 gst_wavpack_parse_get_upstream_length (GstWavpackParse * wvparse); static gint64 gst_wavpack_parse_get_upstream_length (GstWavpackParse * wvparse);
static GstBuffer *gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse, static GstBuffer *gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse,
gint64 offset, guint size, GstFlowReturn * flow); gint64 offset, guint size, GstFlowReturn * flow);
static GstFlowReturn gst_wavpack_parse_chain (GstPad * pad, GstBuffer * buf); static GstFlowReturn gst_wavpack_parse_chain (GstPad * pad, GstBuffer * buf);
@ -139,6 +143,7 @@ static void
gst_wavpack_parse_class_init (GstWavpackParseClass * klass) gst_wavpack_parse_class_init (GstWavpackParseClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
@ -162,6 +167,7 @@ gst_wavpack_parse_index_get_entry_from_sample (GstWavpackParse * wvparse,
gint64 sample_offset) gint64 sample_offset)
{ {
gint i; gint i;
GSList *node; GSList *node;
if (wvparse->entries == NULL) if (wvparse->entries == NULL)
@ -220,7 +226,7 @@ gst_wavpack_parse_index_append_entry (GstWavpackParse * wvparse,
static void static void
gst_wavpack_parse_reset (GstWavpackParse * parse) gst_wavpack_parse_reset (GstWavpackParse * parse)
{ {
parse->total_samples = -1; parse->total_samples = G_GINT64_CONSTANT (-1);
parse->samplerate = 0; parse->samplerate = 0;
parse->channels = 0; parse->channels = 0;
@ -282,12 +288,15 @@ static gboolean
gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query) gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
{ {
GstWavpackParse *parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad)); GstWavpackParse *parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
GstFormat format; GstFormat format;
gboolean ret = FALSE; gboolean ret = FALSE;
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:{ case GST_QUERY_POSITION:{
gint64 cur; gint64 cur;
guint rate; guint rate;
GST_OBJECT_LOCK (parse); GST_OBJECT_LOCK (parse);
@ -322,6 +331,7 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
} }
case GST_QUERY_DURATION:{ case GST_QUERY_DURATION:{
gint64 len; gint64 len;
guint rate; guint rate;
GST_OBJECT_LOCK (parse); GST_OBJECT_LOCK (parse);
@ -338,7 +348,7 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
switch (format) { switch (format) {
case GST_FORMAT_TIME: case GST_FORMAT_TIME:
if (len != -1) if (len != G_GINT64_CONSTANT (-1))
len = gst_util_uint64_scale_int (len, GST_SECOND, rate); len = gst_util_uint64_scale_int (len, GST_SECOND, rate);
gst_query_set_duration (query, GST_FORMAT_TIME, len); gst_query_set_duration (query, GST_FORMAT_TIME, len);
ret = TRUE; ret = TRUE;
@ -359,6 +369,7 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
gst_query_parse_seeking (query, &format, NULL, NULL, NULL); gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
if (format == GST_FORMAT_TIME || format == GST_FORMAT_DEFAULT) { if (format == GST_FORMAT_TIME || format == GST_FORMAT_DEFAULT) {
gboolean seekable; gboolean seekable;
gint64 duration = -1; gint64 duration = -1;
/* only fails if we didn't read the headers yet and can't say /* only fails if we didn't read the headers yet and can't say
@ -399,7 +410,9 @@ gst_wavpack_parse_scan_to_find_sample (GstWavpackParse * parse,
gint64 sample, gint64 * byte_offset, gint64 * start_sample) gint64 sample, gint64 * byte_offset, gint64 * start_sample)
{ {
GstWavpackParseIndexEntry *entry; GstWavpackParseIndexEntry *entry;
GstFlowReturn ret; GstFlowReturn ret;
gint64 off = 0; gint64 off = 0;
/* first, check if we have to scan at all */ /* first, check if we have to scan at all */
@ -427,6 +440,7 @@ gst_wavpack_parse_scan_to_find_sample (GstWavpackParse * parse,
/* now scan forward until we find the chunk we're looking for or hit EOS */ /* now scan forward until we find the chunk we're looking for or hit EOS */
do { do {
WavpackHeader header; WavpackHeader header;
GstBuffer *buf; GstBuffer *buf;
buf = gst_wavpack_parse_pull_buffer (parse, off, sizeof (WavpackHeader), buf = gst_wavpack_parse_pull_buffer (parse, off, sizeof (WavpackHeader),
@ -464,10 +478,15 @@ static gboolean
gst_wavpack_parse_send_newsegment (GstWavpackParse * wvparse, gboolean update) gst_wavpack_parse_send_newsegment (GstWavpackParse * wvparse, gboolean update)
{ {
GstSegment *s = &wvparse->segment; GstSegment *s = &wvparse->segment;
gboolean ret; gboolean ret;
gint64 stop_time = -1; gint64 stop_time = -1;
gint64 start_time = 0; gint64 start_time = 0;
gint64 cur_pos_time; gint64 cur_pos_time;
gint64 diff; gint64 diff;
/* segment is in DEFAULT format, but we want to send a TIME newsegment */ /* segment is in DEFAULT format, but we want to send a TIME newsegment */
@ -504,18 +523,31 @@ gst_wavpack_parse_handle_seek_event (GstWavpackParse * wvparse,
GstEvent * event) GstEvent * event)
{ {
GstSeekFlags seek_flags; GstSeekFlags seek_flags;
GstSeekType start_type; GstSeekType start_type;
GstSeekType stop_type; GstSeekType stop_type;
GstSegment segment; GstSegment segment;
GstFormat format; GstFormat format;
gboolean only_update; gboolean only_update;
gboolean flush, ret; gboolean flush, ret;
gdouble speed; gdouble speed;
gint64 stop; gint64 stop;
gint64 start; /* sample we want to seek to */ gint64 start; /* sample we want to seek to */
gint64 byte_offset; /* byte offset the chunk we seek to starts at */ gint64 byte_offset; /* byte offset the chunk we seek to starts at */
gint64 chunk_start; /* first sample in chunk we seek to */ gint64 chunk_start; /* first sample in chunk we seek to */
guint rate; guint rate;
gint64 last_stop; gint64 last_stop;
if (wvparse->adapter) { if (wvparse->adapter) {
@ -641,6 +673,7 @@ static gboolean
gst_wavpack_parse_sink_event (GstPad * pad, GstEvent * event) gst_wavpack_parse_sink_event (GstPad * pad, GstEvent * event)
{ {
GstWavpackParse *parse; GstWavpackParse *parse;
gboolean ret = TRUE; gboolean ret = TRUE;
parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad)); parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
@ -699,6 +732,7 @@ static gboolean
gst_wavpack_parse_src_event (GstPad * pad, GstEvent * event) gst_wavpack_parse_src_event (GstPad * pad, GstEvent * event)
{ {
GstWavpackParse *parse; GstWavpackParse *parse;
gboolean ret; gboolean ret;
parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad)); parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
@ -720,6 +754,7 @@ static void
gst_wavpack_parse_init (GstWavpackParse * parse, GstWavpackParseClass * gclass) gst_wavpack_parse_init (GstWavpackParse * parse, GstWavpackParseClass * gclass)
{ {
GstElementClass *klass = GST_ELEMENT_GET_CLASS (parse); GstElementClass *klass = GST_ELEMENT_GET_CLASS (parse);
GstPadTemplate *tmpl; GstPadTemplate *tmpl;
tmpl = gst_element_class_get_pad_template (klass, "sink"); tmpl = gst_element_class_get_pad_template (klass, "sink");
@ -760,6 +795,7 @@ gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse, gint64 offset,
guint size, GstFlowReturn * flow) guint size, GstFlowReturn * flow)
{ {
GstFlowReturn flow_ret; GstFlowReturn flow_ret;
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
if (offset + size >= wvparse->upstream_length) { if (offset + size >= wvparse->upstream_length) {
@ -800,7 +836,9 @@ gst_wavpack_parse_create_src_pad (GstWavpackParse * wvparse, GstBuffer * buf,
WavpackHeader * header) WavpackHeader * header)
{ {
GstWavpackMetadata meta; GstWavpackMetadata meta;
GstCaps *caps = NULL; GstCaps *caps = NULL;
guchar *bufptr; guchar *bufptr;
g_assert (wvparse->srcpad == NULL); g_assert (wvparse->srcpad == NULL);
@ -820,9 +858,13 @@ gst_wavpack_parse_create_src_pad (GstWavpackParse * wvparse, GstBuffer * buf,
case ID_WV_BITSTREAM: case ID_WV_BITSTREAM:
case ID_WVX_BITSTREAM:{ case ID_WVX_BITSTREAM:{
WavpackStreamReader *stream_reader = gst_wavpack_stream_reader_new (); WavpackStreamReader *stream_reader = gst_wavpack_stream_reader_new ();
WavpackContext *wpc; WavpackContext *wpc;
gchar error_msg[80]; gchar error_msg[80];
read_id rid; read_id rid;
gint channel_mask; gint channel_mask;
rid.buffer = GST_BUFFER_DATA (buf); rid.buffer = GST_BUFFER_DATA (buf);
@ -837,8 +879,9 @@ gst_wavpack_parse_create_src_pad (GstWavpackParse * wvparse, GstBuffer * buf,
wvparse->samplerate = WavpackGetSampleRate (wpc); wvparse->samplerate = WavpackGetSampleRate (wpc);
wvparse->channels = WavpackGetNumChannels (wpc); wvparse->channels = WavpackGetNumChannels (wpc);
wvparse->total_samples = (header->total_samples == (int32_t) - 1) ? wvparse->total_samples =
-1 : header->total_samples; (header->total_samples ==
0xffffffff) ? G_GINT64_CONSTANT (-1) : header->total_samples;
caps = gst_caps_new_simple ("audio/x-wavpack", caps = gst_caps_new_simple ("audio/x-wavpack",
"width", G_TYPE_INT, WavpackGetBitsPerSample (wpc), "width", G_TYPE_INT, WavpackGetBitsPerSample (wpc),
@ -973,6 +1016,7 @@ static guint8 *
gst_wavpack_parse_find_marker (guint8 * buf, guint size) gst_wavpack_parse_find_marker (guint8 * buf, guint size)
{ {
int i; int i;
guint8 *ret = NULL; guint8 *ret = NULL;
if (G_UNLIKELY (size < 4)) if (G_UNLIKELY (size < 4))
@ -991,11 +1035,13 @@ static GstFlowReturn
gst_wavpack_parse_resync_loop (GstWavpackParse * parse, WavpackHeader * header) gst_wavpack_parse_resync_loop (GstWavpackParse * parse, WavpackHeader * header)
{ {
GstFlowReturn flow_ret = GST_FLOW_UNEXPECTED; GstFlowReturn flow_ret = GST_FLOW_UNEXPECTED;
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
/* loop until we have a frame header or reach the end of the stream */ /* loop until we have a frame header or reach the end of the stream */
while (1) { while (1) {
guint8 *data, *marker; guint8 *data, *marker;
guint len, size; guint len, size;
if (buf) { if (buf) {
@ -1056,6 +1102,7 @@ static void
gst_wavpack_parse_loop (GstElement * element) gst_wavpack_parse_loop (GstElement * element)
{ {
GstWavpackParse *parse = GST_WAVPACK_PARSE (element); GstWavpackParse *parse = GST_WAVPACK_PARSE (element);
GstFlowReturn flow_ret; GstFlowReturn flow_ret;
WavpackHeader header = { {0,}, 0, }; WavpackHeader header = { {0,}, 0, };
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
@ -1131,6 +1178,7 @@ static gboolean
gst_wavpack_parse_resync_adapter (GstAdapter * adapter) gst_wavpack_parse_resync_adapter (GstAdapter * adapter)
{ {
const guint8 *buf, *marker; const guint8 *buf, *marker;
guint avail = gst_adapter_available (adapter); guint avail = gst_adapter_available (adapter);
if (avail < 4) if (avail < 4)
@ -1162,8 +1210,11 @@ static GstFlowReturn
gst_wavpack_parse_chain (GstPad * pad, GstBuffer * buf) gst_wavpack_parse_chain (GstPad * pad, GstBuffer * buf)
{ {
GstWavpackParse *wvparse = GST_WAVPACK_PARSE (GST_PAD_PARENT (pad)); GstWavpackParse *wvparse = GST_WAVPACK_PARSE (GST_PAD_PARENT (pad));
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
WavpackHeader wph; WavpackHeader wph;
const guint8 *tmp_buf; const guint8 *tmp_buf;
if (!wvparse->adapter) { if (!wvparse->adapter) {
@ -1223,6 +1274,7 @@ static GstStateChangeReturn
gst_wavpack_parse_change_state (GstElement * element, GstStateChange transition) gst_wavpack_parse_change_state (GstElement * element, GstStateChange transition)
{ {
GstWavpackParse *wvparse = GST_WAVPACK_PARSE (element); GstWavpackParse *wvparse = GST_WAVPACK_PARSE (element);
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
switch (transition) { switch (transition) {