MythTV master
premieredescriptors.cpp
Go to the documentation of this file.
1#include <cmath>
2
4#include "dvbdescriptors.h"
5
7{
9 m_datePtrs.clear();
10 m_timePtrs.clear();
11 const uint8_t *dataptr = m_data + 8;
12 while ((dataptr + 6) <= (m_data + 2 + DescriptorLength()))
13 {
14 uint starttime_no = *(dataptr+2);
15 for (uint i=0; i < starttime_no; i+=3)
16 {
17 m_datePtrs.push_back(dataptr);
18 m_timePtrs.push_back(dataptr + 3 + i);
20 }
21 dataptr += 3 + starttime_no;
22 }
23 return true;
24}
25
26
28{
29 // set buf to the startdate
30 const uint8_t *buf = m_datePtrs[index];
31 uint mjd = (buf[0] << 8) | buf[1];
32 // reset buf two bytes before the startime
33 buf = m_timePtrs[index]-2;
34 if (mjd >= 40587)
35 {
36 // Modified Julian date as number of days since 17th November 1858.
37 // 1st Jan 1970 was date 40587.
38 uint secsSince1970 = (mjd - 40587) * 86400;
39 secsSince1970 += byteBCD2int(buf[2]) * 3600;
40 secsSince1970 += byteBCD2int(buf[3]) * 60;
41 secsSince1970 += byteBCD2int(buf[4]);
42 return MythDate::fromSecsSinceEpoch(secsSince1970);
43 }
44
45 // Original function taken from dvbdate.c in linuxtv-apps code
46 // Use the routine specified in ETSI EN 300 468 V1.4.1,
47 // "Specification for Service Information in Digital Video Broadcasting"
48 // to convert from Modified Julian Date to Year, Month, Day.
49
50 const auto tmpA = (float)(1.0 / 365.25);
51 const auto tmpB = (float)(1.0 / 30.6001);
52
53 float mjdf = mjd;
54 int year = (int) truncf((mjdf - 15078.2F) * tmpA);
55 int month = (int) truncf(
56 (mjdf - 14956.1F - truncf(year * 365.25F)) * tmpB);
57 int day = (int) truncf(
58 (mjdf - 14956.0F - truncf(year * 365.25F) - truncf(month * 30.6001F)));
59 int i = (month == 14 || month == 15) ? 1 : 0;
60
61 QDate date(1900 + year + i, month - 1 - (i * 12), day);
62 QTime time(byteBCD2int(buf[2]), byteBCD2int(buf[3]),
63 byteBCD2int(buf[4]));
64
65#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
66 return {date, time, Qt::UTC};
67#else
68 return {date, time, QTimeZone(QTimeZone::UTC)};
69#endif
70}
uint DescriptorLength(void) const
const unsigned char * m_data
std::vector< const uint8_t * > m_datePtrs
std::vector< const uint8_t * > m_timePtrs
static constexpr uint8_t byteBCD2int(uint8_t i)
unsigned int uint
Definition: freesurround.h:24
MBASE_PUBLIC QDateTime fromSecsSinceEpoch(int64_t seconds)
This function takes the number of seconds since the start of the epoch and returns a QDateTime with t...
Definition: mythdate.cpp:81