/src/avm/avm_ports/avm_timer.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 3-Clause Clear License |
5 | | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
6 | | * License was not distributed with this source code in the LICENSE file, you |
7 | | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
8 | | * Alliance for Open Media Patent License 1.0 was not distributed with this |
9 | | * source code in the PATENTS file, you can obtain it at |
10 | | * aomedia.org/license/patent-license/. |
11 | | */ |
12 | | |
13 | | #ifndef AVM_AVM_PORTS_AVM_TIMER_H_ |
14 | | #define AVM_AVM_PORTS_AVM_TIMER_H_ |
15 | | |
16 | | #include "config/avm_config.h" |
17 | | |
18 | | #include "avm/avm_integer.h" |
19 | | |
20 | | #if CONFIG_OS_SUPPORT |
21 | | |
22 | | #if defined(_WIN32) |
23 | | /* |
24 | | * Win32 specific includes |
25 | | */ |
26 | | #ifndef WIN32_LEAN_AND_MEAN |
27 | | #define WIN32_LEAN_AND_MEAN |
28 | | #endif |
29 | | #include <windows.h> |
30 | | #else |
31 | | /* |
32 | | * POSIX specific includes |
33 | | */ |
34 | | #include <sys/time.h> |
35 | | |
36 | | /* timersub is not provided by msys at this time. */ |
37 | | #ifndef timersub |
38 | | #define timersub(a, b, result) \ |
39 | | do { \ |
40 | | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
41 | | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
42 | | if ((result)->tv_usec < 0) { \ |
43 | | --(result)->tv_sec; \ |
44 | | (result)->tv_usec += 1000000; \ |
45 | | } \ |
46 | | } while (0) |
47 | | #endif |
48 | | #endif |
49 | | |
50 | | struct avm_usec_timer { |
51 | | #if defined(_WIN32) |
52 | | LARGE_INTEGER begin, end; |
53 | | #else |
54 | | struct timeval begin, end; |
55 | | #endif |
56 | | }; |
57 | | |
58 | 0 | static INLINE void avm_usec_timer_start(struct avm_usec_timer *t) { |
59 | 0 | #if defined(_WIN32) |
60 | 0 | QueryPerformanceCounter(&t->begin); |
61 | 0 | #else |
62 | 0 | gettimeofday(&t->begin, NULL); |
63 | 0 | #endif |
64 | 0 | } Unexecuted instantiation: decodeframe.c:avm_usec_timer_start Unexecuted instantiation: decoder.c:avm_usec_timer_start |
65 | | |
66 | 0 | static INLINE void avm_usec_timer_mark(struct avm_usec_timer *t) { |
67 | 0 | #if defined(_WIN32) |
68 | 0 | QueryPerformanceCounter(&t->end); |
69 | 0 | #else |
70 | 0 | gettimeofday(&t->end, NULL); |
71 | 0 | #endif |
72 | 0 | } Unexecuted instantiation: decodeframe.c:avm_usec_timer_mark Unexecuted instantiation: decoder.c:avm_usec_timer_mark |
73 | | |
74 | 0 | static INLINE int64_t avm_usec_timer_elapsed(struct avm_usec_timer *t) { |
75 | 0 | #if defined(_WIN32) |
76 | 0 | LARGE_INTEGER freq, diff; |
77 | 0 |
|
78 | 0 | diff.QuadPart = t->end.QuadPart - t->begin.QuadPart; |
79 | 0 |
|
80 | 0 | QueryPerformanceFrequency(&freq); |
81 | 0 | return diff.QuadPart * 1000000 / freq.QuadPart; |
82 | 0 | #else |
83 | 0 | struct timeval diff; |
84 | 0 |
|
85 | 0 | timersub(&t->end, &t->begin, &diff); |
86 | 0 | return ((int64_t)diff.tv_sec) * 1000000 + diff.tv_usec; |
87 | 0 | #endif |
88 | 0 | } Unexecuted instantiation: decodeframe.c:avm_usec_timer_elapsed Unexecuted instantiation: decoder.c:avm_usec_timer_elapsed |
89 | | |
90 | | #else /* CONFIG_OS_SUPPORT = 0*/ |
91 | | |
92 | | /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */ |
93 | | #ifndef timersub |
94 | | #define timersub(a, b, result) |
95 | | #endif |
96 | | |
97 | | struct avm_usec_timer { |
98 | | void *dummy; |
99 | | }; |
100 | | |
101 | | static INLINE void avm_usec_timer_start(struct avm_usec_timer *t) { (void)t; } |
102 | | |
103 | | static INLINE void avm_usec_timer_mark(struct avm_usec_timer *t) { (void)t; } |
104 | | |
105 | | static INLINE int avm_usec_timer_elapsed(struct avm_usec_timer *t) { |
106 | | (void)t; |
107 | | return 0; |
108 | | } |
109 | | |
110 | | #endif /* CONFIG_OS_SUPPORT */ |
111 | | |
112 | | #endif // AVM_AVM_PORTS_AVM_TIMER_H_ |