mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2026-01-01 11:08:36 -05:00
modernizations
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1681 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
2d292befab
commit
fa7fc315bd
2 changed files with 27 additions and 20 deletions
|
|
@ -26,7 +26,6 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
@ -34,15 +33,17 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../pulsecore/winsock.h"
|
#include <pulsecore/winsock.h>
|
||||||
|
#include <pulsecore/macro.h>
|
||||||
|
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
|
|
||||||
struct timeval *pa_gettimeofday(struct timeval *tv) {
|
struct timeval *pa_gettimeofday(struct timeval *tv) {
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
assert(tv);
|
pa_assert(tv);
|
||||||
|
|
||||||
return gettimeofday(tv, NULL) < 0 ? NULL : tv;
|
pa_assert_se(gettimeofday(tv, NULL) == 0);
|
||||||
|
return tv;
|
||||||
#elif defined(OS_IS_WIN32)
|
#elif defined(OS_IS_WIN32)
|
||||||
/*
|
/*
|
||||||
* Copied from implementation by Steven Edwards (LGPL).
|
* Copied from implementation by Steven Edwards (LGPL).
|
||||||
|
|
@ -54,12 +55,12 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
|
||||||
#else
|
#else
|
||||||
#define EPOCHFILETIME (116444736000000000LL)
|
#define EPOCHFILETIME (116444736000000000LL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
__int64 t;
|
__int64 t;
|
||||||
|
|
||||||
assert(tv);
|
pa_assert(tv);
|
||||||
|
|
||||||
GetSystemTimeAsFileTime(&ft);
|
GetSystemTimeAsFileTime(&ft);
|
||||||
li.LowPart = ft.dwLowDateTime;
|
li.LowPart = ft.dwLowDateTime;
|
||||||
|
|
@ -67,8 +68,8 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
|
||||||
t = li.QuadPart; /* In 100-nanosecond intervals */
|
t = li.QuadPart; /* In 100-nanosecond intervals */
|
||||||
t -= EPOCHFILETIME; /* Offset to the Epoch time */
|
t -= EPOCHFILETIME; /* Offset to the Epoch time */
|
||||||
t /= 10; /* In microseconds */
|
t /= 10; /* In microseconds */
|
||||||
tv->tv_sec = (long)(t / 1000000);
|
tv->tv_sec = (time_t) (t / PA_USEC_PER_SEC);
|
||||||
tv->tv_usec = (long)(t % 1000000);
|
tv->tv_usec = (suseconds_t) (t % PA_USEC_PER_SEC);
|
||||||
|
|
||||||
return tv;
|
return tv;
|
||||||
#else
|
#else
|
||||||
|
|
@ -78,9 +79,10 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
|
||||||
|
|
||||||
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
|
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
|
||||||
pa_usec_t r;
|
pa_usec_t r;
|
||||||
assert(a && b);
|
pa_assert(a);
|
||||||
|
pa_assert(b);
|
||||||
|
|
||||||
/* Check which whan is the earlier time and swap the two arguments if reuqired. */
|
/* Check which whan is the earlier time and swap the two arguments if required. */
|
||||||
if (pa_timeval_cmp(a, b) < 0) {
|
if (pa_timeval_cmp(a, b) < 0) {
|
||||||
const struct timeval *c;
|
const struct timeval *c;
|
||||||
c = a;
|
c = a;
|
||||||
|
|
@ -89,7 +91,7 @@ pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the second difference*/
|
/* Calculate the second difference*/
|
||||||
r = ((pa_usec_t) a->tv_sec - b->tv_sec)* 1000000;
|
r = ((pa_usec_t) a->tv_sec - b->tv_sec) * PA_USEC_PER_SEC;
|
||||||
|
|
||||||
/* Calculate the microsecond difference */
|
/* Calculate the microsecond difference */
|
||||||
if (a->tv_usec > b->tv_usec)
|
if (a->tv_usec > b->tv_usec)
|
||||||
|
|
@ -101,7 +103,8 @@ pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
|
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
|
||||||
assert(a && b);
|
pa_assert(a);
|
||||||
|
pa_assert(b);
|
||||||
|
|
||||||
if (a->tv_sec < b->tv_sec)
|
if (a->tv_sec < b->tv_sec)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -120,25 +123,25 @@ int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
|
||||||
|
|
||||||
pa_usec_t pa_timeval_age(const struct timeval *tv) {
|
pa_usec_t pa_timeval_age(const struct timeval *tv) {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
assert(tv);
|
pa_assert(tv);
|
||||||
|
|
||||||
return pa_timeval_diff(pa_gettimeofday(&now), tv);
|
return pa_timeval_diff(pa_gettimeofday(&now), tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
|
struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
|
||||||
unsigned long secs;
|
unsigned long secs;
|
||||||
assert(tv);
|
pa_assert(tv);
|
||||||
|
|
||||||
secs = (v/1000000);
|
secs = (unsigned long) (v/PA_USEC_PER_SEC);
|
||||||
tv->tv_sec += (unsigned long) secs;
|
tv->tv_sec += secs;
|
||||||
v -= secs*1000000;
|
v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC;
|
||||||
|
|
||||||
tv->tv_usec += v;
|
tv->tv_usec += (suseconds_t) v;
|
||||||
|
|
||||||
/* Normalize */
|
/* Normalize */
|
||||||
while (tv->tv_usec >= 1000000) {
|
while (tv->tv_usec >= PA_USEC_PER_SEC) {
|
||||||
tv->tv_sec++;
|
tv->tv_sec++;
|
||||||
tv->tv_usec -= 1000000;
|
tv->tv_usec -= PA_USEC_PER_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tv;
|
return tv;
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@
|
||||||
|
|
||||||
PA_C_DECL_BEGIN
|
PA_C_DECL_BEGIN
|
||||||
|
|
||||||
|
#define PA_MSEC_PER_SEC 1000
|
||||||
|
#define PA_USEC_PER_SEC 1000000
|
||||||
|
#define PA_NSEC_PER_SEC 1000000000
|
||||||
|
|
||||||
struct timeval;
|
struct timeval;
|
||||||
|
|
||||||
/** Return the current timestamp, just like UNIX gettimeofday() */
|
/** Return the current timestamp, just like UNIX gettimeofday() */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue