]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/core.c
sample-util: move volume code to separate file
[pulseaudio] / src / pulsecore / core.c
index c064e67e0acc790c15e126648d2cec30120846bb..f5eb8352ae554d38814a311e727111a8bd46cffe 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <signal.h>
 
+#include <pulse/rtclock.h>
 #include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
 
@@ -35,6 +36,7 @@
 #include <pulsecore/sink.h>
 #include <pulsecore/source.h>
 #include <pulsecore/namereg.h>
+#include <pulsecore/core-rtclock.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/core-scache.h>
 #include <pulsecore/core-subscribe.h>
@@ -214,7 +216,7 @@ static void core_free(pa_object *o) {
     pa_xfree(c);
 }
 
-static void exit_callback(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
+static void exit_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
     pa_core *c = userdata;
     pa_assert(c->exit_event == e);
 
@@ -229,11 +231,7 @@ void pa_core_check_idle(pa_core *c) {
         c->exit_idle_time >= 0 &&
         pa_idxset_size(c->clients) == 0) {
 
-        struct timeval tv;
-        pa_gettimeofday(&tv);
-        tv.tv_sec+= c->exit_idle_time;
-
-        c->exit_event = c->mainloop->time_new(c->mainloop, &tv, exit_callback, c);
+        c->exit_event = pa_core_rttime_new(c, pa_rtclock_now() + c->exit_idle_time * PA_USEC_PER_SEC, exit_callback, c);
 
     } else if (c->exit_event && pa_idxset_size(c->clients) > 0) {
         c->mainloop->time_free(c->exit_event);
@@ -261,3 +259,21 @@ void pa_core_maybe_vacuum(pa_core *c) {
     pa_log_debug("Hmm, no streams around, trying to vacuum.");
     pa_mempool_vacuum(c->mempool);
 }
+
+pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) {
+    struct timeval tv;
+
+    pa_assert(c);
+    pa_assert(c->mainloop);
+
+    return c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, usec, TRUE), cb, userdata);
+}
+
+void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec) {
+    struct timeval tv;
+
+    pa_assert(c);
+    pa_assert(c->mainloop);
+
+    c->mainloop->time_restart(e, pa_timeval_rtstore(&tv, usec, TRUE));
+}