diff --git a/src/eitd/SIsections.cpp b/src/eitd/SIsections.cpp index dbf4855c1..8273a4fb5 100644 --- a/src/eitd/SIsections.cpp +++ b/src/eitd/SIsections.cpp @@ -31,12 +31,18 @@ #include "SIservices.hpp" #include "SIevents.hpp" #include "SIsections.hpp" +#include "debug.h" #include #include #include #include +#include +#include +#include + + void SIsectionEIT::parse(void) { const EventList &elist = *getEvents(); @@ -110,3 +116,44 @@ void SIsectionSDT::parse(void) } parsed = 1; } + +void SIsectionTIME::parse(uint8_t *buf) +{ + if(buf[0] != 0x70 && buf[0] != 0x73) + return; + + bool TDT = (buf[0] == 0x70); + if(TDT) { + TimeAndDateSection tdt(buf); + if(tdt.getSectionLength() < 5) + return; + dvbtime = parseDVBtime(tdt.getUtcTimeMjd(), tdt.getUtcTimeBcd()); + xcprintf("SIsectionTIME::parse: TDT time: %s", ctime(&dvbtime)); + parsed = true; + } else { + TimeOffsetSection tot(buf); + dvbtime = parseDVBtime(tot.getUtcTimeMjd(), tot.getUtcTimeBcd()); + xcprintf("SIsectionTIME::parse: TOT time: %s", ctime(&dvbtime)); + const DescriptorList &dlist = *tot.getDescriptors(); + for (DescriptorConstIterator dit = dlist.begin(); dit != dlist.end(); ++dit) { + uint8_t dtype = (*dit)->getTag(); + if(dtype == LOCAL_TIME_OFFSET_DESCRIPTOR) { + /* TOT without descriptors seems to be not better than a plain TDT, such TOT's are */ + /* found on transponders which also have wrong time in TDT etc, so don't trust it. */ + parsed = true; + + const LocalTimeOffsetDescriptor * d = (LocalTimeOffsetDescriptor*) *dit; + const LocalTimeOffsetList * oflist = d->getLocalTimeOffsets(); + for (LocalTimeOffsetConstIterator it = oflist->begin(); it != oflist->end(); ++it) { + const LocalTimeOffset * of = (LocalTimeOffset *) *it; + time_t change_time = parseDVBtime(of->getTimeOfChangeMjd(), of->getTimeOfChangeBcd(), false); + xprintf("TOT: cc=%s reg_id=%d pol=%d offs=%04x new=%04x when=%s", + of->getCountryCode().c_str(), of->getCountryRegionId(), of->getLocalTimeOffsetPolarity(), + of->getLocalTimeOffset(), of->getNextTimeOffset(), ctime(&change_time)); + } + } else { + xprintf("SIsectionTIME::parse: unhandled descriptor %02x\n", dtype); + } + } + } +} diff --git a/src/eitd/SIsections.hpp b/src/eitd/SIsections.hpp index adaf125de..168fa834c 100644 --- a/src/eitd/SIsections.hpp +++ b/src/eitd/SIsections.hpp @@ -89,4 +89,20 @@ public: }; +class SIsectionTIME +{ + private: + time_t dvbtime; + int parsed; + void parse(uint8_t *buf); + public: + SIsectionTIME(uint8_t *buf) + { + parsed = 0; + parse(buf); + } + time_t getTime() { return dvbtime; } + int is_parsed(void) const { return parsed; } +}; + #endif // SISECTIONS_HPP