MythTV  master
eithelper.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef EIT_HELPER_H
4 #define EIT_HELPER_H
5 
6 // C+ headers
7 #include <cstdint>
8 #include <ctime>
9 #include <utility>
10 
11 // Qt includes
12 #include <QDateTime>
13 #include <QMap>
14 #include <QMutex>
15 #include <QObject>
16 #include <QString>
17 
18 // MythTV includes
19 #include "mythdeque.h"
20 #include "mpegtables.h" // for GPS_LEAP_SECONDS
21 
22 class MSqlQuery;
23 
24 // An entry from the EIT table containing event details.
25 class ATSCEvent
26 {
27  public:
28  ATSCEvent(uint a, uint b, uint c, QString d,
29  const unsigned char *e, uint f)
30  : m_startTime(a), m_length(b), m_etm(c), m_descLength(f),
31  m_title(std::move(d)), m_desc(e),
32  m_scanTime(time(nullptr)) {}
33 
34  bool IsStale() const {
35  // The minimum recommended repetition time for EIT events according to
36  // http://atsc.org/wp-content/uploads/2015/03/Program-and-system-information-protocol-implementation-guidelines-for-broadcaster.pdf
37  // is one minute. Consider any EIT event seen > 2 minutes in the past as stale.
38  return m_scanTime + 2 * 60 < time(nullptr);
39  }
40 
41  uint32_t m_startTime;
42  uint32_t m_length;
43  uint32_t m_etm;
44  uint32_t m_descLength;
45  QString m_title;
46  const unsigned char *m_desc {nullptr};
47 
48  private:
49  // The time the event was created.
50  time_t m_scanTime;
51 };
52 
53 // An entry from the ETT table containing description text for an event.
54 class ATSCEtt
55 {
56  public:
57  explicit ATSCEtt(QString text) :
58  m_ett_text(std::move(text)), m_scanTime(time(nullptr)) {}
59 
60  bool IsStale() const {
61  // The minimum recommended repetition time for ETT events according to
62  // http://atsc.org/wp-content/uploads/2015/03/Program-and-system-information-protocol-implementation-guidelines-for-broadcaster.pdf
63  // is one minute. Consider any ETT event seen > 2 minutes in the past as stale.
64  return m_scanTime + 2 * 60 < time(nullptr);
65  }
66 
67  QString m_ett_text;
68 
69  private:
70  // The time the ETT was created.
71  time_t m_scanTime;
72 };
73 
74 using EventIDToATSCEvent = QMap<uint,ATSCEvent> ;
75 using EventIDToETT = QMap<uint,ATSCEtt>;
76 using ATSCSRCToEvents = QMap<uint,EventIDToATSCEvent>;
77 using ServiceToChanID = QMap<unsigned long long,uint>;
78 
79 using FixupKey = uint64_t;
80 using FixupValue = uint64_t;
81 using FixupMap = QMap<FixupKey, FixupValue>;
82 
83 class DBEventEIT;
84 class EITFixUp;
85 class EITCache;
86 
88 class ExtendedTextTable;
91 
92 class EITHelper
93 {
94  public:
95  EITHelper(void);
96  EITHelper(const EITHelper& rhs);
97  virtual ~EITHelper(void);
98 
99  uint GetListSize(void) const;
100  uint ProcessEvents(void);
101 
102  uint GetGPSOffset(void) const { return (uint) (0 - m_gpsOffset); }
103 
104  void SetChannelID(uint _channelid);
105  void SetGPSOffset(uint _gps_offset) { m_gpsOffset = 0 - _gps_offset; }
106  void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup);
107  void SetLanguagePreferences(const QStringList &langPref);
108  void SetSourceID(uint _sourceid);
109  void RescheduleRecordings(void);
110 
111 #ifdef USING_BACKEND
112  void AddEIT(uint atsc_major, uint atsc_minor,
113  const EventInformationTable *eit);
114  void AddETT(uint atsc_major, uint atsc_minor,
115  const ExtendedTextTable *ett);
116  void AddEIT(const DVBEventInformationTable *eit);
117  void AddEIT(const PremiereContentInformationTable *cit);
118 #else // if !USING_BACKEND
119  void AddEIT(uint /*atsc_major*/, uint /*atsc_minor*/, const EventInformationTable */*eit*/) {}
120  void AddETT(uint /*atsc_major*/, uint /*atsc_minor*/, const ExtendedTextTable */*ett*/) {}
121  void AddEIT(const DVBEventInformationTable */*eit*/) {}
122  void AddEIT(const PremiereContentInformationTable */*cit*/) {}
123 #endif // !USING_BACKEND
124 
125  // EIT cache handling
126  static void PruneEITCache(uint timestamp);
127  static void WriteEITCache(void);
128 
129  private:
130  // only ATSC
131  uint GetChanID(uint atsc_major, uint atsc_minor);
132  // only DVB
133  uint GetChanID(uint serviceid, uint networkid, uint tsid);
134  // any DTV
135  uint GetChanID(uint program_number);
136 
137  void CompleteEvent(uint atsc_major, uint atsc_minor,
138  const ATSCEvent &event,
139  const QString &ett);
140 
141  //QListList_Events m_eitList; ///< Event Information Tables List
142  mutable QMutex m_eitListLock;
144 
145  EITFixUp *m_eitFixup {nullptr};
147 
149 
150  /* carry some values to optimize channel lookup and reschedules */
153  QDateTime m_maxStarttime;
154  bool m_seenEITother {false};
155 
158 
160 
161  QMap<uint,uint> m_languagePreferences;
162 
164  static const uint kChunkSize;
165 };
166 
167 #endif // EIT_HELPER_H
int m_gpsOffset
Definition: eithelper.h:148
ATSCEtt(QString text)
Definition: eithelper.h:57
uint32_t m_etm
Definition: eithelper.h:43
QMap< unsigned long long, uint > ServiceToChanID
Definition: eithelper.h:77
uint GetChanID(uint atsc_major, uint atsc_minor)
Definition: eithelper.cpp:812
void CompleteEvent(uint atsc_major, uint atsc_minor, const ATSCEvent &event, const QString &ett)
Definition: eithelper.cpp:773
uint32_t m_length
Definition: eithelper.h:42
ExtendedTextTable contain additional text not contained in EventInformationTables.
Definition: atsctables.h:624
void SetGPSOffset(uint _gps_offset)
Definition: eithelper.h:105
QMutex m_eitListLock
EIT List lock.
Definition: eithelper.h:142
#define GPS_LEAP_SECONDS
Leap seconds as of June 30th, 2012.
Definition: mpegtables.h:34
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
uint GetGPSOffset(void) const
Definition: eithelper.h:102
MythDeque< DBEventEIT * > m_dbEvents
Definition: eithelper.h:159
EITHelper(void)
Definition: eithelper.cpp:37
void SetLanguagePreferences(const QStringList &langPref)
Definition: eithelper.cpp:112
time_t m_scanTime
Definition: eithelper.h:71
uint GetListSize(void) const
Definition: eithelper.cpp:52
void AddEIT(uint atsc_major, uint atsc_minor, const EventInformationTable *eit)
Definition: eithelper.cpp:141
uint32_t m_startTime
Definition: eithelper.h:41
QString m_ett_text
Definition: eithelper.h:67
time_t m_scanTime
Definition: eithelper.h:50
static void WriteEITCache(void)
Definition: eithelper.cpp:764
const unsigned char * m_desc
Definition: eithelper.h:46
FixupMap m_fixup
Definition: eithelper.h:156
bool IsStale() const
Definition: eithelper.h:60
static const uint16_t * d
bool IsStale() const
Definition: eithelper.h:34
uint64_t FixupValue
Definition: eithelper.h:80
void AddETT(uint atsc_major, uint atsc_minor, const ExtendedTextTable *ett)
Definition: eithelper.cpp:180
QMap< uint, ATSCEtt > EventIDToETT
Definition: eithelper.h:75
EITFixUp * m_eitFixup
Definition: eithelper.h:145
QMap< uint, ATSCEvent > EventIDToATSCEvent
Definition: eithelper.h:74
ATSCSRCToEvents m_incompleteEvents
Definition: eithelper.h:157
unsigned int uint
Definition: compat.h:140
QMap< FixupKey, FixupValue > FixupMap
Definition: eithelper.h:81
EIT Fix Up Functions.
Definition: eitfixup.h:13
bool m_seenEITother
if false we only reschedule the active mplex
Definition: eithelper.h:154
void SetSourceID(uint _sourceid)
Definition: eithelper.cpp:129
EventInformationTables contain program titles, start times, and channel information.
Definition: atsctables.h:520
QMap< uint, EventIDToATSCEvent > ATSCSRCToEvents
Definition: eithelper.h:76
QString m_title
Definition: eithelper.h:45
virtual ~EITHelper(void)
Definition: eithelper.cpp:43
static void PruneEITCache(uint timestamp)
Definition: eithelper.cpp:759
static const uint kChunkSize
Maximum number of DB inserts per ProcessEvents call.
Definition: eithelper.h:164
ServiceToChanID m_srvToChanid
Definition: eithelper.h:143
void SetChannelID(uint _channelid)
Definition: eithelper.cpp:135
QDateTime m_maxStarttime
latest starttime of changed events
Definition: eithelper.h:153
ATSCEvent(uint a, uint b, uint c, QString d, const unsigned char *e, uint f)
Definition: eithelper.h:28
QMap< uint, uint > m_languagePreferences
Definition: eithelper.h:161
uint ProcessEvents(void)
Inserts events in EIT list.
Definition: eithelper.cpp:63
static EITCache * s_eitCache
Definition: eithelper.h:146
uint m_sourceid
id of the video source
Definition: eithelper.h:151
uint64_t FixupKey
Definition: eithelper.h:79
uint32_t m_descLength
Definition: eithelper.h:44
void RescheduleRecordings(void)
Tells scheduler about programming changes.
Definition: eithelper.cpp:1407
void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup)
Definition: eithelper.cpp:105
uint m_channelid
id of the channel
Definition: eithelper.h:152