From 58d346c0c40b7d2a89f17ee9ff78dbe11cab584c Mon Sep 17 00:00:00 2001 From: Richard Boulton Date: Sat, 2 Mar 2002 15:52:46 +0000 Subject: [PATCH] Add timestamps to osssrc. Original commit message from CVS: Add timestamps to osssrc. Remove unused member "seq". --- sys/oss/gstosssrc.c | 19 +++++++++++++++---- sys/oss/gstosssrc.h | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sys/oss/gstosssrc.c b/sys/oss/gstosssrc.c index dbc6668ef09..920e427e0e9 100644 --- a/sys/oss/gstosssrc.c +++ b/sys/oss/gstosssrc.c @@ -174,7 +174,8 @@ gst_osssrc_init (GstOssSrc *osssrc) osssrc->bytes_per_read = 4096; osssrc->curoffset = 0; - osssrc->seq = 0; + osssrc->basetime = 0; + osssrc->samples_since_basetime = 0; } static GstBuffer * @@ -183,6 +184,7 @@ gst_osssrc_get (GstPad *pad) GstOssSrc *src; GstBuffer *buf; glong readbytes; + glong readsamples; g_return_val_if_fail (pad != NULL, NULL); src = GST_OSSSRC(gst_pad_get_parent (pad)); @@ -224,10 +226,15 @@ gst_osssrc_get (GstPad *pad) GST_BUFFER_SIZE (buf) = readbytes; GST_BUFFER_OFFSET (buf) = src->curoffset; - - src->curoffset += readbytes; + GST_BUFFER_TIMESTAMP (buf) = src->basetime + + src->samples_since_basetime * 1000000LL / src->frequency; - GST_DEBUG (GST_CAT_PLUGIN_INFO, "pushed buffer from soundcard of %ld bytes\n", readbytes); + src->curoffset += readbytes; + readsamples = readbytes / src->channels; + if (src->format == 16) readsamples /= 2; + src->samples_since_basetime += readsamples; + + GST_DEBUG (GST_CAT_PLUGIN_INFO, "pushed buffer from soundcard of %ld bytes, timestamp %lld\n", readbytes, GST_BUFFER_TIMESTAMP (buf)); return buf; } @@ -252,6 +259,10 @@ gst_osssrc_set_property (GObject *object, guint prop_id, const GValue *value, GP src->channels = g_value_get_int (value); break; case ARG_FREQUENCY: + /* Preserve the timestamps */ + src->basetime = src->samples_since_basetime * 1000000LL / src->frequency; + src->samples_since_basetime = 0; + src->frequency = g_value_get_int (value); break; case ARG_CUROFFSET: diff --git a/sys/oss/gstosssrc.h b/sys/oss/gstosssrc.h index 2118110043a..1ba2a0429b2 100644 --- a/sys/oss/gstosssrc.h +++ b/sys/oss/gstosssrc.h @@ -72,10 +72,10 @@ struct _GstOssSrc { gint frequency; /* blocking */ + guint64 basetime; + guint64 samples_since_basetime; gulong curoffset; gulong bytes_per_read; - - gulong seq; }; struct _GstOssSrcClass {