forked from webmproject/udpsample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.c
101 lines (79 loc) · 1.94 KB
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifdef WINDOWS
#include <windows.h>
#include <mmsystem.h>
unsigned int get_time(void)
{
LARGE_INTEGER pf;
long long now;
QueryPerformanceCounter((LARGE_INTEGER *) &now);
QueryPerformanceFrequency(&pf);
return (unsigned int)(now * 1000 / pf.LowPart);
}
#else
#include <time.h>
#include <sys/time.h>
unsigned int get_time(void)
{
struct timespec ts;
unsigned long long tv;
#if _POSIX_TIMERS > 0
clock_gettime(CLOCK_REALTIME, &ts);
#else
struct timeval tv2;
gettimeofday(&tv2, NULL);
ts.tv_sec = tv2.tv_sec;
ts.tv_nsec = tv2.tv_usec * 1000;
#endif
tv = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
return tv & 0xffffffff;
}
int _kbhit(void)
{
struct timeval tv;
fd_set read_fd;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&read_fd);
FD_SET(0, &read_fd);
if (select(1, &read_fd, NULL, NULL, &tv) == -1)
return 0;
if (FD_ISSET(0, &read_fd))
return 1;
return 0;
}
#endif
#include "tctypes.h"
#include "rtp.h"
#include <stdarg.h>
#include <stdio.h>
unsigned int start_time = 0;
void vpxlog_dbg_no_head(int level, const tc8 *format, ...)
{
va_list list;
if (!(level & LOG_MASK))
return;
va_start(list, format);
vprintf(format, list);
va_end(list);
}
void vpxlog_dbg(int level, const tc8 *format, ...)
{
va_list list;
if (!(level & LOG_MASK))
return;
if (start_time == 0)
start_time = get_time();
printf("%8d ", get_time() - start_time);
va_start(list, format);
vprintf(format, list);
va_end(list);
}