summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authortyler-aicradle <tyler@safex.ai>2021-05-27 09:44:29 -0500
committertyler-aicradle <tyler@safex.ai>2021-05-27 09:44:29 -0500
commit5328941632255c5b7a9652b0446aa74dbf4c5f4b (patch)
tree4002df85db342515c0bc18bb7d082b49ed8c7a7d /gst
parentd8237f150ccc011a362a9e6003b34df7b443b9d3 (diff)
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>
Diffstat (limited to 'gst')
-rw-r--r--gst/gstsystemclock.c77
1 files changed, 47 insertions, 30 deletions
diff --git a/gst/gstsystemclock.c b/gst/gstsystemclock.c
index 3331fe30e9..31a2a261e0 100644
--- a/gst/gstsystemclock.c
+++ b/gst/gstsystemclock.c
@@ -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,8 +848,44 @@ 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)