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 typedef QMap<uint,ATSCEvent> EventIDToATSCEvent;
72 typedef QMap<uint,ATSCEtt> EventIDToETT;
73 typedef QMap<uint,EventIDToATSCEvent> ATSCSRCToEvents;
74 typedef QMap<unsigned long long,uint> ServiceToChanID;
75 
76 typedef uint64_t FixupKey;
77 typedef uint64_t FixupValue;
78 typedef QMap<FixupKey, FixupValue> FixupMap;
79 
80 class DBEventEIT;
81 class EITFixUp;
82 class EITCache;
83 
85 class ExtendedTextTable;
88 
89 class EITHelper
90 {
91  public:
92  EITHelper(void);
93  EITHelper(const EITHelper& rhs);
94  virtual ~EITHelper(void);
95 
96  uint GetListSize(void) const;
97  uint ProcessEvents(void);
98 
99  uint GetGPSOffset(void) const { return (uint) (0 - gps_offset); }
100 
101  void SetChannelID(uint _channelid);
102  void SetGPSOffset(uint _gps_offset) { gps_offset = 0 - _gps_offset; }
103  void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup);
104  void SetLanguagePreferences(const QStringList &langPref);
105  void SetSourceID(uint _sourceid);
106  void RescheduleRecordings(void);
107 
108 #ifdef USING_BACKEND
109  void AddEIT(uint atsc_major, uint atsc_minor,
110  const EventInformationTable *eit);
111  void AddETT(uint atsc_major, uint atsc_minor,
112  const ExtendedTextTable *ett);
113  void AddEIT(const DVBEventInformationTable *eit);
114  void AddEIT(const PremiereContentInformationTable *cit);
115 #else // if !USING_BACKEND
116  void AddEIT(uint, uint, const EventInformationTable*) {}
117  void AddETT(uint, uint, const ExtendedTextTable*) {}
118  void AddEIT(const DVBEventInformationTable*) {}
120 #endif // !USING_BACKEND
121 
122  // EIT cache handling
123  void PruneEITCache(uint timestamp);
124  void WriteEITCache(void);
125 
126  private:
127  // only ATSC
128  uint GetChanID(uint atsc_major, uint atsc_minor);
129  // only DVB
130  uint GetChanID(uint serviceid, uint networkid, uint tsid);
131  // any DTV
132  uint GetChanID(uint program_number);
133 
134  void CompleteEvent(uint atsc_major, uint atsc_minor,
135  const ATSCEvent &event,
136  const QString &ett);
137 
138  //QListList_Events eitList; ///< Event Information Tables List
139  mutable QMutex eitList_lock;
141 
144 
146 
147  /* carry some values to optimize channel lookup and reschedules */
150  QDateTime maxStarttime;
152 
155 
157 
158  QMap<uint,uint> languagePreferences;
159 
161  static const uint kChunkSize;
162 };
163 
164 #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:807
void CompleteEvent(uint atsc_major, uint atsc_minor, const ATSCEvent &event, const QString &ett)
Definition: eithelper.cpp:768
uint32_t m_length
Definition: eithelper.h:39
QMap< FixupKey, FixupValue > FixupMap
Definition: eithelper.h:78
QMap< uint, uint > languagePreferences
Definition: eithelper.h:158
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:102
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
uint GetGPSOffset(void) const
Definition: eithelper.h:99
unsigned int uint
Definition: compat.h:140
EITHelper(void)
Definition: eithelper.cpp:37
void SetLanguagePreferences(const QStringList &langPref)
Definition: eithelper.cpp:115
QMutex eitList_lock
EIT List lock.
Definition: eithelper.h:139
MythDeque< DBEventEIT * > db_events
Definition: eithelper.h:156
uint GetListSize(void) const
Definition: eithelper.cpp:55
void AddEIT(uint atsc_major, uint atsc_minor, const EventInformationTable *eit)
Definition: eithelper.cpp:144
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:76
void WriteEITCache(void)
Definition: eithelper.cpp:759
uint channelid
id of the channel
Definition: eithelper.h:149
ATSCSRCToEvents incomplete_events
Definition: eithelper.h:154
const unsigned char * m_desc
Definition: eithelper.h:43
bool IsStale() const
Definition: eithelper.h:57
static const uint16_t * d
QMap< uint, ATSCEtt > EventIDToETT
Definition: eithelper.h:72
bool IsStale() const
Definition: eithelper.h:31
void AddETT(uint atsc_major, uint atsc_minor, const ExtendedTextTable *ett)
Definition: eithelper.cpp:183
QMap< unsigned long long, uint > ServiceToChanID
Definition: eithelper.h:74
int gps_offset
Definition: eithelper.h:145
EITFixUp * eitfixup
Definition: eithelper.h:142
EIT Fix Up Functions.
Definition: eitfixup.h:13
void SetSourceID(uint _sourceid)
Definition: eithelper.cpp:132
EventInformationTables contain program titles, start times, and channel information.
Definition: atsctables.h:521
FixupMap fixup
Definition: eithelper.h:153
ServiceToChanID srv_to_chanid
Definition: eithelper.h:140
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:151
time_t m_scan_time
Definition: eithelper.h:68
uint sourceid
id of the video source
Definition: eithelper.h:148
QString m_title
Definition: eithelper.h:42
virtual ~EITHelper(void)
Definition: eithelper.cpp:46
void PruneEITCache(uint timestamp)
Definition: eithelper.cpp:754
QDateTime maxStarttime
latest starttime of changed events
Definition: eithelper.h:150
static const uint kChunkSize
Maximum number of DB inserts per ProcessEvents call.
Definition: eithelper.h:161
uint64_t FixupValue
Definition: eithelper.h:77
void SetChannelID(uint _channelid)
Definition: eithelper.cpp:138
uint ProcessEvents(void)
Inserts events in EIT list.
Definition: eithelper.cpp:66
QMap< uint, ATSCEvent > EventIDToATSCEvent
Definition: eithelper.h:71
QMap< uint, EventIDToATSCEvent > ATSCSRCToEvents
Definition: eithelper.h:73
void RescheduleRecordings(void)
Tells scheduler about programming changes.
Definition: eithelper.cpp:1405
static EITCache * s_eitcache
Definition: eithelper.h:143
void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup)
Definition: eithelper.cpp:108