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