]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
dvb_support: add helper to convert GPS time to Unix time
authorLauri Myllari <lauri.myllari@gmail.com>
Mon, 12 Jan 2015 04:35:40 +0000 (20:35 -0800)
committerJaroslav Kysela <perex@perex.cz>
Thu, 22 Oct 2015 15:33:59 +0000 (17:33 +0200)
src/input/mpegts/dvb.h
src/input/mpegts/dvb_support.c

index b08c9ad1d6ecad843af1f7cd93e2dee775072a7d..9ca170ae95516e4713f49f2e0990eb557e4c06c1 100644 (file)
@@ -209,7 +209,7 @@ int atsc_get_string
 #define bcdtoint(i) ((((i & 0xf0) >> 4) * 10) + (i & 0x0f))
 
 time_t dvb_convert_date(const uint8_t *dvb_buf, int local);
-
+time_t atsc_convert_gpstime(uint32_t gpstime);
 void atsc_utf16_to_utf8(const uint8_t *src, int len, char *buf, int buflen);
 
 /*
index 2fb1f5c33c328654a259fec763d858e9d39ff3f1..749cf6dbb3cefba0a98b58d42d7ef9397fde4001 100644 (file)
@@ -506,6 +506,43 @@ dvb_convert_date(const uint8_t *dvb_buf, int local)
   return local ? mktime(&dvb_time) : timegm(&dvb_time);
 }
 
+static time_t _gps_leap_seconds[17] = {
+       362793600,
+       394329600,
+       425865600,
+       489024000,
+       567993600,
+       631152000,
+       662688000,
+       709948800,
+       741484800,
+       773020800,
+       820454400,
+       867715200,
+       915148800,
+       1136073600,
+       1230768000,
+       1341100800,
+       1435708800,
+};
+
+time_t
+atsc_convert_gpstime(uint32_t gpstime)
+{
+  int i;
+  time_t out = gpstime + 315964800; // Add Unix - GPS epoch
+
+  for (i = (sizeof(_gps_leap_seconds)/sizeof(time_t)) - 1; i >= 0; i--) {
+    if (out > _gps_leap_seconds[i]) {
+      tvhwarn("gpstime", "leap seconds: %d", i+1);
+      out -= i+1;
+      break;
+    }
+  }
+
+  return out;
+}
+
 /*
  * DVB API helpers
  */