MythTV  master
premieredescriptors.cpp
Go to the documentation of this file.
1 #include <cmath>
2 
3 #include "premieredescriptors.h"
4 #include "dvbdescriptors.h"
5 
7 {
9  _date_ptrs.clear();
10  _time_ptrs.clear();
11  const uint8_t *dataptr = _data + 8;
12  while ((dataptr + 6) <= (_data + 2 + DescriptorLength()))
13  {
14  uint starttime_no = *(dataptr+2);
15  for (uint i=0; i < starttime_no; i+=3)
16  {
17  _date_ptrs.push_back(dataptr);
18  _time_ptrs.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 = _date_ptrs[index];
31  uint mjd = (buf[0] << 8) | buf[1];
32  // reset buf two bytes before the startime
33  buf = _time_ptrs[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 #if QT_VERSION < QT_VERSION_CHECK(5,8,0)
43  return MythDate::fromTime_t(secsSince1970);
44 #else
45  return MythDate::fromSecsSinceEpoch(secsSince1970);
46 #endif
47  }
48 
49  // Original function taken from dvbdate.c in linuxtv-apps code
50  // Use the routine specified in ETSI EN 300 468 V1.4.1,
51  // "Specification for Service Information in Digital Video Broadcasting"
52  // to convert from Modified Julian Date to Year, Month, Day.
53 
54  const float tmpA = (float)(1.0 / 365.25);
55  const float tmpB = (float)(1.0 / 30.6001);
56 
57  float mjdf = mjd;
58  int year = (int) truncf((mjdf - 15078.2F) * tmpA);
59  int month = (int) truncf(
60  (mjdf - 14956.1F - truncf(year * 365.25F)) * tmpB);
61  int day = (int) truncf(
62  (mjdf - 14956.0F - truncf(year * 365.25F) - truncf(month * 30.6001F)));
63  int i = (month == 14 || month == 15) ? 1 : 0;
64 
65  QDate date(1900 + year + i, month - 1 - i * 12, day);
66  QTime time(byteBCD2int(buf[2]), byteBCD2int(buf[3]),
67  byteBCD2int(buf[4]));
68 
69  return QDateTime(date, time, Qt::UTC);
70 }
unsigned int uint
Definition: compat.h:140
MBASE_PUBLIC QDateTime fromSecsSinceEpoch(uint seconds)
This function takes the number of seconds since the start of the epoch and returns a QDateTime with t...
Definition: mythdate.cpp:88
uint DescriptorLength(void) const
const unsigned char * _data
#define byteBCD2int(i)