From e05f1df04b6a29fe0d38bee4e041977ff94a3865 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Mon, 21 Nov 2011 17:03:21 +0000 Subject: [PATCH] oggstream: account for opus pre-skip in granpos/time mapping --- ext/ogg/gstoggstream.c | 9 +++++++++ ext/ogg/gstoggstream.h | 1 + 2 files changed, 10 insertions(+) diff --git a/ext/ogg/gstoggstream.c b/ext/ogg/gstoggstream.c index 08cfca76e0..e56e561181 100644 --- a/ext/ogg/gstoggstream.c +++ b/ext/ogg/gstoggstream.c @@ -127,6 +127,10 @@ gst_ogg_stream_granule_to_time (GstOggStream * pad, gint64 granule) if (granule == 0 || pad->granulerate_n == 0 || pad->granulerate_d == 0) return 0; + granule += pad->granule_offset; + if (granule < 0) + return 0; + return gst_util_uint64_scale (granule, GST_SECOND * pad->granulerate_d, pad->granulerate_n); } @@ -1858,6 +1862,11 @@ setup_opus_mapper (GstOggStream * pad, ogg_packet * packet) pad->granuleshift = 0; pad->n_header_packets = 2; + /* pre-skip is in samples at 48000 Hz, which matches granule one for one */ + pad->granule_offset = -GST_READ_UINT16_LE (packet->packet + 10); + GST_INFO ("Opus has a pre-skip of %" G_GINT64_FORMAT " samples", + -pad->granule_offset); + pad->caps = gst_caps_new_simple ("audio/x-opus", NULL); return TRUE; diff --git a/ext/ogg/gstoggstream.h b/ext/ogg/gstoggstream.h index d6c4de61c1..a66a78c34d 100644 --- a/ext/ogg/gstoggstream.h +++ b/ext/ogg/gstoggstream.h @@ -60,6 +60,7 @@ struct _GstOggStream gboolean have_fisbone; gint granulerate_n; gint granulerate_d; + gint64 granule_offset; guint32 preroll; guint granuleshift; gint n_header_packets; -- 2.34.1