diff -Naur --exclude CVS gstreamer.orig/configure.ac gstreamer/configure.ac
--- gstreamer.orig/configure.ac	2006-10-05 17:31:15.000000000 +0200
+++ gstreamer/configure.ac	2006-10-10 14:05:20.000000000 +0200
@@ -315,6 +315,36 @@
 AC_FUNC_MMAP
 AM_CONDITIONAL(HAVE_MMAP, test "x$ac_cv_func_mmap_fixed_mapped" = "xyes")
 
+dnl Check for POSIX monotonic clock
+AC_CHECK_FUNCS(clock_gettime, [], [
+  AC_CHECK_LIB(rt, clock_gettime, [
+    AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
+    LIBS="$LIBS -lrt"
+  ])
+])
+
+AC_CACHE_CHECK(for monotonic clocks, gst_cv_monotonic_clock,AC_TRY_RUN([
+#include <time.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+      int main() {
+#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC)
+        return 0;
+#else
+        return 1;
+#endif
+      }],gst_cv_monotonic_clock=yes,gst_cv_monotonic_clock=no))
+
+if test "$gst_cv_monotonic_clock" = "yes"; then
+  AC_DEFINE(HAVE_MONOTONIC_CLOCK,1,[Have a monotonic clock])
+  GST_HAVE_MONOTONIC_CLOCK_DEFINE="#define GST_HAVE_MONOTONIC_CLOCK 1"
+else
+  GST_HAVE_MONOTONIC_CLOCK_DEFINE="#define GST_HAVE_MONOTONIC_CLOCK 0"
+fi
+AC_SUBST(GST_HAVE_MONOTONIC_CLOCK_DEFINE)
+AM_CONDITIONAL(GST_HAVE_MONOTONIC_CLOCK, test "$gst_cv_monotonic_clock" = "yes")
+
 dnl Check for a way to display the function name in debug output
 GST_CHECK_FUNCTION
 
diff -Naur --exclude CVS gstreamer.orig/gst/Makefile.am gstreamer/gst/Makefile.am
--- gstreamer.orig/gst/Makefile.am	2006-10-10 15:37:31.000000000 +0200
+++ gstreamer/gst/Makefile.am	2006-10-10 15:36:21.000000000 +0200
@@ -54,6 +54,14 @@
 GST_URI_SRC = gsturi.c
 endif
 
+if GST_HAVE_MONOTONIC_CLOCK
+GST_POSIX_CLOCK_SRC = gstposixclock.c
+GST_POSIX_CLOCK_H = gstposixclock.h
+else
+GST_POSIX_CLOCK_SRC = 
+GST_POSIX_CLOCK_H = 
+endif
+
 SUBDIRS = $(SUBDIRS_PARSE)
 
 DIST_SUBDIRS = parse
@@ -99,6 +107,7 @@
 	gstpipeline.c		\
 	gstplugin.c		\
 	gstpluginfeature.c	\
+	$(GST_POSIX_CLOCK_SRC)	\
 	gstquark.c		\
 	gstquery.c		\
 	gstregistry.c		\
@@ -180,6 +189,7 @@
 	gstpipeline.h		\
 	gstplugin.h		\
 	gstpluginfeature.h	\
+	$(GST_POSIX_CLOCK_H)	\
 	gstquery.h		\
 	gstsegment.h		\
 	gststructure.h		\
diff -Naur --exclude CVS gstreamer.orig/gst/gst.c gstreamer/gst/gst.c
--- gstreamer.orig/gst/gst.c	2006-10-06 16:46:03.000000000 +0200
+++ gstreamer/gst/gst.c	2006-10-10 14:23:42.000000000 +0200
@@ -1110,7 +1110,11 @@
     return;
   }
 
+#if GST_HAVE_MONOTONIC_CLOCK
   clock = gst_system_clock_obtain ();
+#else
+  clock = gst_posix_clock_obtain ();
+#endif
   gst_object_unref (clock);
   gst_object_unref (clock);
 
diff -Naur --exclude CVS gstreamer.orig/gst/gst.h gstreamer/gst/gst.h
--- gstreamer.orig/gst/gst.h	2006-08-11 12:19:51.000000000 +0200
+++ gstreamer/gst/gst.h	2006-10-10 14:08:25.000000000 +0200
@@ -30,6 +30,7 @@
 
 #include <gst/gstenumtypes.h>
 #include <gst/gstversion.h>
+#include <gst/gstconfig.h>
 
 #include <gst/gstbin.h>
 #include <gst/gstbuffer.h>
@@ -52,6 +53,9 @@
 #include <gst/gstpad.h>
 #include <gst/gstpipeline.h>
 #include <gst/gstplugin.h>
+#if GST_HAVE_MONOTONIC_CLOCK
+#include <gst/gstposixclock.h>
+#endif
 #include <gst/gstquery.h>
 #include <gst/gstregistry.h>
 #include <gst/gstsegment.h>
diff -Naur --exclude CVS gstreamer.orig/gst/gstconfig.h.in gstreamer/gst/gstconfig.h.in
--- gstreamer.orig/gst/gstconfig.h.in	2006-10-05 14:31:07.000000000 +0200
+++ gstreamer/gst/gstconfig.h.in	2006-10-10 13:51:51.000000000 +0200
@@ -167,6 +167,9 @@
    refcounting */
 @GST_HAVE_GLIB_2_8_DEFINE@
 
+/* whether or not POSIX monotonic clock is supported */
+@GST_HAVE_MONOTONIC_CLOCK_DEFINE@
+
 /***** Deal with XML stuff, we have to handle both loadsave and registry *****/
 
 #if (! (defined(GST_DISABLE_LOADSAVE) && defined(GST_DISABLE_REGISTRY)) )
diff -Naur --exclude CVS gstreamer.orig/gst/gstpipeline.c gstreamer/gst/gstpipeline.c
--- gstreamer.orig/gst/gstpipeline.c	2006-09-15 10:43:44.000000000 +0200
+++ gstreamer/gst/gstpipeline.c	2006-10-10 14:27:57.000000000 +0200
@@ -83,9 +83,14 @@
 #include "gsterror.h"
 #include "gst-i18n-lib.h"
 
+#include "gstconfig.h"
 #include "gstpipeline.h"
 #include "gstinfo.h"
+#if GST_HAVE_MONOTONIC_CLOCK
+#include "gstposixclock.h"
+#else
 #include "gstsystemclock.h"
+#endif
 
 GST_DEBUG_CATEGORY_STATIC (pipeline_debug);
 #define GST_CAT_DEFAULT pipeline_debug
@@ -666,10 +671,17 @@
         provide_clock (GST_ELEMENT (pipeline));
     /* no clock, use a system clock */
     if (!clock) {
+#if GST_HAVE_MONOTONIC_CLOCK
+      clock = gst_posix_clock_obtain ();
+
+      GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline obtained posix clock: %p (%s)",
+          clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
+#else
       clock = gst_system_clock_obtain ();
 
       GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline obtained system clock: %p (%s)",
           clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
+#endif
     } else {
       GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline obtained clock: %p (%s)",
           clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
diff -Naur --exclude CVS gstreamer.orig/gst/gstposixclock.c gstreamer/gst/gstposixclock.c
--- gstreamer.orig/gst/gstposixclock.c	1970-01-01 01:00:00.000000000 +0100
+++ gstreamer/gst/gstposixclock.c	2006-10-10 14:19:41.000000000 +0200
@@ -0,0 +1,170 @@
+/* GStreamer
+ * Copyright (C) 2006 Jonas Holmberg <jonashg@axis.com>
+ *
+ * gstposixclock.c: A clock implementation based on posix timers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:gstposixclock
+ * @short_description: A clock implementation based on POSIX timers
+ * @see_also: #GstSystemClock
+ *
+ * GstPosixClock is a clock implementation based on POSIX timers that represents
+ * a monotonic time since some unspecified starting point.
+ *
+ * Last reviewed on 2006-??-?? (0.10.x)
+ */
+
+#include "gst_private.h"
+#include "gstinfo.h"
+
+#include "gstsystemclock.h"
+#include "gstposixclock.h"
+
+/* the one instance of the POSIX clock */
+static GstClock * _the_posix_clock = NULL;
+
+static void gst_posix_clock_class_init (GstPosixClockClass * klass);
+static void gst_posix_clock_dispose (GObject * object);
+
+static GstClockTime gst_posix_clock_get_internal_time (GstClock * clock);
+static guint64 gst_posix_clock_get_resolution (GstClock * clock);
+
+static GStaticMutex _gst_posclock_mutex = G_STATIC_MUTEX_INIT;
+
+static GstSystemClockClass *parent_class = NULL;
+
+GType
+gst_posix_clock_get_type (void)
+{
+  static GType clock_type = 0;
+
+  if (G_UNLIKELY (clock_type == 0)) {
+    static const GTypeInfo clock_info = {
+      sizeof (GstPosixClockClass),
+      NULL,
+      NULL,
+      (GClassInitFunc) gst_posix_clock_class_init,
+      NULL,
+      NULL,
+      sizeof (GstPosixClock),
+      0,
+      NULL,
+      NULL
+    };
+
+    clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstPosixClock",
+        &clock_info, 0);
+  }
+  return clock_type;
+}
+
+static void
+gst_posix_clock_class_init (GstPosixClockClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstObjectClass *gstobject_class;
+  GstClockClass *gstclock_class;
+
+  gobject_class = (GObjectClass *) klass;
+  gstobject_class = (GstObjectClass *) klass;
+  gstclock_class = (GstClockClass *) klass;
+
+  parent_class = g_type_class_peek_parent (klass);
+
+  gobject_class->dispose = gst_posix_clock_dispose;
+
+  gstclock_class->get_internal_time = gst_posix_clock_get_internal_time;
+  gstclock_class->get_resolution = gst_posix_clock_get_resolution;
+}
+
+static void
+gst_posix_clock_dispose (GObject * object)
+{
+  GstClock *clock = (GstClock *) object;
+
+  G_OBJECT_CLASS (parent_class)->dispose (object);
+
+  if (_the_posix_clock == clock) {
+    _the_posix_clock = NULL;
+    GST_CAT_DEBUG (GST_CAT_CLOCK, "disposed posix clock");
+  }
+}
+
+/**
+ * gst_posix_clock_obtain:
+ *
+ * Get a handle to the default POSIX clock. The refcount of the
+ * clock will be increased so you need to unref the clock after
+ * usage.
+ *
+ * Returns: the default POSIX clock.
+ *
+ * MT safe.
+ */
+GstClock *
+gst_posix_clock_obtain (void)
+{
+  GstClock *clock;
+
+  g_static_mutex_lock (&_gst_posclock_mutex);
+  clock = _the_posix_clock;
+
+  if (clock == NULL) {
+    GST_CAT_DEBUG (GST_CAT_CLOCK, "creating new static posix clock");
+    clock = g_object_new (GST_TYPE_POSIX_CLOCK,
+        "name", "GstPosixClock", NULL);
+
+    /* we created the global clock; take ownership so
+     * we can hand out instances later */
+    gst_object_ref (clock);
+    gst_object_sink (GST_OBJECT (clock));
+
+    _the_posix_clock = clock;
+    g_static_mutex_unlock (&_gst_posclock_mutex);
+  } else {
+    g_static_mutex_unlock (&_gst_posclock_mutex);
+    GST_CAT_DEBUG (GST_CAT_CLOCK, "returning static posix clock");
+  }
+
+  /* we ref it since we are a clock factory */
+  gst_object_ref (clock);
+  return clock;
+}
+
+static GstClockTime
+gst_posix_clock_get_internal_time (GstClock * clock)
+{
+  struct timespec ts;
+
+  if (G_UNLIKELY (clock_gettime (CLOCK_MONOTONIC, &ts))) {
+    return GST_CLOCK_TIME_NONE;
+  }
+  return GST_TIMESPEC_TO_TIME (ts);
+}
+
+static guint64
+gst_posix_clock_get_resolution (GstClock * clock)
+{
+  struct timespec ts;
+
+  if (G_UNLIKELY (clock_getres (CLOCK_MONOTONIC, &ts))) {
+    return GST_CLOCK_TIME_NONE;
+  }
+  return GST_TIMESPEC_TO_TIME (ts);
+}
diff -Naur --exclude CVS gstreamer.orig/gst/gstposixclock.h gstreamer/gst/gstposixclock.h
--- gstreamer.orig/gst/gstposixclock.h	1970-01-01 01:00:00.000000000 +0100
+++ gstreamer/gst/gstposixclock.h	2006-10-09 13:14:51.000000000 +0200
@@ -0,0 +1,68 @@
+/* GStreamer
+ * Copyright (C) 2005 Jonas Holmberg <jonashg@axis.com>
+ *
+ * gstposixclock.h: A clock implementation based on POSIX timers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef __GST_POSIX_CLOCK_H__
+#define __GST_POSIX_CLOCK_H__
+
+#include <gst/gstsystemclock.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_POSIX_CLOCK 		(gst_posix_clock_get_type ())
+#define GST_POSIX_CLOCK(obj) 		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_POSIX_CLOCK, GstPosixClock))
+#define GST_IS_POSIX_CLOCK(obj) 	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_POSIX_CLOCK))
+#define GST_POSIX_CLOCK_CLASS(klass) 	(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_POSIX_CLOCK, GstPosixClockClass))
+#define GST_IS_POSIX_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_POSIX_CLOCK))
+#define GST_POSIX_CLOCK_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_POSIX_CLOCK, GstPosixClockClass))
+
+
+typedef struct _GstPosixClock GstPosixClock;
+typedef struct _GstPosixClockClass GstPosixClockClass;
+
+/**
+ * GstPosixClock:
+ * @clock: The parent clock
+ *
+ * An implementation of a #GstSystemClock that uses POSIX timers and represents
+ * monotonic time since some unspecified starting point.
+ */
+struct _GstPosixClock {
+  GstSystemClock clock;
+
+  /*< private >*/
+  gpointer _gst_reserved[GST_PADDING];
+};
+
+struct _GstPosixClockClass {
+  GstSystemClockClass parent_class;
+
+  /*< private >*/
+  gpointer _gst_reserved[GST_PADDING];
+};
+
+GType gst_posix_clock_get_type (void);
+
+GstClock* gst_posix_clock_obtain (void);
+
+G_END_DECLS
+
+#endif /* __GST_POSIX_CLOCK_H__ */
diff -Naur --exclude CVS gstreamer.orig/tests/check/Makefile.am gstreamer/tests/check/Makefile.am
--- gstreamer.orig/tests/check/Makefile.am	2006-09-28 16:00:43.000000000 +0200
+++ gstreamer/tests/check/Makefile.am	2006-10-10 14:57:01.000000000 +0200
@@ -65,6 +65,12 @@
 	pipelines/stress
 endif
 
+if GST_HAVE_MONOTONIC_CLOCK
+POSIX_CLOCK_CHECKS = gst/gstposixclock
+else
+POSIX_CLOCK_CHECKS =
+endif
+
 check_PROGRAMS =				\
 	gst/gstabi			     	\
         gst/gstbuffer				\
@@ -76,6 +82,7 @@
 	gst/gstminiobject 			\
 	gst/gstobject				\
 	gst/gstpad				\
+	$(POSIX_CLOCK_CHECKS)			\
 	gst/gstsegment				\
 	gst/gstsystemclock			\
 	gst/gststructure			\
diff -Naur --exclude CVS gstreamer.orig/tests/check/gst/gstposixclock.c gstreamer/tests/check/gst/gstposixclock.c
--- gstreamer.orig/tests/check/gst/gstposixclock.c	1970-01-01 01:00:00.000000000 +0100
+++ gstreamer/tests/check/gst/gstposixclock.c	2006-10-10 14:58:54.000000000 +0200
@@ -0,0 +1,221 @@
+/* GStreamer
+ * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
+ *
+ * gstposixclock.c: Unit test for GstPosixClock
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gst/check/gstcheck.h>
+
+GST_START_TEST (test_signedness)
+{
+  GstClockTime time[] = { 0, 1, G_MAXUINT64 / GST_SECOND };
+  GstClockTimeDiff diff[] =
+      { 0, 1, -1, G_MAXINT64 / GST_SECOND, G_MININT64 / GST_SECOND };
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (time); i++) {
+    fail_if (time[i] != (time[i] * GST_SECOND / GST_SECOND));
+  }
+  for (i = 0; i < G_N_ELEMENTS (diff); i++) {
+    fail_if (diff[i] != (diff[i] * GST_SECOND / GST_SECOND));
+  }
+}
+
+GST_END_TEST
+#define TIME_UNIT (GST_SECOND / 5)
+    static void
+gst_clock_debug (GstClock * clock)
+{
+  GstClockTime time;
+
+  time = gst_clock_get_time (clock);
+  g_message ("Clock info: time %" G_GUINT64_FORMAT "\n", time);
+}
+
+static gboolean
+ok_callback (GstClock * clock, GstClockTime time,
+    GstClockID id, gpointer user_data)
+{
+  g_message ("unlocked async id %p\n", id);
+  return FALSE;
+}
+
+static gboolean
+error_callback (GstClock * clock, GstClockTime time,
+    GstClockID id, gpointer user_data)
+{
+  g_message ("unlocked unscheduled async id %p, this is wrong\n", id);
+  fail_if (TRUE);
+
+  return FALSE;
+}
+
+GST_START_TEST (test_single_shot)
+{
+  GstClock *clock;
+  GstClockID id, id2;
+  GstClockTime base;
+  GstClockReturn result;
+
+  clock = gst_posix_clock_obtain ();
+  fail_unless (clock != NULL, "Could not create instance of GstPosixClock");
+
+  gst_clock_debug (clock);
+  base = gst_clock_get_time (clock);
+
+  id = gst_clock_new_single_shot_id (clock, base + TIME_UNIT);
+  fail_unless (id != NULL, "Could not create single shot id");
+
+  g_message ("waiting one second\n");
+  result = gst_clock_id_wait (id, NULL);
+  gst_clock_debug (clock);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+
+  g_message ("waiting in the past\n");
+  result = gst_clock_id_wait (id, NULL);
+  gst_clock_debug (clock);
+  fail_unless (result == GST_CLOCK_EARLY, "Waiting did not return EARLY");
+  gst_clock_id_unref (id);
+
+  id = gst_clock_new_single_shot_id (clock, base + 2 * TIME_UNIT);
+  g_message ("waiting one second async id %p\n", id);
+  result = gst_clock_id_wait_async (id, ok_callback, NULL);
+  gst_clock_id_unref (id);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  g_usleep (TIME_UNIT / (2 * 1000));
+
+  id = gst_clock_new_single_shot_id (clock, base + 5 * TIME_UNIT);
+  g_message ("waiting one second async, with cancel on id %p\n", id);
+  result = gst_clock_id_wait_async (id, error_callback, NULL);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  g_usleep (TIME_UNIT / (2 * 1000));
+  g_message ("cancel id %p after half a time unit\n", id);
+  gst_clock_id_unschedule (id);
+  gst_clock_id_unref (id);
+  g_message ("canceled id %p\n", id);
+
+  g_message ("waiting multiple one second async, with cancel\n");
+  id = gst_clock_new_single_shot_id (clock, base + 5 * TIME_UNIT);
+  id2 = gst_clock_new_single_shot_id (clock, base + 6 * TIME_UNIT);
+  g_message ("waiting id %p\n", id);
+  result = gst_clock_id_wait_async (id, ok_callback, NULL);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  gst_clock_id_unref (id);
+  g_message ("waiting id %p\n", id2);
+  result = gst_clock_id_wait_async (id2, error_callback, NULL);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  g_usleep (TIME_UNIT / (2 * 1000));
+  g_message ("cancel id %p after half a time unit\n", id2);
+  gst_clock_id_unschedule (id2);
+  g_message ("canceled id %p\n", id2);
+  gst_clock_id_unref (id2);
+  g_usleep (TIME_UNIT / (2 * 1000));
+}
+
+GST_END_TEST
+GST_START_TEST (test_periodic_shot)
+{
+  GstClock *clock;
+  GstClockID id, id2;
+  GstClockTime base;
+  GstClockReturn result;
+
+  clock = gst_posix_clock_obtain ();
+  fail_unless (clock != NULL, "Could not create instance of GstPosixClock");
+
+  gst_clock_debug (clock);
+  base = gst_clock_get_time (clock);
+
+  /* signal every half a time unit */
+  id = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2);
+  fail_unless (id != NULL, "Could not create periodic id");
+
+  g_message ("waiting one time unit\n");
+  result = gst_clock_id_wait (id, NULL);
+  gst_clock_debug (clock);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+
+  g_message ("waiting for the next\n");
+  result = gst_clock_id_wait (id, NULL);
+  gst_clock_debug (clock);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+
+  g_message ("waiting for the next async %p\n", id);
+  result = gst_clock_id_wait_async (id, ok_callback, NULL);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  g_usleep (TIME_UNIT / (2 * 1000));
+
+  g_message ("waiting some more for the next async %p\n", id);
+  result = gst_clock_id_wait_async (id, ok_callback, NULL);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  g_usleep (TIME_UNIT / (2 * 1000));
+
+  id2 = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2);
+  fail_unless (id2 != NULL, "Could not create second periodic id");
+
+  g_message ("waiting some more for another async %p\n", id2);
+  result = gst_clock_id_wait_async (id2, ok_callback, NULL);
+  fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK");
+  g_usleep (TIME_UNIT / (2 * 1000));
+
+  g_message ("unschedule %p\n", id);
+  gst_clock_id_unschedule (id);
+
+  /* entry cannot be used again */
+  result = gst_clock_id_wait_async (id, error_callback, NULL);
+  fail_unless (result == GST_CLOCK_UNSCHEDULED,
+      "Waiting did not return UNSCHEDULED");
+  result = gst_clock_id_wait (id, NULL);
+  fail_unless (result == GST_CLOCK_UNSCHEDULED,
+      "Waiting did not return UNSCHEDULED");
+  g_usleep (TIME_UNIT / (2 * 1000));
+
+  /* clean up */
+  gst_clock_id_unref (id);
+}
+
+GST_END_TEST
+GST_START_TEST (test_diff)
+{
+  GstClockTime time1[] =
+      { 0, -1, 0, 1, 2 * GST_SECOND, -GST_SECOND, -GST_SECOND };
+  GstClockTime time2[] =
+      { 0, 1, 1, 0, 1 * GST_SECOND, -GST_SECOND, GST_SECOND };
+  GstClockTimeDiff d[] = { 0, 2, 1, -1, -GST_SECOND, 0, 2 * GST_SECOND };
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (d); i++) {
+    fail_if (d[i] != GST_CLOCK_DIFF (time1[i], time2[i]));
+  }
+}
+GST_END_TEST Suite *
+gst_posixclock_suite (void)
+{
+  Suite *s = suite_create ("GstPosixClock");
+  TCase *tc_chain = tcase_create ("waiting");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_signedness);
+  tcase_add_test (tc_chain, test_single_shot);
+  tcase_add_test (tc_chain, test_periodic_shot);
+  tcase_add_test (tc_chain, test_diff);
+
+  return s;
+}
+
+GST_CHECK_MAIN (gst_posixclock);
