alsasrc: handle the case where the drivers don't supply timestamps
authorStefan Sauer <ensonic@users.sf.net>
Mon, 28 Nov 2011 08:12:37 +0000 (09:12 +0100)
committerStefan Sauer <ensonic@users.sf.net>
Mon, 28 Nov 2011 08:13:29 +0000 (09:13 +0100)
If highres-timestamp is 0, try lowres and if that fails fallback to system clock
timestamps.

ext/alsa/gstalsasrc.c

index 3e7ce5f81fc052ff08c93eafd930487751ff1ab3..6a5086043abfb40965798e780bd93acb0f7a040c 100644 (file)
@@ -251,7 +251,8 @@ static GstClockTime
 gst_alsasrc_get_timestamp (GstAlsaSrc * src)
 {
   snd_pcm_status_t *status;
-  snd_htimestamp_t tstamp;
+  snd_htimestamp_t htstamp;
+  snd_timestamp_t tstamp;
   GstClockTime timestamp;
   snd_pcm_uframes_t availmax;
   gint64 offset;
@@ -275,8 +276,19 @@ gst_alsasrc_get_timestamp (GstAlsaSrc * src)
   }
 
   /* get high resolution time stamp from driver */
-  snd_pcm_status_get_htstamp (status, &tstamp);
-  timestamp = GST_TIMESPEC_TO_TIME (tstamp);
+  snd_pcm_status_get_htstamp (status, &htstamp);
+  timestamp = GST_TIMESPEC_TO_TIME (htstamp);
+  if (!timestamp) {
+    GST_INFO_OBJECT (src,
+        "This alsa source does support high resolution timestamps");
+    snd_pcm_status_get_tstamp (status, &tstamp);
+    timestamp = GST_TIMEVAL_TO_TIME (tstamp);
+    if (!timestamp) {
+      GST_INFO_OBJECT (src,
+          "This alsa source does support low resolution timestamps");
+      timestamp = gst_util_get_timestamp ();
+    }
+  }
   GST_DEBUG_OBJECT (src, "Base ts: %" GST_TIME_FORMAT,
       GST_TIME_ARGS (timestamp));
   if (timestamp == 0) {