]> code.delx.au - pulseaudio/blobdiff - src/pulse/mainloop.c
volume: when passing NULL as channel map to pa_cvolume_scale_mask() handle this the...
[pulseaudio] / src / pulse / mainloop.c
index 1b779468801cf14659ccfd5410c5f200fb5d08e8..93a4742d0263de8ae12fab62834bbe2bebee489a 100644 (file)
@@ -56,6 +56,7 @@
 #include <pulsecore/macro.h>
 
 #include "mainloop.h"
+#include "internal.h"
 
 struct pa_io_event {
     pa_mainloop *mainloop;
@@ -319,19 +320,21 @@ static void mainloop_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy
 }
 
 /* Time events */
-static pa_usec_t timeval_load(struct timeval *tv) {
+static pa_usec_t timeval_load(const struct timeval *tv) {
     pa_bool_t is_rtclock;
+    struct timeval ttv;
 
     if (!tv)
         return PA_USEC_INVALID;
 
-    is_rtclock = !!(tv->tv_usec & PA_TIMEVAL_RTCLOCK);
-    tv->tv_usec &= ~PA_TIMEVAL_RTCLOCK;
+    ttv = *tv;
+    is_rtclock = !!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK);
+    ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
 
     if (!is_rtclock)
-        pa_rtclock_from_wallclock(tv);
+        pa_rtclock_from_wallclock(&ttv);
 
-    return pa_timeval_load(tv);
+    return pa_timeval_load(&ttv);
 }
 
 static pa_time_event* mainloop_time_new(
@@ -343,13 +346,13 @@ static pa_time_event* mainloop_time_new(
     pa_mainloop *m;
     pa_time_event *e;
     pa_usec_t t;
-    struct timeval ttv;
 
     pa_assert(a);
     pa_assert(a->userdata);
     pa_assert(callback);
 
-    t = timeval_load(tv? ttv = *tv, &ttv : NULL);
+    t = timeval_load(tv);
+
     m = a->userdata;
     pa_assert(a == &m->api);
 
@@ -385,12 +388,12 @@ static pa_time_event* mainloop_time_new(
 static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
     pa_bool_t valid;
     pa_usec_t t;
-    struct timeval ttv;
 
     pa_assert(e);
     pa_assert(!e->dead);
 
-    t = timeval_load(tv? ttv = *tv, &ttv : NULL);
+    t = timeval_load(tv);
+
     valid = (t != PA_USEC_INVALID);
     if (e->enabled && !valid) {
         pa_assert(e->mainloop->n_enabled_time_events > 0);
@@ -454,10 +457,10 @@ static void mainloop_quit(pa_mainloop_api*a, int retval) {
 static const pa_mainloop_api vtable = {
     .userdata = NULL,
 
-    .io_new= mainloop_io_new,
-    .io_enable= mainloop_io_enable,
-    .io_free= mainloop_io_free,
-    .io_set_destroy= mainloop_io_set_destroy,
+    .io_new = mainloop_io_new,
+    .io_enable = mainloop_io_enable,
+    .io_free = mainloop_io_free,
+    .io_set_destroy = mainloop_io_set_destroy,
 
     .time_new = mainloop_time_new,
     .time_restart = mainloop_time_restart,
@@ -762,23 +765,22 @@ static pa_time_event* find_next_time_event(pa_mainloop *m) {
 
 static int calc_next_timeout(pa_mainloop *m) {
     pa_time_event *t;
-    pa_usec_t usec;
+    pa_usec_t clock_now;
 
     if (!m->n_enabled_time_events)
         return -1;
 
-    t = find_next_time_event(m);
-    pa_assert(t);
+    pa_assert_se(t = find_next_time_event(m));
 
-    if (t->time == 0)
+    if (t->time <= 0)
         return 0;
 
-    usec = t->time - pa_rtclock_now();
+    clock_now = pa_rtclock_now();
 
-    if (usec <= 0)
+    if (t->time <= clock_now)
         return 0;
 
-    return (int) (usec / 1000); /* in milliseconds */
+    return (int) ((t->time - clock_now) / 1000); /* in milliseconds */
 }
 
 static int dispatch_timeout(pa_mainloop *m) {
@@ -992,3 +994,9 @@ void pa_mainloop_set_poll_func(pa_mainloop *m, pa_poll_func poll_func, void *use
     m->poll_func = poll_func;
     m->poll_func_userdata = userdata;
 }
+
+pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m) {
+    pa_assert(m);
+
+    return m->io_new == mainloop_io_new;
+}