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  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  return QDateTime(date, time, Qt::UTC);
66 }
PremiereContentTransmissionDescriptor::m_transmissionCount
uint m_transmissionCount
Definition: premieredescriptors.h:55
MPEGDescriptor::DescriptorLength
uint DescriptorLength(void) const
Definition: mpegdescriptors.h:346
PremiereContentTransmissionDescriptor::m_datePtrs
std::vector< const uint8_t * > m_datePtrs
Definition: premieredescriptors.h:56
PremiereContentTransmissionDescriptor::m_timePtrs
std::vector< const uint8_t * > m_timePtrs
Definition: premieredescriptors.h:57
MythDate::fromSecsSinceEpoch
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:68
byteBCD2int
#define byteBCD2int(i)
Definition: dvbdescriptors.h:53
PremiereContentTransmissionDescriptor::StartTimeUTC
QDateTime StartTimeUTC(uint i) const
Definition: premieredescriptors.cpp:27
MPEGDescriptor::m_data
const unsigned char * m_data
Definition: mpegdescriptors.h:370
PremiereContentTransmissionDescriptor::Parse
virtual bool Parse(void)
Definition: premieredescriptors.cpp:6
uint
unsigned int uint
Definition: compat.h:140
premieredescriptors.h
dvbdescriptors.h