1 | #ifndef footimevalhfoo |
2 | #define footimevalhfoo |
3 | |
4 | /*** |
5 | This file is part of PulseAudio. |
6 | |
7 | Copyright 2004-2006 Lennart Poettering |
8 | Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB |
9 | |
10 | PulseAudio is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU Lesser General Public License as |
12 | published by the Free Software Foundation; either version 2.1 of the |
13 | License, or (at your option) any later version. |
14 | |
15 | PulseAudio is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 | Lesser General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Lesser General Public |
21 | License along with PulseAudio; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
23 | USA. |
24 | ***/ |
25 | |
26 | #include <pulse/cdecl.h> |
27 | #include <pulse/gccmacro.h> |
28 | #include <pulse/sample.h> |
29 | #include <pulse/version.h> |
30 | |
31 | /** \file |
32 | * Utility functions for handling timeval calculations */ |
33 | |
34 | PA_C_DECL_BEGIN |
35 | |
36 | /** The number of milliseconds in a second */ |
37 | #define PA_MSEC_PER_SEC ((pa_usec_t) 1000ULL) |
38 | |
39 | /** The number of microseconds in a second */ |
40 | #define PA_USEC_PER_SEC ((pa_usec_t) 1000000ULL) |
41 | |
42 | /** The number of nanoseconds in a second */ |
43 | #define PA_NSEC_PER_SEC ((unsigned long long) 1000000000ULL) |
44 | |
45 | /** The number of microseconds in a millisecond */ |
46 | #define PA_USEC_PER_MSEC ((pa_usec_t) 1000ULL) |
47 | |
48 | /** The number of nanoseconds in a millisecond */ |
49 | #define PA_NSEC_PER_MSEC ((unsigned long long) 1000000ULL) |
50 | |
51 | /** The number of nanoseconds in a microsecond */ |
52 | #define PA_NSEC_PER_USEC ((unsigned long long) 1000ULL) |
53 | |
54 | /** Invalid time in usec. \since 0.9.15 */ |
55 | #define PA_USEC_INVALID ((pa_usec_t) -1) |
56 | |
57 | /** Biggest time in usec. \since 0.9.18 */ |
58 | #define PA_USEC_MAX ((pa_usec_t) -2) |
59 | |
60 | struct timeval; |
61 | |
62 | /** Return the current wallclock timestamp, just like UNIX gettimeofday(). */ |
63 | struct timeval *pa_gettimeofday(struct timeval *tv); |
64 | |
65 | /** Calculate the difference between the two specified timeval |
66 | * structs. */ |
67 | pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) PA_GCC_PURE; |
68 | |
69 | /** Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwise */ |
70 | int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) PA_GCC_PURE; |
71 | |
72 | /** Return the time difference between now and the specified timestamp */ |
73 | pa_usec_t pa_timeval_age(const struct timeval *tv); |
74 | |
75 | /** Add the specified time in microseconds to the specified timeval structure */ |
76 | struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v); |
77 | |
78 | /** Subtract the specified time in microseconds to the specified timeval structure. \since 0.9.11 */ |
79 | struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v); |
80 | |
81 | /** Store the specified usec value in the timeval struct. \since 0.9.7 */ |
82 | struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v); |
83 | |
84 | /** Load the specified tv value and return it in usec. \since 0.9.7 */ |
85 | pa_usec_t pa_timeval_load(const struct timeval *tv); |
86 | |
87 | PA_C_DECL_END |
88 | |
89 | #endif |
90 | |