UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
tv.h
Go to the documentation of this file.
1/*
2 * FILE: tv.h
3 * AUTHOR: Colin Perkins <csp@csperkins.org>
4 * MODIFIED: Ladan Gharai <ladan@isi.edu>
5 *
6 * Copyright (c) 2001-2003 University of Southern California
7 * Copyright (c) 2005-2023 CESNET z.s.p.o.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 *
23 * This product includes software developed by the University of Southern
24 * California Information Sciences Institute.
25 *
26 * 4. Neither the name of the University nor of the Institute may be used
27 * to endorse or promote products derived from this software without
28 * specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
32 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
33 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
34 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45#ifndef TV_H_8332A958_38EB_4FE7_94E6_22C71BECD013
46#define TV_H_8332A958_38EB_4FE7_94E6_22C71BECD013
47
48#ifdef HAVE_CONFIG_H
49#include "config.h"
50#endif
51
52#ifdef __cplusplus
53#include <cstdint>
54#include <ctime>
55#else
56#include <stdint.h>
57#include <time.h>
58#endif
59
60#ifndef _MSC_VER
61#include <sys/time.h>
62#endif
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68uint32_t get_local_mediatime_offset(void);
69uint32_t get_local_mediatime(void);
70
71void ts_add_nsec(struct timespec *ts, long long offset);
72
73double tv_diff(struct timeval curr_time, struct timeval prev_time);
74uint32_t tv_diff_usec(struct timeval curr_time, struct timeval prev_time);
75void tv_add(struct timeval *ts, double offset_secs);
76void tv_add_usec(struct timeval *ts, long long offset);
77int tv_gt(struct timeval a, struct timeval b);
78uint32_t get_std_audio_local_mediatime(double samples, int rate);
80
81typedef long long time_ns_t;
85#define MS_IN_NS 1000000
86#define MS_IN_NS_DBL 1000000.0
87#define MS_IN_SEC 1000
88#define MS_IN_SEC_DBL 1000.0
89#define US_IN_SEC 1000000LL
90#define US_IN_NS 1000LL
91#define US_IN_SEC_DBL ((double) US_IN_SEC)
92#define NS_IN_SEC 1000000000LL
93#define NS_IN_SEC_DBL ((double) NS_IN_SEC)
94#define NS_IN_US (NS_IN_SEC/US_IN_SEC)
95#define NS_IN_US_DBL ((double) NS_IN_US)
96#define US_TO_MS(val_us) ((val_us) / 1000)
97#define MS_TO_US(val_ms) ((val_ms) * 1000)
98#define NS_TO_MS(val_ns) ((val_ns) / 1000 / 1000)
99#define MS_TO_NS(val_ms) ((val_ms) * 1000)
100
101static inline time_ns_t get_time_in_ns() {
102#ifdef HAVE_TIMESPEC_GET
103 struct timespec ts = { 0, 0 };
105 return ts.tv_sec * NS_IN_SEC + ts.tv_nsec;
106#else
107 struct timeval tv = { 0, 0 };
108 gettimeofday(&tv, NULL);
109 return tv.tv_sec * NS_IN_SEC + tv.tv_usec * NS_IN_US;
110#endif
111}
112
113// old macOS compat
114#if !defined HAVE_TIMESPEC_GET
115#ifndef TIME_UTC
116#define TIME_UTC 1
117#endif
118int timespec_get(struct timespec *ts, int base);
119#endif
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif // ! defined TV_H_8332A958_38EB_4FE7_94E6_22C71BECD013
static __device__ const float offset
Definition cuda_dxt.cu:139
uint32_t ts
Definition tfrc.c:101
uint32_t tv_diff_usec(struct timeval curr_time, struct timeval prev_time)
Definition tv.c:109
long long time_ns_t
Definition tv.h:81
uint32_t get_local_mediatime_offset(void)
Definition tv.c:73
void ts_add_nsec(struct timespec *ts, long long offset)
Definition tv.c:79
uint32_t get_std_video_local_mediatime(void)
Definition tv.c:204
void tv_add(struct timeval *ts, double offset_secs)
Definition tv.c:130
void tv_add_usec(struct timeval *ts, long long offset)
Definition tv.c:135
int timespec_get(struct timespec *ts, int base)
Definition tv.c:236
#define NS_IN_SEC
Definition tv.h:92
int tv_gt(struct timeval a, struct timeval b)
Definition tv.c:153
#define TIME_UTC
Definition tv.h:116
uint32_t get_std_audio_local_mediatime(double samples, int rate)
Definition tv.c:185
double tv_diff(struct timeval curr_time, struct timeval prev_time)
Definition tv.c:97
static time_ns_t get_time_in_ns()
Definition tv.h:101
#define NS_IN_US
Definition tv.h:94
uint32_t get_local_mediatime(void)
Definition tv.c:65