GstSystemClock: Add GST_CLOCK_TYPE_TAI
authorEderson de Souza <ederson.desouza@intel.com>
Fri, 13 Dec 2019 19:07:40 +0000 (11:07 -0800)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 27 Jan 2020 17:16:14 +0000 (17:16 +0000)
GST_CLOCK_TYPE_TAI is GStreamer abstraction for CLOCK_TAI. Main
motivation for this patch is support for transmission offloading features
- when network packets are timestamped with the time they are deemed to
be actually transmitted. Linux API for that requires that time to be
in CLOCK_TAI coordinate.

With GST_CLOCK_TYPE_TAI, applications can use CLOCK_TAI directly on
their pipelines, avoiding the need to cross timestamp packet times. By
leveraging system's CLOCK_TAI, applications also don't need to keep track
of leap seconds - less burden for them. Just keep system's CLOCK_TAI
accurate and use it.

gst/gstsystemclock.c
gst/gstsystemclock.h
meson.build

index 2d56d20..9b1a82e 100644 (file)
@@ -560,7 +560,14 @@ clock_type_to_posix_id (GstClockType clock_type)
     return CLOCK_MONOTONIC;
   else
 #endif
-    return CLOCK_REALTIME;
+  if (clock_type == GST_CLOCK_TYPE_TAI)
+#ifdef HAVE_TAI_CLOCK
+    return CLOCK_TAI;
+#else
+    GST_ERROR
+        ("No CLOCK_TAI available on the system. Falling back to CLOCK_REALTIME");
+#endif
+  return CLOCK_REALTIME;
 }
 #endif
 
index de68be4..7621268 100644 (file)
@@ -48,13 +48,16 @@ typedef struct _GstSystemClockPrivate GstSystemClockPrivate;
  * @GST_CLOCK_TYPE_MONOTONIC: monotonic time since some unspecified starting
  *                            point
  * @GST_CLOCK_TYPE_OTHER: some other time source is used (Since: 1.0.5)
+ * @GST_CLOCK_TYPE_TAI: time since Epoch, but using International Atomic Time
+ *                      as reference (Since 1.18)
  *
  * The different kind of clocks.
  */
 typedef enum {
   GST_CLOCK_TYPE_REALTIME       = 0,
   GST_CLOCK_TYPE_MONOTONIC      = 1,
-  GST_CLOCK_TYPE_OTHER          = 2
+  GST_CLOCK_TYPE_OTHER          = 2,
+  GST_CLOCK_TYPE_TAI            = 3
 } GstClockType;
 
 /**
index a47e7f3..69b3a2c 100644 (file)
@@ -256,7 +256,7 @@ if cc.links('''#include <pthread.h>
   cdata.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
 endif
 
-# Check for posix timers and the monotonic clock
+# Check for posix timers, monotonic clock and TAI clock
 time_prefix = '#include <time.h>\n'
 if cdata.has('HAVE_UNISTD_H')
   time_prefix += '#include <unistd.h>'
@@ -280,6 +280,15 @@ if cc.compiles(monotonic_clock_src, name : 'monotonic clock from time.h')
   cdata.set('HAVE_MONOTONIC_CLOCK', 1)
 endif
 
+tai_clock_src = time_prefix + '''
+#if !defined(CLOCK_TAI)
+#error CLOCK_TAI not defined
+#endif
+'''
+if cc.compiles(tai_clock_src, name : 'TAI clock from time.h')
+  cdata.set('HAVE_TAI_CLOCK', 1)
+endif
+
 # Check for __uint128_t (gcc) by checking for 128-bit division
 uint128_t_src = '''int main() {
 static __uint128_t v1 = 100;