mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
systemclock: Reorganize defined checks for parts of GstSystemClock
The gst_system_clock_get_internal_time and gst_system_clock_get_resolution functions had some nested defined checks making this code somewhat harder to reason about and much harder to change. The logical meaning of the checks has changed but the actual code coming out of the pre-processor should not have changed significantly. The main logical change was flattening the checks for existence of posix timing functionality, from what I can tell these functions aren't available on Windows where they were trying to be included. I have checked the Linux and macOS output and they are functionally unchanged. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
This commit is contained in:
parent
dd22ec68d2
commit
bb77f41abf
1 changed files with 25 additions and 43 deletions
|
@ -825,15 +825,12 @@ clock_type_to_posix_id (GstClockType clock_type)
|
||||||
static GstClockTime
|
static GstClockTime
|
||||||
gst_system_clock_get_internal_time (GstClock * clock)
|
gst_system_clock_get_internal_time (GstClock * clock)
|
||||||
{
|
{
|
||||||
#if defined __APPLE__
|
|
||||||
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
||||||
|
#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);
|
||||||
#else
|
#elif G_OS_WIN32
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
|
||||||
|
|
||||||
if (sysclock->priv->frequency.QuadPart != 0) {
|
if (sysclock->priv->frequency.QuadPart != 0) {
|
||||||
LARGE_INTEGER now;
|
LARGE_INTEGER now;
|
||||||
|
|
||||||
|
@ -842,66 +839,51 @@ gst_system_clock_get_internal_time (GstClock * clock)
|
||||||
|
|
||||||
return gst_util_uint64_scale (now.QuadPart,
|
return gst_util_uint64_scale (now.QuadPart,
|
||||||
GST_SECOND, sysclock->priv->frequency.QuadPart);
|
GST_SECOND, sysclock->priv->frequency.QuadPart);
|
||||||
} else
|
} else {
|
||||||
#endif /* G_OS_WIN32 */
|
|
||||||
#if !defined HAVE_POSIX_TIMERS || !defined HAVE_CLOCK_GETTIME
|
|
||||||
{
|
|
||||||
gint64 monotime;
|
gint64 monotime;
|
||||||
|
|
||||||
monotime = g_get_monotonic_time ();
|
monotime = g_get_monotonic_time ();
|
||||||
|
|
||||||
return monotime * 1000;
|
return monotime * 1000;
|
||||||
}
|
}
|
||||||
#else
|
#elif defined HAVE_POSIX_TIMERS && defined HAVE_CLOCK_GETTIME
|
||||||
{
|
clockid_t ptype;
|
||||||
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
struct timespec ts;
|
||||||
clockid_t ptype;
|
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
ptype = clock_type_to_posix_id (sysclock->priv->clock_type);
|
ptype = clock_type_to_posix_id (sysclock->priv->clock_type);
|
||||||
|
|
||||||
if (G_UNLIKELY (clock_gettime (ptype, &ts)))
|
if (G_UNLIKELY (clock_gettime (ptype, &ts)))
|
||||||
return GST_CLOCK_TIME_NONE;
|
return GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
return GST_TIMESPEC_TO_TIME (ts);
|
return GST_TIMESPEC_TO_TIME (ts);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint64
|
static guint64
|
||||||
gst_system_clock_get_resolution (GstClock * clock)
|
gst_system_clock_get_resolution (GstClock * clock)
|
||||||
{
|
{
|
||||||
#if defined __APPLE__
|
|
||||||
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
||||||
|
#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, sysclock->priv->mach_timebase.denom);
|
||||||
#else
|
#elif G_OS_WIN32
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
|
||||||
|
|
||||||
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 {
|
||||||
#endif /* G_OS_WIN32 */
|
|
||||||
#if defined(HAVE_POSIX_TIMERS) && defined(HAVE_CLOCK_GETTIME)
|
|
||||||
{
|
|
||||||
GstSystemClock *sysclock = GST_SYSTEM_CLOCK_CAST (clock);
|
|
||||||
clockid_t ptype;
|
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
ptype = clock_type_to_posix_id (sysclock->priv->clock_type);
|
|
||||||
|
|
||||||
if (G_UNLIKELY (clock_getres (ptype, &ts)))
|
|
||||||
return GST_CLOCK_TIME_NONE;
|
|
||||||
|
|
||||||
return GST_TIMESPEC_TO_TIME (ts);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
return 1 * GST_USECOND;
|
return 1 * GST_USECOND;
|
||||||
}
|
}
|
||||||
#endif
|
#elif defined(HAVE_POSIX_TIMERS) && defined(HAVE_CLOCK_GETTIME)
|
||||||
|
clockid_t ptype;
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
ptype = clock_type_to_posix_id (sysclock->priv->clock_type);
|
||||||
|
|
||||||
|
if (G_UNLIKELY (clock_getres (ptype, &ts)))
|
||||||
|
return GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
|
return GST_TIMESPEC_TO_TIME (ts);
|
||||||
|
#else
|
||||||
|
return 1 * GST_USECOND;
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue