]> code.delx.au - pulseaudio/blobdiff - polyp/util.c
new features:
[pulseaudio] / polyp / util.c
index 2878c546b7032313bc57bb007ebe9b266779ba20..6c8febb62494cbf634d365d1c39b2576398f4c1e 100644 (file)
@@ -36,6 +36,7 @@
 #include <pwd.h>
 #include <signal.h>
 #include <pthread.h>
+#include <sys/time.h>
 
 #include "util.h"
 #include "xmalloc.h"
@@ -192,3 +193,23 @@ char *pa_get_host_name(char *s, size_t l) {
     s[l-1] = 0;
     return s;
 }
+
+uint32_t pa_age(struct timeval *tv) {
+    struct timeval now;
+    uint32_t r;
+    assert(tv);
+
+    if (tv->tv_sec == 0)
+        return 0;
+
+    gettimeofday(&now, NULL);
+    
+    r = (now.tv_sec-tv->tv_sec) * 1000000;
+
+    if (now.tv_usec >= tv->tv_usec)
+        r += now.tv_usec - tv->tv_usec;
+    else
+        r -= tv->tv_usec - now.tv_usec;
+
+    return r;
+}