ext/speex/gstspeexdec.c: Try to preserve input timestamps when we can.

Original commit message from CVS:
* ext/speex/gstspeexdec.c: (speex_dec_chain_parse_data),
(speex_dec_chain):
Try to preserve input timestamps when we can.
Do beginnings of error concealment.
This commit is contained in:
Wim Taymans 2008-04-29 14:11:45 +00:00
parent d76f39be0e
commit 0062c4d6d0
2 changed files with 44 additions and 13 deletions

View file

@ -1,3 +1,10 @@
2008-04-29 Wim Taymans <wim.taymans@collabora.co.uk>
* ext/speex/gstspeexdec.c: (speex_dec_chain_parse_data),
(speex_dec_chain):
Try to preserve input timestamps when we can.
Do beginnings of error concealment.
2008-04-28 Michael Smith <msmith@songbirdnest.com>
* gst/debug/gstnavigationtest.c:

View file

@ -106,6 +106,9 @@ static void gst_speex_dec_get_property (GObject * object, guint prop_id,
static void gst_speex_dec_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static GstFlowReturn speex_dec_chain_parse_data (GstSpeexDec * dec,
GstBuffer * buf, GstClockTime timestamp, GstClockTime duration);
static void
gst_speex_dec_base_init (gpointer g_class)
{
@ -623,13 +626,21 @@ speex_dec_chain_parse_comments (GstSpeexDec * dec, GstBuffer * buf)
}
static GstFlowReturn
speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf)
speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf,
GstClockTime timestamp, GstClockTime duration)
{
GstFlowReturn res = GST_FLOW_OK;
gint i, fpp;
guint size;
guint8 *data;
SpeexBits *bits;
if (timestamp != -1) {
dec->segment.last_stop = timestamp;
dec->granulepos = -1;
}
if (buf) {
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
@ -637,19 +648,27 @@ speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf)
speex_bits_read_from (&dec->bits, (char *) data, size);
fpp = dec->header->frames_per_packet;
bits = &dec->bits;
GST_DEBUG_OBJECT (dec, "received buffer of size %u, fpp %d", size, fpp);
/* copy timestamp */
} else {
GST_DEBUG_OBJECT (dec, "creating concealment data");
fpp = dec->header->frames_per_packet;
bits = NULL;
}
/* now decode each frame */
for (i = 0; i < fpp; i++) {
GstBuffer *outbuf;
gint64 timestamp;
gint16 *out_data;
gint ret, j;
GST_LOG_OBJECT (dec, "decoding frame %d/%d", i, fpp);
ret = speex_decode (dec->state, &dec->bits, dec->output);
ret = speex_decode (dec->state, bits, dec->output);
if (ret == -1) {
/* uh? end of stream */
GST_WARNING_OBJECT (dec, "Unexpected end of stream found");
@ -659,7 +678,7 @@ speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf)
break;
}
if (speex_bits_remaining (&dec->bits) < 0) {
if (bits && speex_bits_remaining (bits) < 0) {
GST_WARNING_OBJECT (dec, "Decoding overflow: corrupted stream?");
break;
}
@ -698,8 +717,10 @@ speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf)
GST_DEBUG_OBJECT (dec, "granulepos=%" G_GINT64_FORMAT, dec->granulepos);
}
if (timestamp == -1) {
timestamp = gst_util_uint64_scale_int (dec->granulepos,
GST_SECOND, dec->header->rate);
}
GST_BUFFER_OFFSET (outbuf) = dec->granulepos;
GST_BUFFER_OFFSET_END (outbuf) = dec->granulepos + dec->frame_size;
@ -719,6 +740,7 @@ speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf)
GST_DEBUG_OBJECT (dec, "flow: %s", gst_flow_get_name (res));
break;
}
timestamp = -1;
}
return res;
@ -740,7 +762,9 @@ speex_dec_chain (GstPad * pad, GstBuffer * buf)
res = speex_dec_chain_parse_comments (dec, buf);
break;
default:
res = speex_dec_chain_parse_data (dec, buf);
res =
speex_dec_chain_parse_data (dec, buf, GST_BUFFER_TIMESTAMP (buf),
GST_BUFFER_DURATION (buf));
break;
}