diff --git a/doxygen/doxygen.conf.in b/doxygen/doxygen.conf.in index 3d7ad3222..f466c9d47 100644 --- a/doxygen/doxygen.conf.in +++ b/doxygen/doxygen.conf.in @@ -417,7 +417,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = ../src/polyp/context.h ../src/polyp/stream.h ../src/polyp/polypaudio.h ../src/polyp/sample.h ../src/polyp/def.h ../src/polyp/subscribe.h ../src/polyp/introspect.h ../src/polyp/scache.h ../src/polyp/mainloop-api.h ../src/polyp/glib-mainloop.h ../src/polyp/mainloop.h ../src/polyp/mainloop-signal.h ../src/polyp/error.h ../src/polyp/operation.h ../src/polyp/simple.h ../src/polyp/version.h ../src/polyp/volume.h ../src/polyp/channelmap.h ../src/polyp/thread-mainloop.h ../src/polyp/xmalloc.h ../src/polyp/utf8.h ../src/polyp/util.h +INPUT = ../src/polyp/context.h ../src/polyp/stream.h ../src/polyp/polypaudio.h ../src/polyp/sample.h ../src/polyp/def.h ../src/polyp/subscribe.h ../src/polyp/introspect.h ../src/polyp/scache.h ../src/polyp/mainloop-api.h ../src/polyp/glib-mainloop.h ../src/polyp/mainloop.h ../src/polyp/mainloop-signal.h ../src/polyp/error.h ../src/polyp/operation.h ../src/polyp/simple.h ../src/polyp/version.h ../src/polyp/volume.h ../src/polyp/channelmap.h ../src/polyp/thread-mainloop.h ../src/polyp/xmalloc.h ../src/polyp/utf8.h ../src/polyp/util.h ../src/polyp/timeval.h # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e7ad2fd4a..b0401e650 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -351,6 +351,7 @@ libpolyp_la_SOURCES = \ polyp/stream.c polyp/stream.h \ polyp/subscribe.c polyp/subscribe.h \ polyp/sample.c polyp/sample.h \ + polyp/timeval.c polyp/timeval.h \ polyp/volume.c polyp/volume.h \ polyp/utf8.c polyp/utf8.h \ polyp/mainloop.c polyp/mainloop.h \ @@ -493,9 +494,10 @@ libpolypcore_la_SOURCES = \ polyp/mainloop-signal.c polyp/mainloop-signal.h \ polyp/sample.c polyp/sample.h \ polyp/volume.c polyp/volume.h \ + polyp/timeval.c polyp/timeval.h \ polyp/utf8.c polyp/utf8.h \ - polyp/xmalloc.c polyp/xmalloc.h \ - polyp/util.c polyp/util.h + polyp/util.c polyp/util.h \ + polyp/xmalloc.c polyp/xmalloc.h # Pure core stuff (some are shared in libpolyp though). libpolypcore_la_SOURCES += \ diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c index 5047fc306..037cbaf71 100644 --- a/src/modules/module-combine.c +++ b/src/modules/module-combine.c @@ -26,6 +26,7 @@ #include #include +#include #include #include diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 78850011c..a1555e672 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -33,6 +33,7 @@ #include #include +#include #include #include diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index 81c322879..758d1bd6e 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -31,6 +31,7 @@ #include #include +#include #include #include diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c index a1196a2d3..56fc91ef1 100644 --- a/src/modules/rtp/module-rtp-recv.c +++ b/src/modules/rtp/module-rtp-recv.c @@ -31,6 +31,7 @@ #include #include +#include #include #include diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index a88ea76af..4ca2b1e62 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -32,6 +32,7 @@ #include #include +#include #include #include diff --git a/src/polyp/glib12-mainloop.c b/src/polyp/glib12-mainloop.c index f7459f192..dfd6ff2f1 100644 --- a/src/polyp/glib12-mainloop.c +++ b/src/polyp/glib12-mainloop.c @@ -25,6 +25,7 @@ #include +#include #include #include diff --git a/src/polyp/mainloop.c b/src/polyp/mainloop.c index 8f44c180c..6b5b3b252 100644 --- a/src/polyp/mainloop.c +++ b/src/polyp/mainloop.c @@ -44,6 +44,7 @@ #include "../polypcore/pipe.h" #endif +#include #include #include diff --git a/src/polyp/polypaudio.h b/src/polyp/polypaudio.h index 51e3f9703..c172315b2 100644 --- a/src/polyp/polypaudio.h +++ b/src/polyp/polypaudio.h @@ -41,6 +41,7 @@ #include #include #include +#include /** \file * Include all polyplib header files at once. The following @@ -48,7 +49,8 @@ * \ref context.h, \ref stream.h, \ref introspect.h, \ref subscribe.h, * \ref scache.h, \ref version.h, \ref error.h, \ref channelmap.h, * \ref operation.h,\ref volume.h, \ref xmalloc.h, \ref utf8.h, \ref - * thread-mainloop.h, \ref mainloop.h, \ref util.h and \ref mainloop-signal.h at once */ + * thread-mainloop.h, \ref mainloop.h, \ref util.h, \ref timeval.h and + * \ref mainloop-signal.h at once */ /** \mainpage * diff --git a/src/polyp/timeval.c b/src/polyp/timeval.c new file mode 100644 index 000000000..6043d7fd2 --- /dev/null +++ b/src/polyp/timeval.c @@ -0,0 +1,142 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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.1 of the + License, or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#ifdef HAVE_WINDOWS_H +#include +#endif + +#include "../polypcore/winsock.h" + +#include "timeval.h" + +struct timeval *pa_gettimeofday(struct timeval *tv) { +#ifdef HAVE_GETTIMEOFDAY + assert(tv); + + return gettimeofday(tv, NULL) < 0 ? NULL : tv; +#elif defined(OS_IS_WIN32) + /* + * Copied from implementation by Steven Edwards (LGPL). + * Found on wine mailing list. + */ + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define EPOCHFILETIME (116444736000000000i64) +#else +#define EPOCHFILETIME (116444736000000000LL) +#endif + + FILETIME ft; + LARGE_INTEGER li; + __int64 t; + + assert(tv); + + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + t = li.QuadPart; /* In 100-nanosecond intervals */ + t -= EPOCHFILETIME; /* Offset to the Epoch time */ + t /= 10; /* In microseconds */ + tv->tv_sec = (long)(t / 1000000); + tv->tv_usec = (long)(t % 1000000); + + return tv; +#else +#error "Platform lacks gettimeofday() or equivalent function." +#endif +} + +pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) { + pa_usec_t r; + assert(a && b); + + /* Check which whan is the earlier time and swap the two arguments if reuqired. */ + if (pa_timeval_cmp(a, b) < 0) { + const struct timeval *c; + c = a; + a = b; + b = c; + } + + /* Calculate the second difference*/ + r = ((pa_usec_t) a->tv_sec - b->tv_sec)* 1000000; + + /* Calculate the microsecond difference */ + if (a->tv_usec > b->tv_usec) + r += ((pa_usec_t) a->tv_usec - b->tv_usec); + else if (a->tv_usec < b->tv_usec) + r -= ((pa_usec_t) b->tv_usec - a->tv_usec); + + return r; +} + +int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) { + assert(a && b); + + if (a->tv_sec < b->tv_sec) + return -1; + + if (a->tv_sec > b->tv_sec) + return 1; + + if (a->tv_usec < b->tv_usec) + return -1; + + if (a->tv_usec > b->tv_usec) + return 1; + + return 0; +} + +pa_usec_t pa_timeval_age(const struct timeval *tv) { + struct timeval now; + assert(tv); + + return pa_timeval_diff(pa_gettimeofday(&now), tv); +} + +struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) { + unsigned long secs; + assert(tv); + + secs = (v/1000000); + tv->tv_sec += (unsigned long) secs; + v -= secs*1000000; + + tv->tv_usec += v; + + /* Normalize */ + while (tv->tv_usec >= 1000000) { + tv->tv_sec++; + tv->tv_usec -= 1000000; + } + + return tv; +} diff --git a/src/polyp/timeval.h b/src/polyp/timeval.h new file mode 100644 index 000000000..9990d4cae --- /dev/null +++ b/src/polyp/timeval.h @@ -0,0 +1,53 @@ +#ifndef footimevalhfoo +#define footimevalhfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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.1 of the + License, or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include +#include + +/** \file + * Utility functions for handling timeval calculations */ + +PA_C_DECL_BEGIN + +struct timeval; + +/** Return the current timestamp, just like UNIX gettimeofday() */ +struct timeval *pa_gettimeofday(struct timeval *tv); + +/** Calculate the difference between the two specified timeval + * structs. */ +pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b); + +/** Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwse */ +int pa_timeval_cmp(const struct timeval *a, const struct timeval *b); + +/** Return the time difference between now and the specified timestamp */ +pa_usec_t pa_timeval_age(const struct timeval *tv); + +/** Add the specified time inmicroseconds to the specified timeval structure */ +struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v); + +PA_C_DECL_END + +#endif diff --git a/src/polyp/util.c b/src/polyp/util.c index 76b5c9b97..dcebff595 100644 --- a/src/polyp/util.c +++ b/src/polyp/util.c @@ -23,39 +23,33 @@ #include #endif -#include -#include -#include -#include #include -#include +#include #include -#include -#include -#include +#include +#include #include -#include +#include #include -#include -#include - -#ifdef HAVE_NETDB_H -#include -#endif #ifdef HAVE_PWD_H #include #endif -#ifdef HAVE_GRP_H -#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#ifdef HAVE_NETDB_H +#include #endif #ifdef HAVE_WINDOWS_H #include #endif -#include +#include "../polypcore/winsock.h" + #include #include @@ -154,112 +148,6 @@ char *pa_get_home_dir(char *s, size_t l) { #endif } -struct timeval *pa_gettimeofday(struct timeval *tv) { -#ifdef HAVE_GETTIMEOFDAY - assert(tv); - - return gettimeofday(tv, NULL) < 0 ? NULL : tv; -#elif defined(OS_IS_WIN32) - /* - * Copied from implementation by Steven Edwards (LGPL). - * Found on wine mailing list. - */ - -#if defined(_MSC_VER) || defined(__BORLANDC__) -#define EPOCHFILETIME (116444736000000000i64) -#else -#define EPOCHFILETIME (116444736000000000LL) -#endif - - FILETIME ft; - LARGE_INTEGER li; - __int64 t; - - assert(tv); - - GetSystemTimeAsFileTime(&ft); - li.LowPart = ft.dwLowDateTime; - li.HighPart = ft.dwHighDateTime; - t = li.QuadPart; /* In 100-nanosecond intervals */ - t -= EPOCHFILETIME; /* Offset to the Epoch time */ - t /= 10; /* In microseconds */ - tv->tv_sec = (long)(t / 1000000); - tv->tv_usec = (long)(t % 1000000); - - return tv; -#else -#error "Platform lacks gettimeofday() or equivalent function." -#endif -} - -pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) { - pa_usec_t r; - assert(a && b); - - /* Check which whan is the earlier time and swap the two arguments if reuqired. */ - if (pa_timeval_cmp(a, b) < 0) { - const struct timeval *c; - c = a; - a = b; - b = c; - } - - /* Calculate the second difference*/ - r = ((pa_usec_t) a->tv_sec - b->tv_sec)* 1000000; - - /* Calculate the microsecond difference */ - if (a->tv_usec > b->tv_usec) - r += ((pa_usec_t) a->tv_usec - b->tv_usec); - else if (a->tv_usec < b->tv_usec) - r -= ((pa_usec_t) b->tv_usec - a->tv_usec); - - return r; -} - -int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) { - assert(a && b); - - if (a->tv_sec < b->tv_sec) - return -1; - - if (a->tv_sec > b->tv_sec) - return 1; - - if (a->tv_usec < b->tv_usec) - return -1; - - if (a->tv_usec > b->tv_usec) - return 1; - - return 0; -} - -pa_usec_t pa_timeval_age(const struct timeval *tv) { - struct timeval now; - assert(tv); - - return pa_timeval_diff(pa_gettimeofday(&now), tv); -} - -struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) { - unsigned long secs; - assert(tv); - - secs = (v/1000000); - tv->tv_sec += (unsigned long) secs; - v -= secs*1000000; - - tv->tv_usec += v; - - /* Normalize */ - while (tv->tv_usec >= 1000000) { - tv->tv_sec++; - tv->tv_usec -= 1000000; - } - - return tv; -} - char *pa_get_binary_name(char *s, size_t l) { #ifdef HAVE_READLINK diff --git a/src/polyp/util.h b/src/polyp/util.h index 8bd03f98a..cd8aab0bd 100644 --- a/src/polyp/util.h +++ b/src/polyp/util.h @@ -22,10 +22,8 @@ USA. ***/ -#include -#include +#include -#include #include /** \file @@ -33,8 +31,6 @@ PA_C_DECL_BEGIN -struct timeval; - /** Return the current username in the specified string buffer. */ char *pa_get_user_name(char *s, size_t l); @@ -55,22 +51,6 @@ char *pa_get_binary_name(char *s, size_t l); * component). */ const char *pa_path_get_filename(const char *p); -/** Return the current timestamp, just like UNIX gettimeofday() */ -struct timeval *pa_gettimeofday(struct timeval *tv); - -/** Calculate the difference between the two specified timeval - * structs. */ -pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b); - -/** Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwse */ -int pa_timeval_cmp(const struct timeval *a, const struct timeval *b); - -/** Return the time difference between now and the specified timestamp */ -pa_usec_t pa_timeval_age(const struct timeval *tv); - -/** Add the specified time inmicroseconds to the specified timeval structure */ -struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v); - /** Wait t milliseconds */ int pa_msleep(unsigned long t); diff --git a/src/polypcore/core-scache.c b/src/polypcore/core-scache.c index 068f2361d..1ee3361f8 100644 --- a/src/polypcore/core-scache.c +++ b/src/polypcore/core-scache.c @@ -43,6 +43,7 @@ #include #include +#include #include #include diff --git a/src/polypcore/core.c b/src/polypcore/core.c index 43f7015e0..09d023dce 100644 --- a/src/polypcore/core.c +++ b/src/polypcore/core.c @@ -28,6 +28,7 @@ #include #include +#include #include #include diff --git a/src/polypcore/module.c b/src/polypcore/module.c index 52cde9c39..0286bba85 100644 --- a/src/polypcore/module.c +++ b/src/polypcore/module.c @@ -30,6 +30,7 @@ #include #include +#include #include #include diff --git a/src/polypcore/pdispatch.c b/src/polypcore/pdispatch.c index 4b0d1bb27..c6f90bac4 100644 --- a/src/polypcore/pdispatch.c +++ b/src/polypcore/pdispatch.c @@ -27,6 +27,7 @@ #include #include +#include #include #include diff --git a/src/polypcore/protocol-esound.c b/src/polypcore/protocol-esound.c index 98738728a..c11bdb21c 100644 --- a/src/polypcore/protocol-esound.c +++ b/src/polypcore/protocol-esound.c @@ -31,6 +31,7 @@ #include #include +#include #include #include diff --git a/src/polypcore/protocol-native.c b/src/polypcore/protocol-native.c index f0e50ec54..0a408c6d6 100644 --- a/src/polypcore/protocol-native.c +++ b/src/polypcore/protocol-native.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include diff --git a/src/polypcore/socket-client.c b/src/polypcore/socket-client.c index 4fb0a5d89..ec2f9a9e3 100644 --- a/src/polypcore/socket-client.c +++ b/src/polypcore/socket-client.c @@ -54,6 +54,7 @@ #include "winsock.h" +#include #include #include diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index 300884839..2936420c3 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-test.c @@ -28,6 +28,8 @@ #include #include +#include + #include #include diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 676b8d37e..701444312 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -28,6 +28,8 @@ #include #include +#include + #include #include #include