Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dvb_support: add helper to convert GPS time to Unix time
  • Loading branch information
laurimyllari authored and perexg committed Oct 22, 2015
1 parent 9092778 commit 80c945a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/input/mpegts/dvb.h
Expand Up @@ -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);

/*
Expand Down
37 changes: 37 additions & 0 deletions src/input/mpegts/dvb_support.c
Expand Up @@ -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
*/
Expand Down

0 comments on commit 80c945a

Please sign in to comment.