summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2002-04-28 14:33:09 +0000
committerWim Taymans <wim.taymans@gmail.com>2002-04-28 14:33:09 +0000
commit71d810adff54054e458e06cebd9f294ec05b21b0 (patch)
tree2b931202f7ccfe7bf13de4dfae40257e1ac12b0b /sys
parentca8b0275ca139fb0824edfaf02701a59c87ddce4 (diff)
Fix clocking.
Original commit message from CVS: Fix clocking.
Diffstat (limited to 'sys')
-rw-r--r--sys/oss/gstosssink.c30
-rw-r--r--sys/oss/gstosssink.h1
2 files changed, 22 insertions, 9 deletions
diff --git a/sys/oss/gstosssink.c b/sys/oss/gstosssink.c
index 7ef567df..e7660a10 100644
--- a/sys/oss/gstosssink.c
+++ b/sys/oss/gstosssink.c
@@ -222,19 +222,28 @@ gst_osssink_get_time (GstClock *clock, gpointer data)
{
GstOssSink *osssink = GST_OSSSINK (data);
gint delay;
- gint offset = 0;
+ GstClockTime res;
if (!osssink->bps)
return 0;
- /* if we have a start time, use offset */
- if (osssink->offset >= 0LL) {
- offset = osssink->offset;
+ ioctl (osssink->fd, SNDCTL_DSP_GETODELAY, &delay);
+
+ /* sometimes delay is bigger than the number of bytes sent to the device, which screws
+ * up this calculation, we assume that everything is still in the device then */
+ if (delay > osssink->handled) {
+ res = osssink->offset;
+ }
+ else {
+ res = osssink->offset + (osssink->handled - delay) * 1000000LL / osssink->bps;
}
- ioctl (osssink->fd, SNDCTL_DSP_GETODELAY, &delay);
+ /*
+ g_print ("from osssink: %lld %lld %d %lld %d\n", res, osssink->offset, delay, osssink->handled,
+ osssink->bps);
+ */
- return offset + (osssink->handled - delay) * 1000000LL / osssink->bps;
+ return res;
}
static void
@@ -261,7 +270,8 @@ gst_osssink_init (GstOssSink *osssink)
#endif /* WORDS_BIGENDIAN */
/* gst_clock_register (osssink->clock, GST_OBJECT (osssink)); */
osssink->bufsize = 4096;
- osssink->offset = -1LL;
+ osssink->bps = 0;
+ osssink->offset = 0LL;
osssink->handled = 0LL;
/* 6 buffers per chunk by default */
osssink->sinkpool = gst_buffer_pool_get_default (osssink->bufsize, 6);
@@ -472,12 +482,13 @@ gst_osssink_chain (GstPad *pad, GstBuffer *buf)
if (osssink->clock) {
/* FIXME, NEW_MEDIA/DISCONT?. Try to get our start point */
- if (osssink->offset == -1LL && buftime != -1LL) {
+ if (!osssink->have_offset && buftime != -1LL) {
GST_INFO (GST_CAT_PLUGIN_INFO,
"osssink: clock at offset: %lld, new offset %lld at time %lld\n",
osssink->offset, buftime, gst_clock_get_time (osssink->clock));
osssink->offset = buftime;
+ osssink->have_offset = TRUE;
osssink->handled = 0;
gst_element_clock_wait (GST_ELEMENT (osssink), osssink->clock, buftime);
}
@@ -697,7 +708,8 @@ gst_osssink_change_state (GstElement *element)
}
break;
case GST_STATE_READY_TO_PAUSED:
- osssink->offset = -1LL;
+ osssink->offset = 0LL;
+ osssink->have_offset = FALSE;
break;
case GST_STATE_PAUSED_TO_PLAYING:
/* gst_clock_adjust (osssink->clock, osssink->offset - gst_clock_get_time (osssink->clock)); */
diff --git a/sys/oss/gstosssink.h b/sys/oss/gstosssink.h
index 9a22418f..8ede9da7 100644
--- a/sys/oss/gstosssink.h
+++ b/sys/oss/gstosssink.h
@@ -77,6 +77,7 @@ struct _GstOssSink {
gboolean mute;
guint bufsize;
guint bps;
+ gboolean have_offset;
guint64 offset;
guint64 handled;