1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vpx_ports/vpx_timer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 + 1.15 +#ifndef VPX_TIMER_H 1.16 +#define VPX_TIMER_H 1.17 +#include "vpx/vpx_integer.h" 1.18 + 1.19 +#if CONFIG_OS_SUPPORT 1.20 + 1.21 +#if defined(_WIN32) 1.22 +/* 1.23 + * Win32 specific includes 1.24 + */ 1.25 +#ifndef WIN32_LEAN_AND_MEAN 1.26 +#define WIN32_LEAN_AND_MEAN 1.27 +#endif 1.28 +#include <windows.h> 1.29 +#else 1.30 +/* 1.31 + * POSIX specific includes 1.32 + */ 1.33 +#include <sys/time.h> 1.34 + 1.35 +/* timersub is not provided by msys at this time. */ 1.36 +#ifndef timersub 1.37 +#define timersub(a, b, result) \ 1.38 + do { \ 1.39 + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 1.40 + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 1.41 + if ((result)->tv_usec < 0) { \ 1.42 + --(result)->tv_sec; \ 1.43 + (result)->tv_usec += 1000000; \ 1.44 + } \ 1.45 + } while (0) 1.46 +#endif 1.47 +#endif 1.48 + 1.49 + 1.50 +struct vpx_usec_timer { 1.51 +#if defined(_WIN32) 1.52 + LARGE_INTEGER begin, end; 1.53 +#else 1.54 + struct timeval begin, end; 1.55 +#endif 1.56 +}; 1.57 + 1.58 + 1.59 +static void 1.60 +vpx_usec_timer_start(struct vpx_usec_timer *t) { 1.61 +#if defined(_WIN32) 1.62 + QueryPerformanceCounter(&t->begin); 1.63 +#else 1.64 + gettimeofday(&t->begin, NULL); 1.65 +#endif 1.66 +} 1.67 + 1.68 + 1.69 +static void 1.70 +vpx_usec_timer_mark(struct vpx_usec_timer *t) { 1.71 +#if defined(_WIN32) 1.72 + QueryPerformanceCounter(&t->end); 1.73 +#else 1.74 + gettimeofday(&t->end, NULL); 1.75 +#endif 1.76 +} 1.77 + 1.78 + 1.79 +static int64_t 1.80 +vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { 1.81 +#if defined(_WIN32) 1.82 + LARGE_INTEGER freq, diff; 1.83 + 1.84 + diff.QuadPart = t->end.QuadPart - t->begin.QuadPart; 1.85 + 1.86 + QueryPerformanceFrequency(&freq); 1.87 + return diff.QuadPart * 1000000 / freq.QuadPart; 1.88 +#else 1.89 + struct timeval diff; 1.90 + 1.91 + timersub(&t->end, &t->begin, &diff); 1.92 + return diff.tv_sec * 1000000 + diff.tv_usec; 1.93 +#endif 1.94 +} 1.95 + 1.96 +#else /* CONFIG_OS_SUPPORT = 0*/ 1.97 + 1.98 +/* Empty timer functions if CONFIG_OS_SUPPORT = 0 */ 1.99 +#ifndef timersub 1.100 +#define timersub(a, b, result) 1.101 +#endif 1.102 + 1.103 +struct vpx_usec_timer { 1.104 + void *dummy; 1.105 +}; 1.106 + 1.107 +static void 1.108 +vpx_usec_timer_start(struct vpx_usec_timer *t) { } 1.109 + 1.110 +static void 1.111 +vpx_usec_timer_mark(struct vpx_usec_timer *t) { } 1.112 + 1.113 +static long 1.114 +vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { 1.115 + return 0; 1.116 +} 1.117 + 1.118 +#endif /* CONFIG_OS_SUPPORT */ 1.119 + 1.120 +#endif