mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-09-27 15:26:33 -04:00
fix clock_gettime() con macOS <10.12 (not provided by base)
This commit is contained in:
parent
94d03f9004
commit
b7071869d1
@ -57,23 +57,4 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DARWIN_FEATURE_CLOCK_GETTIME
|
#endif // __APPLE_
|
||||||
/**
|
|
||||||
* Missing POSIX RealTime/Monotonic Clock
|
|
||||||
*/
|
|
||||||
#include <mach/mach_time.h>
|
|
||||||
|
|
||||||
int clock_gettime(int clk_id, struct timespec *t) {
|
|
||||||
mach_timebase_info_data_t timebase;
|
|
||||||
mach_timebase_info(&timebase);
|
|
||||||
uint64_t time;
|
|
||||||
time = mach_absolute_time();
|
|
||||||
double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom);
|
|
||||||
double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9);
|
|
||||||
t->tv_sec = seconds;
|
|
||||||
t->tv_nsec = nseconds;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // APPLE Compatibility
|
|
||||||
|
@ -31,13 +31,45 @@ int pthread_barrier_wait(pthread_barrier_t *barrier);
|
|||||||
|
|
||||||
#endif // PTHREAD_BARRIER_H_
|
#endif // PTHREAD_BARRIER_H_
|
||||||
|
|
||||||
// <time.h>
|
|
||||||
#ifndef CLOCK_REALTIME
|
|
||||||
# define CLOCK_REALTIME 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CLOCK_MONOTONIC
|
// macOS < 10.12 doesn't have clock_gettime()
|
||||||
# define CLOCK_MONOTONIC 0
|
#include <time.h>
|
||||||
#endif
|
#if !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC)
|
||||||
|
|
||||||
#endif // APPLE Compatibility
|
#define CLOCK_REALTIME 0
|
||||||
|
#define CLOCK_MONOTONIC 6
|
||||||
|
typedef int clockid_t;
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <mach/mach_time.h>
|
||||||
|
|
||||||
|
// here to avoid problem on linking of qrtplib
|
||||||
|
inline int clock_gettime( clockid_t clk_id, struct timespec *ts )
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
if ( ts )
|
||||||
|
{
|
||||||
|
if ( CLOCK_REALTIME == clk_id )
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
ret = gettimeofday(&tv, NULL);
|
||||||
|
ts->tv_sec = tv.tv_sec;
|
||||||
|
ts->tv_nsec = tv.tv_usec * 1000;
|
||||||
|
}
|
||||||
|
else if ( CLOCK_MONOTONIC == clk_id )
|
||||||
|
{
|
||||||
|
const uint64_t t = mach_absolute_time();
|
||||||
|
mach_timebase_info_data_t timebase;
|
||||||
|
mach_timebase_info(&timebase);
|
||||||
|
const uint64_t tdiff = t * timebase.numer / timebase.denom;
|
||||||
|
ts->tv_sec = tdiff / 1000000000;
|
||||||
|
ts->tv_nsec = tdiff % 1000000000;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CLOCK_REALTIME and CLOCK_MONOTONIC
|
||||||
|
|
||||||
|
#endif // __APPLE__
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
project(qrtplib)
|
project(qrtplib)
|
||||||
|
|
||||||
set (qrtplib_HEADERS
|
set (qrtplib_HEADERS
|
||||||
../custom/apple/apple_compat.h
|
|
||||||
rtcpapppacket.h
|
rtcpapppacket.h
|
||||||
rtcpbyepacket.h
|
rtcpbyepacket.h
|
||||||
rtcpcompoundpacket.h
|
rtcpcompoundpacket.h
|
||||||
@ -44,7 +43,6 @@ set (qrtplib_HEADERS
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(qrtplib_SOURCES
|
set(qrtplib_SOURCES
|
||||||
../custom/apple/apple_compat.c
|
|
||||||
rtcpapppacket.cpp
|
rtcpapppacket.cpp
|
||||||
rtcpbyepacket.cpp
|
rtcpbyepacket.cpp
|
||||||
rtcpcompoundpacket.cpp
|
rtcpcompoundpacket.cpp
|
||||||
|
@ -60,6 +60,10 @@
|
|||||||
#define CEPOCH 11644473600000000ULL
|
#define CEPOCH 11644473600000000ULL
|
||||||
#endif // RTP_HAVE_VSUINT64SUFFIX
|
#endif // RTP_HAVE_VSUINT64SUFFIX
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include "../custom/apple/apple_compat.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace qrtplib
|
namespace qrtplib
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user