mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-31 11:32:38 +00:00
systemclock: reorg real and mono time functions for macOS and win32
This simplifies the pre-processor checks a little to make it easier to follow the code. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
This commit is contained in:
parent
d8237f150c
commit
5328941632
1 changed files with 47 additions and 30 deletions
|
@ -386,6 +386,10 @@ static void gst_system_clock_get_property (GObject * object, guint prop_id,
|
|||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static GstClockTime gst_system_clock_get_internal_time (GstClock * clock);
|
||||
#if defined __APPLE__ || defined G_OS_WIN32
|
||||
static GstClockTime gst_system_clock_get_mono_time (GstSystemClock * clock);
|
||||
static GstClockTime gst_system_clock_get_real_time ();
|
||||
#endif
|
||||
static guint64 gst_system_clock_get_resolution (GstClock * clock);
|
||||
static GstClockReturn gst_system_clock_id_wait_jitter (GstClock * clock,
|
||||
GstClockEntry * entry, GstClockTimeDiff * jitter);
|
||||
|
@ -828,37 +832,14 @@ gst_system_clock_get_internal_time (GstClock * 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__
|
||||
{
|
||||
uint64_t mach_t = mach_absolute_time ();
|
||||
return gst_util_uint64_scale (mach_t, sysclock->priv->mach_timebase.numer,
|
||||
sysclock->priv->mach_timebase.denom);
|
||||
}
|
||||
#elif defined G_OS_WIN32
|
||||
{
|
||||
if (sysclock->priv->frequency.QuadPart != 0) {
|
||||
LARGE_INTEGER now;
|
||||
|
||||
/* we prefer the highly accurate performance counters on windows */
|
||||
QueryPerformanceCounter (&now);
|
||||
|
||||
return gst_util_uint64_scale (now.QuadPart,
|
||||
GST_SECOND, sysclock->priv->frequency.QuadPart);
|
||||
} else {
|
||||
gint64 monotime;
|
||||
|
||||
monotime = g_get_monotonic_time ();
|
||||
|
||||
return monotime * 1000;
|
||||
}
|
||||
return gst_system_clock_get_real_time ();
|
||||
} else {
|
||||
return gst_system_clock_get_mono_time (sysclock);
|
||||
}
|
||||
#elif defined HAVE_POSIX_TIMERS && defined HAVE_CLOCK_GETTIME
|
||||
clockid_t ptype;
|
||||
// BSD and Linux' Posix timers and clock_gettime cover all of the different clock types
|
||||
// without need for special handling so we'll use those.
|
||||
clockid_t ptype;
|
||||
struct timespec ts;
|
||||
|
||||
ptype = clock_type_to_posix_id (sysclock->priv->clock_type);
|
||||
|
@ -867,9 +848,45 @@ gst_system_clock_get_internal_time (GstClock * clock)
|
|||
return GST_CLOCK_TIME_NONE;
|
||||
|
||||
return GST_TIMESPEC_TO_TIME (ts);
|
||||
#endif /* __APPLE__ */
|
||||
#endif /* __APPLE__ || G_OS_WIN32 */
|
||||
}
|
||||
|
||||
#if defined __APPLE__ || defined G_OS_WIN32
|
||||
static GstClockTime
|
||||
gst_system_clock_get_real_time ()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static GstClockTime
|
||||
gst_system_clock_get_mono_time (GstSystemClock * sysclock)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
uint64_t mach_t = mach_absolute_time ();
|
||||
return gst_util_uint64_scale (mach_t, sysclock->priv->mach_timebase.numer,
|
||||
sysclock->priv->mach_timebase.denom);
|
||||
#else
|
||||
if (sysclock->priv->frequency.QuadPart != 0) {
|
||||
LARGE_INTEGER now;
|
||||
|
||||
/* we prefer the highly accurate performance counters on windows */
|
||||
QueryPerformanceCounter (&now);
|
||||
|
||||
return gst_util_uint64_scale (now.QuadPart,
|
||||
GST_SECOND, sysclock->priv->frequency.QuadPart);
|
||||
} else {
|
||||
gint64 monotime;
|
||||
|
||||
monotime = g_get_monotonic_time ();
|
||||
|
||||
return monotime * 1000;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* __APPLE__ || G_OS_WIN32 */
|
||||
|
||||
static guint64
|
||||
gst_system_clock_get_resolution (GstClock * clock)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue