[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.17-30-gc024aea

Lennart Poettering gitmailer-noreply at 0pointer.de
Thu Sep 17 19:14:19 PDT 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  56b6e18030b5a467946bd0a5803ec119efccdc8a (commit)

- Log -----------------------------------------------------------------
c024aea timeval: make timeval conversion routines handle PA_USEC_INVALID special
a1da83b timeval: add UNLIKELY annotation
05f6236 timeval: make pa_timeval_sub saturating
fdec460 core-rtclock: introduce pa_timespec_store() akin pa_timeval_store()
f7d3896 timeval: introduce PA_USEC_MAX
56f217f macro: introduce PA_INT_TYPE_MIN, PA_INT_TYPE_MAX, PA_INT_TYPE_SIGNED macros
fb4a2a1 mainloop: sum up dispatched events in an unsigned to clarify range
18d69c5 mainloop: use PA_LLIST_FOREACH macros where applicable
b32f599 mainloop: don't initialize fields we don't have to
a049909 mainloop: calculate in pa_usec_t everywhere
a43118b mainloop: properly convert time to wallclock time when handing it to the user
a37e48a alsa: fix Surround mixer element name
-----------------------------------------------------------------------

Summary of changes:
 .../alsa/mixer/paths/analog-output-headphones.conf |    2 +-
 .../mixer/paths/analog-output-lfe-on-mono.conf     |    2 +-
 .../alsa/mixer/paths/analog-output-mono.conf       |    2 +-
 src/pulse/mainloop.c                               |  176 ++++++++++----------
 src/pulse/timeval.c                                |   67 ++++++--
 src/pulse/timeval.h                                |    7 +-
 src/pulsecore/core-rtclock.c                       |   22 +++-
 src/pulsecore/core-rtclock.h                       |    1 +
 src/pulsecore/macro.h                              |   12 ++
 9 files changed, 183 insertions(+), 108 deletions(-)

-----------------------------------------------------------------------

commit a37e48a819f40bebd31e353f4afa43a1ba4a7567
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 03:46:33 2009 +0200

    alsa: fix Surround mixer element name
    
    s/Sourround/Surround/
    
    Spotted by Colin Guthrie

diff --git a/src/modules/alsa/mixer/paths/analog-output-headphones.conf b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
index 691cb3f..61d2e29 100644
--- a/src/modules/alsa/mixer/paths/analog-output-headphones.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
@@ -56,7 +56,7 @@ volume = off
 switch = off
 volume = off
 
-[Element Sourround]
+[Element Surround]
 switch = off
 volume = off
 
diff --git a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
index 3457d4a..911361d 100644
--- a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
@@ -62,7 +62,7 @@ volume = off
 switch = off
 volume = off
 
-[Element Sourround]
+[Element Surround]
 switch = off
 volume = off
 
diff --git a/src/modules/alsa/mixer/paths/analog-output-mono.conf b/src/modules/alsa/mixer/paths/analog-output-mono.conf
index dc270cf..2fbc60b 100644
--- a/src/modules/alsa/mixer/paths/analog-output-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-mono.conf
@@ -59,7 +59,7 @@ volume = off
 switch = off
 volume = off
 
-[Element Sourround]
+[Element Surround]
 switch = off
 volume = off
 

commit a43118b730c60a17b032b882b10ff9b93ab59460
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 03:48:55 2009 +0200

    mainloop: properly convert time to wallclock time when handing it to the user

diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 93a4742..379f88a 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -806,7 +806,7 @@ static int dispatch_timeout(pa_mainloop *m) {
             /* Disable time event */
             mainloop_time_restart(e, NULL);
 
-            e->callback(&m->api, e, pa_timeval_rtstore(&tv, e->time, TRUE), e->userdata);
+            e->callback(&m->api, e, pa_timeval_rtstore(&tv, e->time, FALSE), e->userdata);
 
             r++;
         }

commit a049909a7044813cb6237d22757ac24081b59af8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 03:59:40 2009 +0200

    mainloop: calculate in pa_usec_t everywhere

diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 379f88a..d2cc7ae 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -112,7 +112,7 @@ struct pa_mainloop {
     struct pollfd *pollfds;
     unsigned max_pollfds, n_pollfds;
 
-    int prepared_timeout;
+    pa_usec_t prepared_timeout;
     pa_time_event *cached_next_time_event;
 
     pa_mainloop_api api;
@@ -320,21 +320,19 @@ static void mainloop_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy
 }
 
 /* Time events */
-static pa_usec_t timeval_load(const struct timeval *tv) {
-    pa_bool_t is_rtclock;
+static pa_usec_t make_rt(const struct timeval *tv) {
     struct timeval ttv;
 
     if (!tv)
         return PA_USEC_INVALID;
 
-    ttv = *tv;
-    is_rtclock = !!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK);
-    ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
-
-    if (!is_rtclock)
-        pa_rtclock_from_wallclock(&ttv);
+    if (tv->tv_usec & PA_TIMEVAL_RTCLOCK) {
+        ttv = *tv;
+        ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
+        tv = pa_rtclock_from_wallclock(&ttv);
+    }
 
-    return pa_timeval_load(&ttv);
+    return pa_timeval_load(tv);
 }
 
 static pa_time_event* mainloop_time_new(
@@ -351,7 +349,7 @@ static pa_time_event* mainloop_time_new(
     pa_assert(a->userdata);
     pa_assert(callback);
 
-    t = timeval_load(tv);
+    t = make_rt(tv);
 
     m = a->userdata;
     pa_assert(a == &m->api);
@@ -392,7 +390,7 @@ static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
     pa_assert(e);
     pa_assert(!e->dead);
 
-    t = timeval_load(tv);
+    t = make_rt(tv);
 
     valid = (t != PA_USEC_INVALID);
     if (e->enabled && !valid) {
@@ -763,12 +761,12 @@ static pa_time_event* find_next_time_event(pa_mainloop *m) {
     return n;
 }
 
-static int calc_next_timeout(pa_mainloop *m) {
+static pa_usec_t calc_next_timeout(pa_mainloop *m) {
     pa_time_event *t;
     pa_usec_t clock_now;
 
-    if (!m->n_enabled_time_events)
-        return -1;
+    if (m->n_enabled_time_events <= 0)
+        return PA_USEC_INVALID;
 
     pa_assert_se(t = find_next_time_event(m));
 
@@ -780,7 +778,7 @@ static int calc_next_timeout(pa_mainloop *m) {
     if (t->time <= clock_now)
         return 0;
 
-    return (int) ((t->time - clock_now) / 1000); /* in milliseconds */
+    return t->time - clock_now;
 }
 
 static int dispatch_timeout(pa_mainloop *m) {
@@ -850,12 +848,17 @@ int pa_mainloop_prepare(pa_mainloop *m, int timeout) {
         goto quit;
 
     if (m->n_enabled_defer_events <= 0) {
+
         if (m->rebuild_pollfds)
             rebuild_pollfds(m);
 
         m->prepared_timeout = calc_next_timeout(m);
-        if (timeout >= 0 && (timeout < m->prepared_timeout || m->prepared_timeout < 0))
-            m->prepared_timeout = timeout;
+        if (timeout >= 0) {
+            uint64_t u = (uint64_t) timeout * PA_USEC_PER_MSEC;
+
+            if (u < m->prepared_timeout || m->prepared_timeout == PA_USEC_INVALID)
+                m->prepared_timeout = timeout;
+        }
     }
 
     m->state = STATE_PREPARED;
@@ -866,6 +869,13 @@ quit:
     return -2;
 }
 
+static int usec_to_timeout(pa_usec_t u) {
+    if (u == PA_USEC_INVALID)
+        return -1;
+
+    return (u + PA_USEC_PER_MSEC - 1) / PA_USEC_PER_MSEC;
+}
+
 int pa_mainloop_poll(pa_mainloop *m) {
     pa_assert(m);
     pa_assert(m->state == STATE_PREPARED);
@@ -881,9 +891,24 @@ int pa_mainloop_poll(pa_mainloop *m) {
         pa_assert(!m->rebuild_pollfds);
 
         if (m->poll_func)
-            m->poll_func_ret = m->poll_func(m->pollfds, m->n_pollfds, m->prepared_timeout, m->poll_func_userdata);
-        else
-            m->poll_func_ret = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
+            m->poll_func_ret = m->poll_func(
+                    m->pollfds, m->n_pollfds,
+                    usec_to_timeout(m->prepared_timeout),
+                    m->poll_func_userdata);
+        else {
+#ifdef HAVE_PPOLL
+            struct timespec ts;
+
+            m->poll_func_ret = ppoll(
+                    m->pollfds, m->n_pollfds,
+                    m->prepared_timeout == PA_USEC_INVALID ? NULL : pa_timespec_store(&ts, m->prepared_timeout),
+                    NULL);
+#else
+            m->poll_func_ret = poll(
+                    m->pollfds, m->n_pollfds,
+                    usec_to_timeout(m->prepared_timeout));
+#endif
+        }
 
         if (m->poll_func_ret < 0) {
             if (errno == EINTR)

commit b32f5994e9d1872c3a2ed8fd44d6d1866bb8387f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:00:38 2009 +0200

    mainloop: don't initialize fields we don't have to

diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index d2cc7ae..4f3b676 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -172,17 +172,14 @@ static pa_io_event* mainloop_io_new(
     m = a->userdata;
     pa_assert(a == &m->api);
 
-    e = pa_xnew(pa_io_event, 1);
+    e = pa_xnew0(pa_io_event, 1);
     e->mainloop = m;
-    e->dead = FALSE;
 
     e->fd = fd;
     e->events = events;
-    e->pollfd = NULL;
 
     e->callback = callback;
     e->userdata = userdata;
-    e->destroy_callback = NULL;
 
 #ifdef OS_IS_WIN32
     {
@@ -265,16 +262,14 @@ static pa_defer_event* mainloop_defer_new(
     m = a->userdata;
     pa_assert(a == &m->api);
 
-    e = pa_xnew(pa_defer_event, 1);
+    e = pa_xnew0(pa_defer_event, 1);
     e->mainloop = m;
-    e->dead = FALSE;
 
     e->enabled = TRUE;
     m->n_enabled_defer_events++;
 
     e->callback = callback;
     e->userdata = userdata;
-    e->destroy_callback = NULL;
 
     PA_LLIST_PREPEND(pa_defer_event, m->defer_events, e);
 
@@ -354,9 +349,8 @@ static pa_time_event* mainloop_time_new(
     m = a->userdata;
     pa_assert(a == &m->api);
 
-    e = pa_xnew(pa_time_event, 1);
+    e = pa_xnew0(pa_time_event, 1);
     e->mainloop = m;
-    e->dead = FALSE;
 
     if ((e->enabled = (t != PA_USEC_INVALID))) {
         e->time = t;
@@ -373,7 +367,6 @@ static pa_time_event* mainloop_time_new(
 
     e->callback = callback;
     e->userdata = userdata;
-    e->destroy_callback = NULL;
 
     PA_LLIST_PREPEND(pa_time_event, m->time_events, e);
 
@@ -478,9 +471,8 @@ pa_mainloop *pa_mainloop_new(void) {
 
     pa_init_i18n();
 
-    m = pa_xnew(pa_mainloop, 1);
+    m = pa_xnew0(pa_mainloop, 1);
 
-    m->wakeup_pipe_type = 0;
     if (pipe(m->wakeup_pipe) < 0) {
         pa_log_error("ERROR: cannot create wakeup pipe");
         pa_xfree(m);
@@ -491,32 +483,14 @@ pa_mainloop *pa_mainloop_new(void) {
     pa_make_fd_nonblock(m->wakeup_pipe[1]);
     pa_make_fd_cloexec(m->wakeup_pipe[0]);
     pa_make_fd_cloexec(m->wakeup_pipe[1]);
-    m->wakeup_requested = FALSE;
 
-    PA_LLIST_HEAD_INIT(pa_io_event, m->io_events);
-    PA_LLIST_HEAD_INIT(pa_time_event, m->time_events);
-    PA_LLIST_HEAD_INIT(pa_defer_event, m->defer_events);
-
-    m->n_enabled_defer_events = m->n_enabled_time_events = m->n_io_events = 0;
-    m->io_events_please_scan = m->time_events_please_scan = m->defer_events_please_scan = 0;
-
-    m->cached_next_time_event = NULL;
-    m->prepared_timeout = 0;
-
-    m->pollfds = NULL;
-    m->max_pollfds = m->n_pollfds = 0;
     m->rebuild_pollfds = TRUE;
 
-    m->quit = FALSE;
-    m->retval = 0;
-
     m->api = vtable;
     m->api.userdata = m;
 
     m->state = STATE_PASSIVE;
 
-    m->poll_func = NULL;
-    m->poll_func_userdata = NULL;
     m->poll_func_ret = -1;
 
     return m;

commit 18d69c5d9d04d81135f078d7f49bad3214418622
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:03:49 2009 +0200

    mainloop: use PA_LLIST_FOREACH macros where applicable

diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 4f3b676..67f095b 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -497,11 +497,9 @@ pa_mainloop *pa_mainloop_new(void) {
 }
 
 static void cleanup_io_events(pa_mainloop *m, pa_bool_t force) {
-    pa_io_event *e;
+    pa_io_event *e, *n;
 
-    e = m->io_events;
-    while (e) {
-        pa_io_event *n = e->next;
+    PA_LLIST_FOREACH_SAFE(e, n, m->io_events) {
 
         if (!force && m->io_events_please_scan <= 0)
             break;
@@ -521,19 +519,15 @@ static void cleanup_io_events(pa_mainloop *m, pa_bool_t force) {
 
             m->rebuild_pollfds = TRUE;
         }
-
-        e = n;
     }
 
     pa_assert(m->io_events_please_scan == 0);
 }
 
 static void cleanup_time_events(pa_mainloop *m, pa_bool_t force) {
-    pa_time_event *e;
+    pa_time_event *e, *n;
 
-    e = m->time_events;
-    while (e) {
-        pa_time_event *n = e->next;
+    PA_LLIST_FOREACH_SAFE(e, n, m->time_events) {
 
         if (!force && m->time_events_please_scan <= 0)
             break;
@@ -557,19 +551,15 @@ static void cleanup_time_events(pa_mainloop *m, pa_bool_t force) {
 
             pa_xfree(e);
         }
-
-        e = n;
     }
 
     pa_assert(m->time_events_please_scan == 0);
 }
 
 static void cleanup_defer_events(pa_mainloop *m, pa_bool_t force) {
-    pa_defer_event *e;
+    pa_defer_event *e, *n;
 
-    e = m->defer_events;
-    while (e) {
-        pa_defer_event *n = e->next;
+    PA_LLIST_FOREACH_SAFE(e, n, m->defer_events) {
 
         if (!force && m->defer_events_please_scan <= 0)
             break;
@@ -593,8 +583,6 @@ static void cleanup_defer_events(pa_mainloop *m, pa_bool_t force) {
 
             pa_xfree(e);
         }
-
-        e = n;
     }
 
     pa_assert(m->defer_events_please_scan == 0);
@@ -651,7 +639,7 @@ static void rebuild_pollfds(pa_mainloop *m) {
         m->n_pollfds++;
     }
 
-    for (e = m->io_events; e; e = e->next) {
+    PA_LLIST_FOREACH(e, m->io_events) {
         if (e->dead) {
             e->pollfd = NULL;
             continue;
@@ -675,16 +663,22 @@ static int dispatch_pollfds(pa_mainloop *m) {
 
     pa_assert(m->poll_func_ret > 0);
 
-    for (e = m->io_events, k = m->poll_func_ret; e && !m->quit && k > 0; e = e->next) {
+    k = m->poll_func_ret;
+
+    PA_LLIST_FOREACH(e, m->io_events) {
+
+        if (k <= 0 || m->quit)
+            break;
+
         if (e->dead || !e->pollfd || !e->pollfd->revents)
             continue;
 
         pa_assert(e->pollfd->fd == e->fd);
         pa_assert(e->callback);
+
         e->callback(&m->api, e, e->fd, map_flags_from_libc(e->pollfd->revents), e->userdata);
         e->pollfd->revents = 0;
         r++;
-
         k--;
     }
 
@@ -698,7 +692,11 @@ static int dispatch_defer(pa_mainloop *m) {
     if (m->n_enabled_defer_events <= 0)
         return 0;
 
-    for (e = m->defer_events; e && !m->quit; e = e->next) {
+    PA_LLIST_FOREACH(e, m->defer_events) {
+
+        if (m->quit)
+            break;
+
         if (e->dead || !e->enabled)
             continue;
 
@@ -717,7 +715,7 @@ static pa_time_event* find_next_time_event(pa_mainloop *m) {
     if (m->cached_next_time_event)
         return m->cached_next_time_event;
 
-    for (t = m->time_events; t; t = t->next) {
+    PA_LLIST_FOREACH(t, m->time_events) {
 
         if (t->dead || !t->enabled)
             continue;
@@ -766,7 +764,10 @@ static int dispatch_timeout(pa_mainloop *m) {
 
     now = pa_rtclock_now();
 
-    for (e = m->time_events; e && !m->quit; e = e->next) {
+    PA_LLIST_FOREACH(e, m->time_events) {
+
+        if (m->quit)
+            break;
 
         if (e->dead || !e->enabled)
             continue;
@@ -806,7 +807,8 @@ static void clear_wakeup(pa_mainloop *m) {
         return;
 
     if (m->wakeup_requested) {
-        while (pa_read(m->wakeup_pipe[0], &c, sizeof(c), &m->wakeup_pipe_type) == sizeof(c));
+        while (pa_read(m->wakeup_pipe[0], &c, sizeof(c), &m->wakeup_pipe_type) == sizeof(c))
+            ;
         m->wakeup_requested = 0;
     }
 }
@@ -964,7 +966,8 @@ quit:
 int pa_mainloop_run(pa_mainloop *m, int *retval) {
     int r;
 
-    while ((r = pa_mainloop_iterate(m, 1, retval)) >= 0);
+    while ((r = pa_mainloop_iterate(m, 1, retval)) >= 0)
+        ;
 
     if (r == -2)
         return 1;
@@ -984,6 +987,7 @@ void pa_mainloop_quit(pa_mainloop *m, int retval) {
 
 pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m) {
     pa_assert(m);
+
     return &m->api;
 }
 

commit fb4a2a1bbbd35601b5da62037c1cee40be859428
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:05:10 2009 +0200

    mainloop: sum up dispatched events in an unsigned to clarify range

diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 67f095b..62659d8 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -657,9 +657,9 @@ static void rebuild_pollfds(pa_mainloop *m) {
     m->rebuild_pollfds = FALSE;
 }
 
-static int dispatch_pollfds(pa_mainloop *m) {
+static unsigned dispatch_pollfds(pa_mainloop *m) {
     pa_io_event *e;
-    int r = 0, k;
+    unsigned r = 0, k;
 
     pa_assert(m->poll_func_ret > 0);
 
@@ -685,9 +685,9 @@ static int dispatch_pollfds(pa_mainloop *m) {
     return r;
 }
 
-static int dispatch_defer(pa_mainloop *m) {
+static unsigned dispatch_defer(pa_mainloop *m) {
     pa_defer_event *e;
-    int r = 0;
+    unsigned r = 0;
 
     if (m->n_enabled_defer_events <= 0)
         return 0;
@@ -753,10 +753,10 @@ static pa_usec_t calc_next_timeout(pa_mainloop *m) {
     return t->time - clock_now;
 }
 
-static int dispatch_timeout(pa_mainloop *m) {
+static unsigned dispatch_timeout(pa_mainloop *m) {
     pa_time_event *e;
     pa_usec_t now;
-    int r = 0;
+    unsigned r = 0;
     pa_assert(m);
 
     if (m->n_enabled_time_events <= 0)
@@ -903,7 +903,7 @@ quit:
 }
 
 int pa_mainloop_dispatch(pa_mainloop *m) {
-    int dispatched = 0;
+    unsigned dispatched = 0;
 
     pa_assert(m);
     pa_assert(m->state == STATE_POLLED);
@@ -929,7 +929,7 @@ int pa_mainloop_dispatch(pa_mainloop *m) {
 
     m->state = STATE_PASSIVE;
 
-    return dispatched;
+    return (int) dispatched;
 
 quit:
     m->state = STATE_QUIT;
@@ -938,6 +938,7 @@ quit:
 
 int pa_mainloop_get_retval(pa_mainloop *m) {
     pa_assert(m);
+
     return m->retval;
 }
 

commit 56f217f3f8b43a02a72bf28e049f9a20738843c8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:05:54 2009 +0200

    macro: introduce PA_INT_TYPE_MIN, PA_INT_TYPE_MAX, PA_INT_TYPE_SIGNED macros

diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h
index bffcc26..9a5a267 100644
--- a/src/pulsecore/macro.h
+++ b/src/pulsecore/macro.h
@@ -304,6 +304,18 @@ typedef int pa_bool_t;
 #define pa_memzero(x,l) (memset((x), 0, (l)))
 #define pa_zero(x) (pa_memzero(&(x), sizeof(x)))
 
+#define PA_INT_TYPE_SIGNED(type) (!!((type) 0 > (type) -1))
+
+#define PA_INT_TYPE_MAX(type)                                          \
+    ((type) (PA_INT_TYPE_SIGNED(type)                                  \
+             ? ~(~(type) 0 << (8*sizeof(type)-1))                      \
+             : (type) -1))
+
+#define PA_INT_TYPE_MIN(type)                                          \
+    ((type) (PA_INT_TYPE_SIGNED(type)                                  \
+             ? (~(type) 0 << (8*sizeof(type)-1))                       \
+             : (type) 0))
+
 /* We include this at the very last place */
 #include <pulsecore/log.h>
 

commit f7d38965b355b4932e7a17774e4625f57248f845
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:07:12 2009 +0200

    timeval: introduce PA_USEC_MAX

diff --git a/src/pulse/timeval.h b/src/pulse/timeval.h
index 48c6cdb..3cea5d3 100644
--- a/src/pulse/timeval.h
+++ b/src/pulse/timeval.h
@@ -51,12 +51,15 @@ PA_C_DECL_BEGIN
 /** The number of nanoseconds in a microsecond */
 #define PA_NSEC_PER_USEC ((unsigned long long) 1000ULL)
 
-/** Invalid time in usec */
+/** Invalid time in usec. \since 0.9.15 */
 #define PA_USEC_INVALID ((pa_usec_t) -1)
 
+/** Biggest time in usec. \since 0.9.18 */
+#define PA_USEC_MAX ((pa_usec_t) -2)
+
 struct timeval;
 
-/** Return the current timestamp, just like UNIX gettimeofday() */
+/** Return the current wallclock timestamp, just like UNIX gettimeofday(). */
 struct timeval *pa_gettimeofday(struct timeval *tv);
 
 /** Calculate the difference between the two specified timeval

commit fdec460661faa802c1acf9d985990c2d1b4fa1a3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:08:36 2009 +0200

    core-rtclock: introduce pa_timespec_store() akin pa_timeval_store()

diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c
index 3b3e3a6..7690ab7 100644
--- a/src/pulsecore/core-rtclock.c
+++ b/src/pulsecore/core-rtclock.c
@@ -151,6 +151,20 @@ pa_usec_t pa_timespec_load(const struct timespec *ts) {
         (pa_usec_t) ts->tv_nsec / PA_NSEC_PER_USEC;
 }
 
+struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v) {
+    pa_assert(ts);
+
+    if (PA_UNLIKELY(v == PA_USEC_INVALID)) {
+        ts->tv_sec = PA_INT_TYPE_MAX(time_t);
+        ts->tv_nsec = (long) (PA_NSEC_PER_SEC-1);
+        return NULL;
+    }
+
+    ts->tv_sec = (time_t) (v / PA_USEC_PER_SEC);
+    ts->tv_nsec = (long) ((v % PA_USEC_PER_SEC) * PA_NSEC_PER_USEC);
+
+    return ts;
+}
 
 static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
 
diff --git a/src/pulsecore/core-rtclock.h b/src/pulsecore/core-rtclock.h
index 9f5ae2d..3b393ed 100644
--- a/src/pulsecore/core-rtclock.h
+++ b/src/pulsecore/core-rtclock.h
@@ -44,6 +44,7 @@ void pa_rtclock_hrtimer_enable(void);
 struct timeval* pa_rtclock_from_wallclock(struct timeval *tv);
 
 pa_usec_t pa_timespec_load(const struct timespec *ts);
+struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v);
 
 struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock);
 

commit 05f6236a83414573587c73dbc439e68dae5f529e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:10:26 2009 +0200

    timeval: make pa_timeval_sub saturating

diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index 376cf13..1a0d3ce 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -33,6 +33,7 @@
 
 #include <pulsecore/winsock.h>
 #include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
 
 #include "timeval.h"
 
@@ -54,9 +55,9 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
 #define EPOCHFILETIME (116444736000000000LL)
 #endif
 
-    FILETIME        ft;
-    LARGE_INTEGER   li;
-    __int64         t;
+    FILETIME ft;
+    LARGE_INTEGER li;
+    int64_t t;
 
     pa_assert(tv);
 
@@ -128,40 +129,65 @@ pa_usec_t pa_timeval_age(const struct timeval *tv) {
 }
 
 struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
-    unsigned long secs;
+    time_t secs;
     pa_assert(tv);
 
-    secs = (unsigned long) (v/PA_USEC_PER_SEC);
-    tv->tv_sec += (time_t) secs;
-    v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC;
+    secs = (time_t) (v/PA_USEC_PER_SEC);
 
+    if (PA_UNLIKELY(tv->tv_sec > PA_INT_TYPE_MAX(time_t) - secs))
+        goto overflow;
+
+    tv->tv_sec += secs;
+    v -= (pa_usec_t) secs * PA_USEC_PER_SEC;
     tv->tv_usec += (suseconds_t) v;
 
     /* Normalize */
-    while ((unsigned) tv->tv_usec >= PA_USEC_PER_SEC) {
+    while ((pa_usec_t) tv->tv_usec >= PA_USEC_PER_SEC) {
+
+        if (PA_UNLIKELY(tv->tv_sec >= PA_INT_TYPE_MAX(time_t)))
+            goto overflow;
+
         tv->tv_sec++;
         tv->tv_usec -= (suseconds_t) PA_USEC_PER_SEC;
     }
 
     return tv;
+
+overflow:
+    tv->tv_sec = PA_INT_TYPE_MAX(time_t);
+    tv->tv_usec = (suseconds_t) (PA_USEC_PER_SEC-1);
+    return tv;
 }
 
 struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v) {
-    unsigned long secs;
+    time_t secs;
     pa_assert(tv);
 
-    secs = (unsigned long) (v/PA_USEC_PER_SEC);
-    tv->tv_sec -= (time_t) secs;
-    v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC;
+    secs = (time_t) (v/PA_USEC_PER_SEC);
+
+    if (PA_UNLIKELY(tv->tv_sec < secs))
+        goto underflow;
+
+    tv->tv_sec -= secs;
+    v -= (pa_usec_t) secs * PA_USEC_PER_SEC;
 
     if (tv->tv_usec >= (suseconds_t) v)
         tv->tv_usec -= (suseconds_t) v;
     else {
+
+        if (PA_UNLIKELY(tv->tv_sec <= 0))
+            goto underflow;
+
         tv->tv_sec --;
         tv->tv_usec += (suseconds_t) (PA_USEC_PER_SEC - v);
     }
 
     return tv;
+
+underflow:
+    tv->tv_sec = 0;
+    tv->tv_usec = 0;
+    return tv;
 }
 
 struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) {

commit a1da83b206d4a73bfa537ab3694bac7244bd19a1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:11:02 2009 +0200

    timeval: add UNLIKELY annotation

diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index 1a0d3ce..87569cf 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -83,7 +83,7 @@ pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
     pa_assert(b);
 
     /* Check which whan is the earlier time and swap the two arguments if required. */
-    if (pa_timeval_cmp(a, b) < 0) {
+    if (PA_UNLIKELY(pa_timeval_cmp(a, b) < 0)) {
         const struct timeval *c;
         c = a;
         a = b;
@@ -95,9 +95,9 @@ pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
 
     /* Calculate the microsecond difference */
     if (a->tv_usec > b->tv_usec)
-        r += ((pa_usec_t) a->tv_usec - (pa_usec_t) b->tv_usec);
+        r += (pa_usec_t) a->tv_usec - (pa_usec_t) b->tv_usec;
     else if (a->tv_usec < b->tv_usec)
-        r -= ((pa_usec_t) b->tv_usec - (pa_usec_t) a->tv_usec);
+        r -= (pa_usec_t) b->tv_usec - (pa_usec_t) a->tv_usec;
 
     return r;
 }

commit c024aeaae91c139914dc928df975ea311729052c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 18 04:11:59 2009 +0200

    timeval: make timeval conversion routines handle PA_USEC_INVALID special

diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index 87569cf..cde4417 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -193,6 +193,13 @@ underflow:
 struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) {
     pa_assert(tv);
 
+    if (PA_UNLIKELY(v == PA_USEC_INVALID)) {
+        tv->tv_sec = PA_INT_TYPE_MAX(time_t);
+        tv->tv_usec = (suseconds_t) (PA_USEC_PER_SEC-1);
+
+        return tv;
+    }
+
     tv->tv_sec = (time_t) (v / PA_USEC_PER_SEC);
     tv->tv_usec = (suseconds_t) (v % PA_USEC_PER_SEC);
 
@@ -200,7 +207,9 @@ struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) {
 }
 
 pa_usec_t pa_timeval_load(const struct timeval *tv) {
-    pa_assert(tv);
+
+    if (PA_UNLIKELY(!tv))
+        return PA_USEC_INVALID;
 
     return
         (pa_usec_t) tv->tv_sec * PA_USEC_PER_SEC +
diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c
index 7690ab7..1420470 100644
--- a/src/pulsecore/core-rtclock.c
+++ b/src/pulsecore/core-rtclock.c
@@ -132,6 +132,8 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
 
     pa_assert(tv);
 
+    /* pa_timeval_sub() saturates on underflow! */
+
     if (pa_timeval_cmp(&wc_now, tv) < 0)
         pa_timeval_add(&rt_now, pa_timeval_diff(tv, &wc_now));
     else
@@ -144,7 +146,9 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
 }
 
 pa_usec_t pa_timespec_load(const struct timespec *ts) {
-    pa_assert(ts);
+
+    if (PA_UNLIKELY(!ts))
+        return PA_USEC_INVALID;
 
     return
         (pa_usec_t) ts->tv_sec * PA_USEC_PER_SEC +
@@ -176,6 +180,8 @@ static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
 
     pa_assert(tv);
 
+    /* pa_timeval_sub() saturates on underflow! */
+
     if (pa_timeval_cmp(&rt_now, tv) < 0)
         pa_timeval_add(&wc_now, pa_timeval_diff(tv, &rt_now));
     else

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list