Skip to content

Commit 8e47060

Browse files
committed
tv: mv get_time_in_ns to .c
+ drop macOS <10.15 compat (10.15 required, see wiki - Prerequisites in Compile UltraGrid (Source))
1 parent e508fec commit 8e47060

4 files changed

Lines changed: 19 additions & 24 deletions

File tree

src/audio/audio_playback.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <stdlib.h> // for free, calloc
4242
#include <string.h> // for strncpy
4343
#include <strings.h> // for strcasecmp
44+
#include <sys/time.h> // for gettimeofday
4445

4546
#include "audio/types.h" // for audio_frame, AC_PCM, audio_desc
4647
#include "debug.h" // for log_msg, LOG_LEVEL_ERROR, LOG_LEVEL_INFO

src/rtp/net_udp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <stdbool.h> // for bool, false, true
5454
#include <stdint.h> // for uint16_t, uintmax_t
5555
#include <stdlib.h> // for NULL, free, abort, calloc, malloc
56+
#include <sys/time.h> // for gettimeofday
5657

5758
#ifndef _WIN32
5859
#include <ifaddrs.h>

src/tv.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@
4545
*
4646
*/
4747

48-
#include "debug.h"
4948
#include "tv.h"
49+
50+
#include "debug.h"
5051
#include "utils/random.h"
5152

5253
#include <assert.h>
53-
#include <stdlib.h>
5454
#include <pthread.h>
55+
#include <stdio.h> // for perror
56+
#include <stdlib.h> // for NULL, lldiv, lldiv_t
57+
#include <sys/time.h> // for timeval, gettimeofda
58+
#include <time.h> // for timespec, TIME_UTC, timespec_get
5559

5660
pthread_once_t once_control = PTHREAD_ONCE_INIT;
5761
static struct timeval start_time;
@@ -245,15 +249,15 @@ uint32_t get_std_video_local_mediatime(void)
245249
return ((double)standard_time.vtime.tv_sec + (((double)standard_time.vtime.tv_usec) / 1000000.0)) * vrate;
246250
}
247251

248-
#if defined __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500
249-
int timespec_get(struct timespec *ts, int base)
252+
/**
253+
* @returns nanoseconds since implementation defined epoche (timespec_get def)
254+
*/
255+
time_ns_t
256+
get_time_in_ns()
250257
{
251-
assert(base == TIME_UTC);
252-
struct timeval tv = { 0, 0 };
253-
gettimeofday(&tv, NULL);
254-
ts->tv_sec = tv.tv_sec;
255-
ts->tv_nsec = tv.tv_usec * 1000L;
256-
return base; // returning base means success
257-
258+
struct timespec ts = { 0, 0 };
259+
if (timespec_get(&ts, TIME_UTC) == 0) {
260+
perror("timespec_get");
261+
}
262+
return (ts.tv_sec * NS_IN_SEC) + ts.tv_nsec;
258263
}
259-
#endif

src/tv.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ uint32_t get_std_audio_local_mediatime(double samples, int rate);
7676
uint32_t get_std_video_local_mediatime(void);
7777

7878
typedef long long time_ns_t;
79+
time_ns_t get_time_in_ns();
7980
/// @todo
8081
/// The naming is inconsistent - whereas US_IN_NS is the 1 us represented in ns,
8182
/// MS_IN_SEC is count of milliseconds in a second. Unify the use.
@@ -99,18 +100,6 @@ typedef long long time_ns_t;
99100
#define MS_TO_NS(val_ms) ((time_ns_t) (val_ms) * 1000)
100101
#define SEC_TO_NS(val_sec) ((val_sec) * 1000LL * 1000 * 1000)
101102

102-
// old macOS compat
103-
#if defined __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500
104-
#define TIME_UTC 1
105-
int timespec_get(struct timespec *ts, int base);
106-
#endif
107-
108-
static inline time_ns_t get_time_in_ns() {
109-
struct timespec ts = { 0, 0 };
110-
timespec_get(&ts, TIME_UTC);
111-
return ts.tv_sec * NS_IN_SEC + ts.tv_nsec;
112-
}
113-
114103
#ifdef __cplusplus
115104
}
116105
#endif

0 commit comments

Comments
 (0)