Index: libs/gst-plugins-base/Makefile
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/Makefile,v
retrieving revision 1.22
diff -u -r1.22 Makefile
--- libs/gst-plugins-base/Makefile	23 Mar 2010 15:38:26 -0000	1.22
+++ libs/gst-plugins-base/Makefile	8 Nov 2010 09:08:09 -0000
@@ -21,7 +21,6 @@
 	--disable-xvideo \
 	--disable-xshm \
 	--disable-gst_v4l \
-	--disable-alsa \
 	--disable-cdparanoia \
 	--disable-gnome_vfs \
 	--disable-gio \
@@ -45,6 +44,12 @@
 	--with-audioresample-format=int
 endif
 
+ifeq ($(AXIS_CONFIG_AUDIO_ALSA_SOUND_SYSTEM),y)
+	CONFIG_FLAGS += --enable-alsa
+else
+	CONFIG_FLAGS += --disable-alsa
+endif
+
 UNPREFIXED_FILES = \
 	config.h
 
Index: libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.c
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.c,v
retrieving revision 1.1.1.15
diff -u -r1.1.1.15 gstalsasrc.c
--- libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.c	3 May 2010 07:55:59 -0000	1.1.1.15
+++ libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.c	8 Nov 2010 09:08:09 -0000
@@ -44,6 +44,8 @@
 #include <unistd.h>
 #include <string.h>
 #include <getopt.h>
+#include <time.h>
+#include <sys/times.h>
 #include <alsa/asoundlib.h>
 
 #include "gstalsasrc.h"
@@ -59,6 +61,7 @@
   PROP_0,
   PROP_DEVICE,
   PROP_DEVICE_NAME,
+  PROP_CLOCK_USE_MONOTONIC,
 };
 
 static void gst_alsasrc_init_interfaces (GType type);
@@ -84,6 +87,9 @@
 static guint gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length);
 static guint gst_alsasrc_delay (GstAudioSrc * asrc);
 static void gst_alsasrc_reset (GstAudioSrc * asrc);
+static GstClockTime gst_alsasrc_get_src_clock (GstClock * clock,
+                                               GObject * object);
+
 
 /* AlsaSrc signals and args */
 enum
@@ -198,10 +204,12 @@
   GObjectClass *gobject_class;
   GstBaseSrcClass *gstbasesrc_class;
   GstAudioSrcClass *gstaudiosrc_class;
+  GstBaseAudioSrcClass *gstbaseaudiosrc_class;
 
   gobject_class = (GObjectClass *) klass;
   gstbasesrc_class = (GstBaseSrcClass *) klass;
   gstaudiosrc_class = (GstAudioSrcClass *) klass;
+  gstbaseaudiosrc_class = (GstBaseAudioSrcClass *) klass;
 
   gobject_class->finalize = gst_alsasrc_finalize;
   gobject_class->get_property = gst_alsasrc_get_property;
@@ -216,6 +224,8 @@
   gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_alsasrc_read);
   gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_alsasrc_delay);
   gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_alsasrc_reset);
+  gstbaseaudiosrc_class->get_timestamp =
+      GST_DEBUG_FUNCPTR (gst_alsasrc_get_timestamp);
 
   g_object_class_install_property (gobject_class, PROP_DEVICE,
       g_param_spec_string ("device", "Device",
@@ -226,15 +236,77 @@
       g_param_spec_string ("device-name", "Device name",
           "Human-readable name of the sound device",
           DEFAULT_PROP_DEVICE_NAME, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class, PROP_CLOCK_USE_MONOTONIC,
+      g_param_spec_boolean ("use-monotonic", "Use monotonic clock",
+          "Specifies whether the monotonic clock is used or not",
+          FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+}
+
+GstClockTime
+gst_alsasrc_get_timestamp (GObject *object)
+{
+  GstAlsaSrc *asrc = (GstAlsaSrc *)object;
+  snd_pcm_status_t *status;
+  snd_htimestamp_t tstamp;
+  GstClockTime timestamp;
+  snd_pcm_sframes_t d1;
+  snd_pcm_sframes_t dframes;
+  snd_timestamp_t  nohtstamp;
+  struct timespec mytime;
+  snd_pcm_uframes_t avail;
+
+  static GstClockTime start = 0;
+
+  GST_DEBUG_OBJECT (object, "Getting alsa timestamp!");
+
+  if (!asrc) {
+    GST_ERROR_OBJECT (asrc, "No alsa handle created yet !");
+    return 0;
+  }
+
+  if (snd_pcm_status_malloc (&status) != 0) {
+    GST_ERROR_OBJECT (asrc, "snd_pcm_status_malloc failed");
+  }
+
+  if (snd_pcm_status (asrc->handle, status) != 0) {
+    GST_ERROR_OBJECT (asrc, "snd_pcm_status failed");
+  }
+
+  /* get high resolution time stamp */
+  snd_pcm_status_get_htstamp (status, &tstamp);
+  timestamp = GST_TIMESPEC_TO_TIME (tstamp);
+
+  /* Compensate the fact that the timestamp references the last sample */
+  timestamp -= gst_util_uint64_scale_int (asrc->buffer_size * 2, GST_SECOND,
+      asrc->rate);
+  /* Compensate for any played samples */
+  timestamp += gst_util_uint64_scale_int (snd_pcm_status_get_delay (status),
+      GST_SECOND, asrc->rate);
+
+  snd_pcm_status_free (status);
+
+  return timestamp;
+}
+
+static GstClockTime
+gst_alsasrc_get_src_clock (GstClock * clock, GObject * object)
+{
+  GstClockTime result;
+  struct timespec mytime;
+
+  clock_gettime(CLOCK_MONOTONIC, &mytime);
+  result = GST_TIMESPEC_TO_TIME (mytime);
+
+  return result;
 }
 
 static void
 gst_alsasrc_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
 {
-  GstAlsaSrc *src;
-
-  src = GST_ALSA_SRC (object);
+  GstBaseAudioSrc *bsrc = (GstBaseAudioSrc *)object;
+  GstAlsaSrc *src = GST_ALSA_SRC (object);
 
   switch (prop_id) {
     case PROP_DEVICE:
@@ -244,6 +316,15 @@
         src->device = g_strdup (DEFAULT_PROP_DEVICE);
       }
       break;
+    case PROP_CLOCK_USE_MONOTONIC:
+      GST_ALSA_SRC_LOCK (src);
+      src->use_monotonic = g_value_get_boolean (value);
+      if (src->use_monotonic)
+        gst_base_audio_src_create_clock (bsrc, gst_alsasrc_get_src_clock);
+      else
+        gst_base_audio_src_create_clock (bsrc, NULL);
+      GST_ALSA_SRC_UNLOCK (src);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -267,6 +348,11 @@
           gst_alsa_find_device_name (GST_OBJECT_CAST (src),
               src->device, src->handle, SND_PCM_STREAM_CAPTURE));
       break;
+    case PROP_CLOCK_USE_MONOTONIC:
+      GST_ALSA_SRC_LOCK (src);
+      g_value_set_boolean (value, src->use_monotonic);
+      GST_ALSA_SRC_UNLOCK (src);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -280,6 +366,7 @@
 
   alsasrc->device = g_strdup (DEFAULT_PROP_DEVICE);
   alsasrc->cached_caps = NULL;
+  alsasrc->use_monotonic = FALSE;
 
   alsasrc->alsa_lock = g_mutex_new ();
 }
@@ -604,6 +691,8 @@
 
   alsa = GST_ALSA_SRC (asrc);
 
+  GST_DEBUG_OBJECT (asrc, "Entering function !");
+
   CHECK (snd_pcm_open (&alsa->handle, alsa->device, SND_PCM_STREAM_CAPTURE,
           SND_PCM_NONBLOCK), open_error);
 
Index: libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.h
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.h,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 gstalsasrc.h
--- libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.h	15 Mar 2007 13:21:15 -0000	1.1.1.3
+++ libs/gst-plugins-base/gst-plugins-base/ext/alsa/gstalsasrc.h	8 Nov 2010 09:08:09 -0000
@@ -34,6 +34,7 @@
 #define GST_ALSA_SRC_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ALSA_SRC,GstAlsaSrcClass))
 #define GST_IS_ALSA_SRC(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ALSA_SRC))
 #define GST_IS_ALSA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ALSA_SRC))
+#define GST_ALSA_SRC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALSA_SRC, GstAlsaSrcClass))
 #define GST_ALSA_SRC_CAST(obj)       ((GstAlsaSrc *)(obj))
 
 #define GST_ALSA_SRC_GET_LOCK(obj)  (GST_ALSA_SRC_CAST (obj)->alsa_lock)
@@ -73,6 +74,7 @@
   GstAlsaMixer          *mixer;
 
   GMutex                *alsa_lock;
+  gboolean              use_monotonic;
 };
 
 struct _GstAlsaSrcClass {
@@ -80,6 +82,7 @@
 };
 
 GType gst_alsasrc_get_type(void);
+GstClockTime gst_alsasrc_get_timestamp (GObject *object);
 
 G_END_DECLS
 
Index: libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.c
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.c,v
retrieving revision 1.1.1.15
diff -u -r1.1.1.15 gstbaseaudiosrc.c
--- libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.c	4 Mar 2010 13:24:05 -0000	1.1.1.15
+++ libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.c	8 Nov 2010 09:08:10 -0000
@@ -37,6 +37,7 @@
 #endif
 
 #include <string.h>
+#include <stdio.h>
 
 #include "gstbaseaudiosrc.h"
 
@@ -250,8 +251,7 @@
    * value based on negotiated format. */
   GST_BASE_SRC (baseaudiosrc)->blocksize = 0;
 
-  baseaudiosrc->clock = gst_audio_clock_new ("GstAudioSrcClock",
-      (GstAudioClockGetTimeFunc) gst_base_audio_src_get_time, baseaudiosrc);
+  gst_base_audio_src_create_clock (baseaudiosrc, gst_base_audio_src_get_time);
 
   /* we are always a live source */
   gst_base_src_set_live (GST_BASE_SRC (baseaudiosrc), TRUE);
@@ -447,6 +447,35 @@
   return result;
 }
 
+/**
+ * gst_base_audio_src_create_clock:
+ * @src: a #GstBaseAudioSrc
+ *
+ * Replaces the current clock with a new clock provided by @src.
+ * Providing a NULL clock will replace any existing clock with the default
+ * #GstBaseAudioSrc clock implementation.
+ *
+ * Since: 0.10.xx
+ */
+void
+gst_base_audio_src_create_clock (GstBaseAudioSrc * baseaudiosrc,
+    void *func)
+{
+  /* Release any previously used clock objects */
+  if (baseaudiosrc->clock)
+    g_object_unref (baseaudiosrc->clock);
+
+  if (func) {
+    baseaudiosrc->clock = gst_audio_clock_new ("SubElementAudioSrcClock",
+        (GstAudioClockGetTimeFunc) func, baseaudiosrc);
+    baseaudiosrc->child_clock = TRUE;
+  } else {
+    baseaudiosrc->clock = gst_audio_clock_new ("GstAudioSrcClock",
+        (GstAudioClockGetTimeFunc) gst_base_audio_src_get_time, baseaudiosrc);
+    baseaudiosrc->child_clock = FALSE;
+  }
+}
+
 static void
 gst_base_audio_src_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
@@ -946,49 +975,88 @@
       case GST_BASE_AUDIO_SRC_SLAVE_RETIMESTAMP:
       {
         GstClockTime base_time, latency;
+        GstBaseAudioSrcClass *class = GST_BASE_AUDIO_SRC_GET_CLASS (src);
 
-        /* We are slaved to another clock, take running time of the pipeline clock and
-         * timestamp against it. Somebody else in the pipeline should figure out the
-         * clock drift. We keep the duration we calculated above. */
-        timestamp = gst_clock_get_time (clock);
         base_time = GST_ELEMENT_CAST (src)->base_time;
-
-        if (GST_CLOCK_DIFF (timestamp, base_time) < 0)
-          timestamp -= base_time;
-        else
-          timestamp = 0;
-
-        /* subtract latency */
-        latency =
-            gst_util_uint64_scale_int (total_samples, GST_SECOND, spec->rate);
-        if (timestamp > latency)
-          timestamp -= latency;
-        else
-          timestamp = 0;
+        if (src->child_clock) {
+          if (class->get_timestamp) {
+            timestamp = class->get_timestamp ((GObject*)src);
+          } else {
+            struct timespec mytime;
+
+            GST_WARNING_OBJECT (src, "No function for getting a timestamp was "
+                "specified, supplying monotonic clock instead !");
+            clock_gettime(CLOCK_MONOTONIC, &mytime);
+            GST_DEBUG ("clock_gettime gives:             %" G_GUINT64_FORMAT,
+                GST_TIMESPEC_TO_TIME (mytime));
+            timestamp = GST_TIMESPEC_TO_TIME (mytime);
+          }
+        } else {
+          /* We are slaved to another clock, take running time of the pipeline clock and
+           * timestamp against it. Somebody else in the pipeline should figure out the
+           * clock drift. We keep the duration we calculated above. */
+          timestamp = gst_clock_get_time (clock);
+
+          if (GST_CLOCK_DIFF (timestamp, base_time) < 0)
+            timestamp -= base_time;
+          else
+            timestamp = 0;
+
+          /* subtract latency */
+          latency =
+              gst_util_uint64_scale_int (total_samples, GST_SECOND, spec->rate);
+          if (timestamp > latency)
+            timestamp -= latency;
+          else
+            timestamp = 0;
+        }
       }
       case GST_BASE_AUDIO_SRC_SLAVE_NONE:
         break;
     }
   } else {
-    GstClockTime base_time;
-
-    /* to get the timestamp against the clock we also need to add our offset */
-    timestamp = gst_audio_clock_adjust (clock, timestamp);
+    if (src->child_clock) {
+      GstClockTime base_time, latency;
+      GstBaseAudioSrcClass *class = GST_BASE_AUDIO_SRC_GET_CLASS (src);
+
+      if (class->get_timestamp) {
+        /* Sub class is provider of time stamps, so go get it */
+        timestamp = class->get_timestamp ((GObject*)src);
+      } else {
+        struct timespec mytime;
+
+        GST_WARNING_OBJECT (src, "No function for getting a timestamp was "
+            "specified, supplying monotonic clock instead !");
+        clock_gettime(CLOCK_MONOTONIC, &mytime);
+        GST_DEBUG ("clock_gettime gives:             %" G_GUINT64_FORMAT,
+            GST_TIMESPEC_TO_TIME (mytime));
+        timestamp = GST_TIMESPEC_TO_TIME (mytime);
+      }
+    } else {
+      GstClockTime base_time;
 
-    /* we are not slaved, subtract base_time */
-    base_time = GST_ELEMENT_CAST (src)->base_time;
+      GST_DEBUG ("timestamp = %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp));
 
-    if (GST_CLOCK_DIFF (timestamp, base_time) < 0) {
-      timestamp -= base_time;
-      GST_LOG_OBJECT (src,
-          "buffer timestamp %" GST_TIME_FORMAT " (base_time %" GST_TIME_FORMAT
-          ")", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (base_time));
-    } else {
-      GST_LOG_OBJECT (src,
-          "buffer timestamp 0, ts %" GST_TIME_FORMAT " <= base_time %"
-          GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
-          GST_TIME_ARGS (base_time));
-      timestamp = 0;
+      /* to get the timestamp against the clock we also need to add our offset */
+      timestamp = gst_audio_clock_adjust (clock, timestamp);
+      GST_DEBUG ("Adjusted timestamp = %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp));
+
+      /* we are not slaved, subtract base_time */
+      base_time = GST_ELEMENT_CAST (src)->base_time;
+      GST_DEBUG ("base_time = %" GST_TIME_FORMAT, GST_TIME_ARGS (base_time));
+
+      if (GST_CLOCK_DIFF (timestamp, base_time) < 0) {
+        timestamp -= base_time;
+        GST_LOG_OBJECT (src,
+            "buffer timestamp %" GST_TIME_FORMAT " (base_time %" GST_TIME_FORMAT
+            ")", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (base_time));
+      } else {
+        GST_LOG_OBJECT (src,
+            "buffer timestamp 0, ts %" GST_TIME_FORMAT " <= base_time %"
+            GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
+            GST_TIME_ARGS (base_time));
+        timestamp = 0;
+      }
     }
   }
 
@@ -1063,7 +1131,10 @@
       GST_DEBUG_OBJECT (src, "NULL->READY");
       GST_OBJECT_LOCK (src);
       if (src->ringbuffer == NULL) {
-        gst_audio_clock_reset (GST_AUDIO_CLOCK (src->clock), 0);
+        struct timespec mytime;
+
+        clock_gettime(CLOCK_MONOTONIC, &mytime);
+        gst_audio_clock_reset (GST_AUDIO_CLOCK (src->clock),0);
         src->ringbuffer = gst_base_audio_src_create_ringbuffer (src);
       }
       GST_OBJECT_UNLOCK (src);
Index: libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.h
===================================================================
RCS file: /usr/local/cvs/linux/libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.h,v
retrieving revision 1.1.1.6
diff -u -r1.1.1.6 gstbaseaudiosrc.h
--- libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.h	27 Jan 2009 09:16:33 -0000	1.1.1.6
+++ libs/gst-plugins-base/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.h	8 Nov 2010 09:08:10 -0000
@@ -102,6 +102,8 @@
 
   /* clock */
   GstClock      *clock;
+  gboolean      child_clock;
+
 
   /*< private >*/
   GstBaseAudioSrcPrivate *priv;
@@ -122,6 +124,7 @@
 
   /* subclass ringbuffer allocation */
   GstRingBuffer* (*create_ringbuffer)  (GstBaseAudioSrc *src);
+  GstClockTime (*get_timestamp) (GObject *object);
 
   /*< private >*/
   gpointer _gst_reserved[GST_PADDING];
@@ -140,6 +143,8 @@
 GstBaseAudioSrcSlaveMethod
            gst_base_audio_src_get_slave_method         (GstBaseAudioSrc *src);
 
+void       gst_base_audio_src_create_clock          (GstBaseAudioSrc * baseaudiosrc,
+                                                     void *func);
 
 G_END_DECLS
 
