From: Jaroslav Kysela Date: Thu, 30 Apr 2015 09:36:46 +0000 (+0200) Subject: time update - make it work again using TDT/TOT tables, fixes #2776 X-Git-Tag: v4.1~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02948826e9dcdd35f51ee0d667f99e78c8890509;p=thirdparty%2Ftvheadend.git time update - make it work again using TDT/TOT tables, fixes #2776 --- diff --git a/configure b/configure index cf3619c6c..40b51e8ff 100755 --- a/configure +++ b/configure @@ -165,6 +165,17 @@ int test(void) } ' +check_cc_snippet stime ' +#include +#define TEST test +int test(void) +{ + time_t t = 1; + stime(&t); + return 0; +} +' + check_cc_snippet recvmmsg ' #define _GNU_SOURCE #include diff --git a/src/input/mpegts.h b/src/input/mpegts.h index 1ea32a6e4..9c5e15808 100644 --- a/src/input/mpegts.h +++ b/src/input/mpegts.h @@ -164,6 +164,7 @@ typedef struct mpegts_pid_sub #define MPS_WEIGHT_RAW 400 #define MPS_WEIGHT_NIT2 300 #define MPS_WEIGHT_SDT2 300 +#define MPS_WEIGHT_TDT 101 #define MPS_WEIGHT_PMT_SCAN 100 int mps_weight; void *mps_owner; @@ -964,6 +965,8 @@ int dvb_sdt_callback (struct mpegts_table *mt, const uint8_t *ptr, int len, int tableid); int dvb_tdt_callback (struct mpegts_table *mt, const uint8_t *ptr, int len, int tableid); +int dvb_tot_callback + (struct mpegts_table *mt, const uint8_t *ptr, int len, int tableid); int atsc_vct_callback (struct mpegts_table *mt, const uint8_t *ptr, int len, int tableid); diff --git a/src/input/mpegts/dvb.h b/src/input/mpegts/dvb.h index 69633a2fb..89fe4c114 100644 --- a/src/input/mpegts/dvb.h +++ b/src/input/mpegts/dvb.h @@ -34,10 +34,19 @@ struct mpegts_mux; #define DVB_PAT_PID 0x00 #define DVB_CAT_PID 0x01 +#define DVB_TSDT_PID 0x02 #define DVB_NIT_PID 0x10 #define DVB_SDT_PID 0x11 #define DVB_BAT_PID 0x11 #define DVB_EIT_PID 0x12 +#define DVB_RST_PID 0x13 +#define DVB_TDT_PID 0x14 +#define DVB_SNC_PID 0x15 +#define DVB_RNT_PID 0x16 +#define DVB_INB_PID 0x1C +#define DVB_MSR_PID 0x1D +#define DVB_DIT_PID 0x1E +#define DVB_SIT_PID 0x1F #define DVB_VCT_PID 0x1FFB /* Tables */ @@ -60,6 +69,12 @@ struct mpegts_mux; #define DVB_BAT_BASE 0x48 #define DVB_BAT_MASK 0xF8 +#define DVB_TDT_BASE 0x70 +#define DVB_TDT_MASK 0xFF + +#define DVB_TOT_BASE 0x73 +#define DVB_TOT_MASK 0xFF + #define DVB_FASTSCAN_NIT_BASE 0xBC #define DVB_FASTSCAN_SDT_BASE 0xBD #define DVB_FASTSCAN_MASK 0xFF diff --git a/src/input/mpegts/dvb_psi.c b/src/input/mpegts/dvb_psi.c index ac888ef3e..343ecd3ce 100644 --- a/src/input/mpegts/dvb_psi.c +++ b/src/input/mpegts/dvb_psi.c @@ -27,6 +27,7 @@ #include "bouquet.h" #include "fastscan.h" #include "descrambler/dvbcam.h" +#include "tvhtime.h" #include #include @@ -2370,6 +2371,50 @@ psi_parse_pmt return ret; } +/** + * TDT parser, from ISO 13818-1 and ETSI EN 300 468 + */ + +static void dvb_time_update(const uint8_t *ptr, const char *srcname) +{ + static time_t dvb_last_update = 0; + time_t t; + if (dvb_last_update + 1800 < dispatch_clock) { + t = dvb_convert_date(ptr, 0); + tvhtime_update(t, srcname); + dvb_last_update = dispatch_clock; + } +} + +int +dvb_tdt_callback + (mpegts_table_t *mt, const uint8_t *ptr, int len, int tableid) +{ + if (len == 5) { + dvb_time_update(ptr, "TDT"); + mt->mt_incomplete = 0; + mt->mt_complete = 1; + mt->mt_finished = 1; + } + return 0; +} + +/** + * TOT parser, from ISO 13818-1 and ETSI EN 300 468 + */ +int +dvb_tot_callback + (mpegts_table_t *mt, const uint8_t *ptr, int len, int tableid) +{ + if (len >= 5) { + dvb_time_update(ptr, "TOT"); + mt->mt_incomplete = 0; + mt->mt_complete = 1; + mt->mt_finished = 1; + } + return 0; +} + /* * Install default table sets */ @@ -2410,6 +2455,14 @@ psi_tables_dvb ( mpegts_mux_t *mm ) DVB_SDT_PID, MPS_WEIGHT_SDT); mpegts_table_add(mm, DVB_BAT_BASE, DVB_BAT_MASK, dvb_bat_callback, NULL, "bat", MT_CRC, DVB_BAT_PID, MPS_WEIGHT_BAT); + if (tvhtime_update_enabled) { + mpegts_table_add(mm, DVB_TDT_BASE, DVB_TDT_MASK, dvb_tdt_callback, + NULL, "tdt", MT_ONESHOT | MT_QUICKREQ | MT_RECORD, + DVB_TDT_PID, MPS_WEIGHT_TDT); + mpegts_table_add(mm, DVB_TOT_BASE, DVB_TOT_MASK, dvb_tot_callback, + NULL, "tot", MT_ONESHOT | MT_QUICKREQ | MT_CRC | MT_RECORD, + DVB_TDT_PID, MPS_WEIGHT_TDT); + } #if ENABLE_MPEGTS_DVB if (idnode_is_instance(&mm->mm_id, &dvb_mux_dvbs_class)) { dvb_mux_conf_t *mc = &((dvb_mux_t *)mm)->lm_tuning; diff --git a/src/main.c b/src/main.c index 0daab067b..ed06ff307 100644 --- a/src/main.c +++ b/src/main.c @@ -71,6 +71,7 @@ #endif #include "profile.h" #include "bouquet.h" +#include "tvhtime.h" #ifdef PLATFORM_LINUX #include @@ -966,6 +967,8 @@ main(int argc, char **argv) libav_init(); #endif + tvhtime_init(); + profile_init(); imagecache_init(); diff --git a/src/tvhlog.h b/src/tvhlog.h index de87e9959..c6b1acf7c 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -111,9 +111,10 @@ static inline int tvhlog_limit ( tvhlog_limit_t *limit, uint32_t delay ) tvhtrace(subsys, "%s() leave", #fcn); \ } while (0) -#define tvhdebug(...) tvhlog(LOG_DEBUG, ##__VA_ARGS__) -#define tvhinfo(...) tvhlog(LOG_INFO, ##__VA_ARGS__) -#define tvhwarn(...) tvhlog(LOG_WARNING, ##__VA_ARGS__) -#define tvherror(...) tvhlog(LOG_ERR, ##__VA_ARGS__) +#define tvhdebug(...) tvhlog(LOG_DEBUG, ##__VA_ARGS__) +#define tvhinfo(...) tvhlog(LOG_INFO, ##__VA_ARGS__) +#define tvhwarn(...) tvhlog(LOG_WARNING, ##__VA_ARGS__) +#define tvhnotice(...) tvhlog(LOG_NOTICE, ##__VA_ARGS__) +#define tvherror(...) tvhlog(LOG_ERR, ##__VA_ARGS__) #endif /* __TVH_LOGGING_H__ */ diff --git a/src/tvhtime.c b/src/tvhtime.c index 9bee7609f..ae4688dfc 100644 --- a/src/tvhtime.c +++ b/src/tvhtime.c @@ -82,34 +82,40 @@ ntp_shm_init ( void ) * Update time */ void -tvhtime_update ( struct tm *tm ) +tvhtime_update ( time_t utc, const char *srcname ) { #if !ENABLE_ANDROID - time_t now; + struct tm tm; struct timeval tv; ntp_shm_t *ntp_shm; - int64_t t1, t2; + int64_t t1, t2, diff; - tvhtrace("time", "current time is %04d/%02d/%02d %02d:%02d:%02d", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + localtime_r(&utc, &tm); + + tvhtrace("time", "%s - current time is %04d/%02d/%02d %02d:%02d:%02d", + srcname, + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); - /* Current and reported time */ - now = mktime(tm); gettimeofday(&tv, NULL); /* Delta */ - t1 = now * 1000000; + t1 = utc * 1000000; t2 = tv.tv_sec * 1000000 + tv.tv_usec; /* Update local clock */ if (tvhtime_update_enabled) { - if (llabs(t2 - t1) > tvhtime_tolerance) { - tvhlog(LOG_DEBUG, "time", "updated system clock"); -#ifdef stime - stime(&now); + if ((diff = llabs(t2 - t1)) > tvhtime_tolerance) { +#if ENABLE_STIME + if (stime(&utc) < 0) + tvherror("time", "%s - unable to update system time: %s", srcname, strerror(errno)); + else + tvhdebug("time", "%s - updated system clock", srcname); #else - tvhlog(LOG_NOTICE, "time", "stime(2) not implemented"); + tvhnotice("time", "%s - stime(2) not implemented", srcname); #endif + } else { + tvhwarn("time", "%s - time not updated (diff %"PRId64")", srcname, diff); } } @@ -121,7 +127,7 @@ tvhtime_update ( struct tm *tm ) tvhtrace("time", "ntp delta = %"PRId64" us\n", t2 - t1); ntp_shm->valid = 0; ntp_shm->count++; - ntp_shm->clockTimeStampSec = now; + ntp_shm->clockTimeStampSec = utc; ntp_shm->clockTimeStampUSec = 0; ntp_shm->receiveTimeStampSec = tv.tv_sec; ntp_shm->receiveTimeStampUSec = (int)tv.tv_usec; @@ -141,6 +147,7 @@ void tvhtime_init ( void ) tvhtime_ntp_enabled = 0; if (htsmsg_get_u32(m, "tolerance", &tvhtime_tolerance)) tvhtime_tolerance = 5000; + htsmsg_destroy(m); } static void tvhtime_save ( void ) @@ -150,6 +157,7 @@ static void tvhtime_save ( void ) htsmsg_add_u32(m, "ntp_enabled", tvhtime_ntp_enabled); htsmsg_add_u32(m, "tolerance", tvhtime_tolerance); hts_settings_save(m, "tvhtime/config"); + htsmsg_destroy(m); } void tvhtime_set_update_enabled ( uint32_t on ) diff --git a/src/tvhtime.h b/src/tvhtime.h index 0d07a6fc8..fec870169 100644 --- a/src/tvhtime.h +++ b/src/tvhtime.h @@ -25,7 +25,7 @@ extern uint32_t tvhtime_ntp_enabled; extern uint32_t tvhtime_tolerance; void tvhtime_init ( void ); -void tvhtime_update ( struct tm *now ); +void tvhtime_update ( time_t utc, const char *srcname ); void tvhtime_set_update_enabled ( uint32_t on ); void tvhtime_set_ntp_enabled ( uint32_t on );