Merge "vp9: Fix to quality regression issue for 1 pass."
[aom.git] / vpx_ports / vpx_timer.h
blobdd98e291c2f7e76917475b4ef4d551f7df3f158b
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 #ifndef VPX_PORTS_VPX_TIMER_H_
13 #define VPX_PORTS_VPX_TIMER_H_
15 #include "./vpx_config.h"
17 #include "vpx/vpx_integer.h"
19 #if CONFIG_OS_SUPPORT
21 #if defined(_WIN32)
23 * Win32 specific includes
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
27 #endif
28 #include <windows.h>
29 #else
31 * POSIX specific includes
33 #include <sys/time.h>
35 /* timersub is not provided by msys at this time. */
36 #ifndef timersub
37 #define timersub(a, b, result) \
38 do { \
39 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
40 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
41 if ((result)->tv_usec < 0) { \
42 --(result)->tv_sec; \
43 (result)->tv_usec += 1000000; \
44 } \
45 } while (0)
46 #endif
47 #endif
50 struct vpx_usec_timer {
51 #if defined(_WIN32)
52 LARGE_INTEGER begin, end;
53 #else
54 struct timeval begin, end;
55 #endif
59 static INLINE void
60 vpx_usec_timer_start(struct vpx_usec_timer *t) {
61 #if defined(_WIN32)
62 QueryPerformanceCounter(&t->begin);
63 #else
64 gettimeofday(&t->begin, NULL);
65 #endif
69 static INLINE void
70 vpx_usec_timer_mark(struct vpx_usec_timer *t) {
71 #if defined(_WIN32)
72 QueryPerformanceCounter(&t->end);
73 #else
74 gettimeofday(&t->end, NULL);
75 #endif
79 static INLINE int64_t
80 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
81 #if defined(_WIN32)
82 LARGE_INTEGER freq, diff;
84 diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
86 QueryPerformanceFrequency(&freq);
87 return diff.QuadPart * 1000000 / freq.QuadPart;
88 #else
89 struct timeval diff;
91 timersub(&t->end, &t->begin, &diff);
92 return diff.tv_sec * 1000000 + diff.tv_usec;
93 #endif
96 #else /* CONFIG_OS_SUPPORT = 0*/
98 /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */
99 #ifndef timersub
100 #define timersub(a, b, result)
101 #endif
103 struct vpx_usec_timer {
104 void *dummy;
107 static INLINE void
108 vpx_usec_timer_start(struct vpx_usec_timer *t) { }
110 static INLINE void
111 vpx_usec_timer_mark(struct vpx_usec_timer *t) { }
113 static INLINE int
114 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
115 return 0;
118 #endif /* CONFIG_OS_SUPPORT */
120 #endif // VPX_PORTS_VPX_TIMER_H_