From 1e81bc4b64a9d383e5396869d14da6c2dff31f4d Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Mon, 21 Nov 2011 12:50:22 +0000 Subject: [PATCH] opusdec: read pre-skip from first header if available --- ext/opus/gstopusdec.c | 12 ++++++++++++ ext/opus/gstopusdec.h | 1 + 2 files changed, 13 insertions(+) diff --git a/ext/opus/gstopusdec.c b/ext/opus/gstopusdec.c index 54d25d56cd..f0a9a5144e 100644 --- a/ext/opus/gstopusdec.c +++ b/ext/opus/gstopusdec.c @@ -77,6 +77,8 @@ static GstFlowReturn gst_opus_dec_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer); static gboolean gst_opus_dec_set_format (GstAudioDecoder * bdec, GstCaps * caps); +static gboolean gst_opus_dec_is_header (GstBuffer * buf, const char *magic, + guint magic_size); static void gst_opus_dec_base_init (gpointer g_class) @@ -122,6 +124,8 @@ gst_opus_dec_reset (GstOpusDec * dec) gst_buffer_replace (&dec->streamheader, NULL); gst_buffer_replace (&dec->vorbiscomment, NULL); + + dec->pre_skip = 0; } static void @@ -159,9 +163,17 @@ gst_opus_dec_stop (GstAudioDecoder * dec) static GstFlowReturn gst_opus_dec_parse_header (GstOpusDec * dec, GstBuffer * buf) { + g_return_val_if_fail (gst_opus_dec_is_header (buf, "OpusHead", 8), + GST_FLOW_ERROR); + g_return_val_if_fail (GST_BUFFER_SIZE (buf) >= 19, GST_FLOW_ERROR); + + dec->pre_skip = GST_READ_UINT16_LE (GST_BUFFER_DATA (buf) + 10); + GST_DEBUG_OBJECT (dec, "Found pre-skip of %u samples", dec->pre_skip); + return GST_FLOW_OK; } + static GstFlowReturn gst_opus_dec_parse_comments (GstOpusDec * dec, GstBuffer * buf) { diff --git a/ext/opus/gstopusdec.h b/ext/opus/gstopusdec.h index 9e78330e1f..eee27dc554 100644 --- a/ext/opus/gstopusdec.h +++ b/ext/opus/gstopusdec.h @@ -53,6 +53,7 @@ struct _GstOpusDec { int sample_rate; int n_channels; + guint32 pre_skip; }; struct _GstOpusDecClass {