systemclock: Use g_get_real_time on Windows and macOS for realtime clock

These targets previously were unable to produce wall clock times when
using GstSystemClock, this change makes it possible.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
This commit is contained in:
tyler-aicradle 2021-05-26 14:55:55 -05:00
parent bb77f41abf
commit d8237f150c

View file

@ -826,11 +826,21 @@ static GstClockTime
gst_system_clock_get_internal_time (GstClock * clock) gst_system_clock_get_internal_time (GstClock * clock)
{ {
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock); GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
#if defined __APPLE__ || defined G_OS_WIN32
if (sysclock->priv->clock_type == GST_CLOCK_TYPE_REALTIME) {
gint64 rt_micros = g_get_real_time ();
// g_get_real_time returns microseconds but we need nanos, so we'll multiply by 1000
return ((guint64) rt_micros) * 1000;
} else
#endif
#if defined __APPLE__ #if defined __APPLE__
{
uint64_t mach_t = mach_absolute_time (); uint64_t mach_t = mach_absolute_time ();
return gst_util_uint64_scale (mach_t, sysclock->priv->mach_timebase.numer, return gst_util_uint64_scale (mach_t, sysclock->priv->mach_timebase.numer,
sysclock->priv->mach_timebase.denom); sysclock->priv->mach_timebase.denom);
#elif G_OS_WIN32 }
#elif defined G_OS_WIN32
{
if (sysclock->priv->frequency.QuadPart != 0) { if (sysclock->priv->frequency.QuadPart != 0) {
LARGE_INTEGER now; LARGE_INTEGER now;
@ -846,6 +856,7 @@ gst_system_clock_get_internal_time (GstClock * clock)
return monotime * 1000; return monotime * 1000;
} }
}
#elif defined HAVE_POSIX_TIMERS && defined HAVE_CLOCK_GETTIME #elif defined HAVE_POSIX_TIMERS && defined HAVE_CLOCK_GETTIME
clockid_t ptype; clockid_t ptype;
struct timespec ts; struct timespec ts;
@ -863,15 +874,25 @@ static guint64
gst_system_clock_get_resolution (GstClock * clock) gst_system_clock_get_resolution (GstClock * clock)
{ {
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock); GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
#if defined __APPLE__ || defined G_OS_WIN32
if (sysclock->priv->clock_type == GST_CLOCK_TYPE_REALTIME) {
return 1 * GST_USECOND;
} else
#endif
#if defined __APPLE__ #if defined __APPLE__
{
return gst_util_uint64_scale (GST_NSECOND, return gst_util_uint64_scale (GST_NSECOND,
sysclock->priv->mach_timebase.numer, sysclock->priv->mach_timebase.denom); sysclock->priv->mach_timebase.numer,
#elif G_OS_WIN32 sysclock->priv->mach_timebase.denom);
}
#elif defined G_OS_WIN32
{
if (sysclock->priv->frequency.QuadPart != 0) { if (sysclock->priv->frequency.QuadPart != 0) {
return GST_SECOND / sysclock->priv->frequency.QuadPart; return GST_SECOND / sysclock->priv->frequency.QuadPart;
} else { } else {
return 1 * GST_USECOND; return 1 * GST_USECOND;
} }
}
#elif defined(HAVE_POSIX_TIMERS) && defined(HAVE_CLOCK_GETTIME) #elif defined(HAVE_POSIX_TIMERS) && defined(HAVE_CLOCK_GETTIME)
clockid_t ptype; clockid_t ptype;
struct timespec ts; struct timespec ts;