Merge "Update for key frame target size setting."
[profile/ivi/libvpx.git] / vpx_ports / vpx_timer.h
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
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  */
10
11
12 #ifndef VPX_TIMER_H
13 #define VPX_TIMER_H
14 #include "vpx/vpx_integer.h"
15
16 #if CONFIG_OS_SUPPORT
17
18 #if defined(_WIN32)
19 /*
20  * Win32 specific includes
21  */
22 #ifndef WIN32_LEAN_AND_MEAN
23 #define WIN32_LEAN_AND_MEAN
24 #endif
25 #include <windows.h>
26 #else
27 /*
28  * POSIX specific includes
29  */
30 #include <sys/time.h>
31
32 /* timersub is not provided by msys at this time. */
33 #ifndef timersub
34 #define timersub(a, b, result) \
35     do { \
36         (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
37         (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
38         if ((result)->tv_usec < 0) { \
39             --(result)->tv_sec; \
40             (result)->tv_usec += 1000000; \
41         } \
42     } while (0)
43 #endif
44 #endif
45
46
47 struct vpx_usec_timer
48 {
49 #if defined(_WIN32)
50     LARGE_INTEGER  begin, end;
51 #else
52     struct timeval begin, end;
53 #endif
54 };
55
56
57 static void
58 vpx_usec_timer_start(struct vpx_usec_timer *t)
59 {
60 #if defined(_WIN32)
61     QueryPerformanceCounter(&t->begin);
62 #else
63     gettimeofday(&t->begin, NULL);
64 #endif
65 }
66
67
68 static void
69 vpx_usec_timer_mark(struct vpx_usec_timer *t)
70 {
71 #if defined(_WIN32)
72     QueryPerformanceCounter(&t->end);
73 #else
74     gettimeofday(&t->end, NULL);
75 #endif
76 }
77
78
79 static int64_t
80 vpx_usec_timer_elapsed(struct vpx_usec_timer *t)
81 {
82 #if defined(_WIN32)
83     LARGE_INTEGER freq, diff;
84
85     diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
86
87     QueryPerformanceFrequency(&freq);
88     return diff.QuadPart * 1000000 / freq.QuadPart;
89 #else
90     struct timeval diff;
91
92     timersub(&t->end, &t->begin, &diff);
93     return diff.tv_sec * 1000000 + diff.tv_usec;
94 #endif
95 }
96
97 #else /* CONFIG_OS_SUPPORT = 0*/
98
99 /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */
100 #ifndef timersub
101 #define timersub(a, b, result)
102 #endif
103
104 struct vpx_usec_timer
105 {
106     void *dummy;
107 };
108
109 static void
110 vpx_usec_timer_start(struct vpx_usec_timer *t) { }
111
112 static void
113 vpx_usec_timer_mark(struct vpx_usec_timer *t) { }
114
115 static long
116 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { return 0; }
117
118 #endif /* CONFIG_OS_SUPPORT */
119
120 #endif