From 05a1e071b9d1ad06536814e546d7256169654adf Mon Sep 17 00:00:00 2001 From: David Schleef Date: Wed, 23 Sep 2009 13:17:54 -0700 Subject: [PATCH] celtdec: Handle lookahead, discont --- ext/celt/gstceltdec.c | 21 +++++++++++++++++++++ ext/celt/gstceltdec.h | 1 + 2 files changed, 22 insertions(+) diff --git a/ext/celt/gstceltdec.c b/ext/celt/gstceltdec.c index 2f3d7807dc..4837237f2d 100644 --- a/ext/celt/gstceltdec.c +++ b/ext/celt/gstceltdec.c @@ -609,6 +609,7 @@ celt_dec_chain_parse_data (GstCeltDec * dec, GstBuffer * buf, GstBuffer *outbuf; gint16 *out_data; gint error = CELT_OK; + int skip = 0; if (timestamp != -1) { dec->segment.last_stop = timestamp; @@ -636,6 +637,10 @@ celt_dec_chain_parse_data (GstCeltDec * dec, GstBuffer * buf, size = 0; } + if (dec->discont) { + celt_mode_info (dec->mode, CELT_GET_LOOKAHEAD, &skip); + } + res = gst_pad_alloc_buffer_and_set_caps (dec->srcpad, GST_BUFFER_OFFSET_NONE, dec->frame_size * dec->header.nb_channels * 2, GST_PAD_CAPS (dec->srcpad), &outbuf); @@ -655,6 +660,14 @@ celt_dec_chain_parse_data (GstCeltDec * dec, GstBuffer * buf, return GST_FLOW_ERROR; } + if (skip > 0) { + GST_ERROR ("skipping %d samples", skip); + GST_BUFFER_DATA (outbuf) = GST_BUFFER_DATA (outbuf) + + skip * dec->header.nb_channels * 2; + GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (outbuf) - + skip * dec->header.nb_channels * 2; + } + if (dec->granulepos == -1) { if (dec->segment.format != GST_FORMAT_TIME) { GST_WARNING_OBJECT (dec, "segment not initialized or not TIME format"); @@ -672,6 +685,10 @@ celt_dec_chain_parse_data (GstCeltDec * dec, GstBuffer * buf, gst_util_uint64_scale_int (dec->granulepos - dec->frame_size, GST_SECOND, dec->header.sample_rate); GST_BUFFER_DURATION (outbuf) = dec->frame_duration; + if (dec->discont) { + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); + dec->discont = 0; + } dec->granulepos += dec->frame_size; dec->segment.last_stop += dec->frame_duration; @@ -696,6 +713,10 @@ celt_dec_chain (GstPad * pad, GstBuffer * buf) dec = GST_CELT_DEC (gst_pad_get_parent (pad)); + if (GST_BUFFER_IS_DISCONT (buf)) { + dec->discont = TRUE; + } + if (dec->packetno == 0) res = celt_dec_chain_parse_header (dec, buf); else if (dec->packetno == 1) diff --git a/ext/celt/gstceltdec.h b/ext/celt/gstceltdec.h index 77851338ad..8d86290a6d 100644 --- a/ext/celt/gstceltdec.h +++ b/ext/celt/gstceltdec.h @@ -58,6 +58,7 @@ struct _GstCeltDec { GstSegment segment; /* STREAM LOCK */ gint64 granulepos; /* -1 = needs to be set from current time */ + gboolean discont; }; struct _GstCeltDecClass {