[vlc-commits] mtime: use timespec_get() in NTPtime64()

Rémi Denis-Courmont git at videolan.org
Wed Dec 9 18:18:12 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec  9 19:12:54 2015 +0200| [064fffbc5380242c4b8de7dce02e8e82c643d628] | committer: Rémi Denis-Courmont

mtime: use timespec_get() in NTPtime64()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=064fffbc5380242c4b8de7dce02e8e82c643d628
---

 src/misc/mtime.c |   24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/src/misc/mtime.c b/src/misc/mtime.c
index 46939dc..ea283f1 100644
--- a/src/misc/mtime.c
+++ b/src/misc/mtime.c
@@ -230,35 +230,19 @@ mtime_t date_Decrement( date_t *p_date, uint32_t i_nb_samples )
 /**
  * @return NTP 64-bits timestamp in host byte order.
  */
-uint64_t NTPtime64 (void)
+uint64_t NTPtime64(void)
 {
-#if (_POSIX_TIMERS > 0)
     struct timespec ts;
 
-    clock_gettime (CLOCK_REALTIME, &ts);
-#else
-    struct timeval tv;
-    struct
-    {
-        uint32_t tv_sec;
-        uint32_t tv_nsec;
-    } ts;
-
-    gettimeofday (&tv, NULL);
-    ts.tv_sec = tv.tv_sec;
-    ts.tv_nsec = tv.tv_usec * 1000;
-#endif
+    timespec_get(&ts, TIME_UTC);
 
     /* Convert nanoseconds to 32-bits fraction (232 picosecond units) */
     uint64_t t = (uint64_t)(ts.tv_nsec) << 32;
     t /= 1000000000;
 
-
-    /* There is 70 years (incl. 17 leap ones) offset to the Unix Epoch.
-     * No leap seconds during that period since they were not invented yet.
+    /* The offset to Unix epoch is 70 years (incl. 17 leap ones). There were
+     * no leap seconds during that period since they had not been invented yet.
      */
-    assert (t < 0x100000000);
     t |= ((UINT64_C(70) * 365 + 17) * 24 * 60 * 60 + ts.tv_sec) << 32;
     return t;
 }
-



More information about the vlc-commits mailing list