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
FixupKey
uint64_t FixupKey
Definition: eithelper.h:79
EITHelper::m_dbEvents
MythDeque< DBEventEIT * > m_dbEvents
Definition: eithelper.h:159
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:126
e
QDomElement e
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1417
EITHelper::WriteEITCache
static void WriteEITCache(void)
Definition: eithelper.cpp:744
EITHelper::SetChannelID
void SetChannelID(uint _channelid)
Definition: eithelper.cpp:135
EITHelper::EITHelper
EITHelper(void)
Definition: eithelper.cpp:37
EITFixUp
EIT Fix Up Functions.
Definition: eitfixup.h:14
ATSCEvent::ATSCEvent
ATSCEvent(uint a, uint b, uint c, QString d, const unsigned char *e, uint f)
Definition: eithelper.h:28
EITHelper::SetFixup
void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup)
Definition: eithelper.cpp:105
DVBEventInformationTable
Definition: dvbtables.h:296
EITHelper::m_incompleteEvents
ATSCSRCToEvents m_incompleteEvents
Definition: eithelper.h:157
PremiereContentInformationTable
Definition: premieretables.h:11
ATSCEtt
Definition: eithelper.h:55
EITHelper::AddETT
void AddETT(uint atsc_major, uint atsc_minor, const ExtendedTextTable *ett)
Definition: eithelper.cpp:180
EITHelper::m_eitFixup
EITFixUp * m_eitFixup
Definition: eithelper.h:145
EITHelper::m_sourceid
uint m_sourceid
id of the video source
Definition: eithelper.h:151
EITHelper::m_eitListLock
QMutex m_eitListLock
EIT List lock.
Definition: eithelper.h:142
FixupValue
uint64_t FixupValue
Definition: eithelper.h:80
EITHelper::EITHelper
EITHelper(const EITHelper &rhs)
ATSCEvent::m_length
uint32_t m_length
Definition: eithelper.h:42
ATSCEtt::m_ett_text
QString m_ett_text
Definition: eithelper.h:67
EventIDToATSCEvent
QMap< uint, ATSCEvent > EventIDToATSCEvent
Definition: eithelper.h:74
EITHelper::m_channelid
uint m_channelid
id of the channel
Definition: eithelper.h:152
ATSCEvent::m_descLength
uint32_t m_descLength
Definition: eithelper.h:44
mythdeque.h
EITHelper::m_fixup
FixupMap m_fixup
Definition: eithelper.h:156
EITHelper::AddEIT
void AddEIT(uint atsc_major, uint atsc_minor, const EventInformationTable *eit)
Definition: eithelper.cpp:141
EITHelper::RescheduleRecordings
void RescheduleRecordings(void)
Tells scheduler about programming changes.
Definition: eithelper.cpp:1382
EITHelper::m_languagePreferences
QMap< uint, uint > m_languagePreferences
Definition: eithelper.h:161
ATSCEvent::IsStale
bool IsStale() const
Definition: eithelper.h:34
ATSCEvent::m_scanTime
time_t m_scanTime
Definition: eithelper.h:50
EITHelper::m_gpsOffset
int m_gpsOffset
Definition: eithelper.h:148
mpegtables.h
EITHelper::~EITHelper
virtual ~EITHelper(void)
Definition: eithelper.cpp:43
f
QTextStream t & f
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:600
ATSCEtt::ATSCEtt
ATSCEtt(QString text)
Definition: eithelper.h:57
EventInformationTable
EventInformationTables contain program titles, start times, and channel information.
Definition: atsctables.h:521
ATSCEvent::m_title
QString m_title
Definition: eithelper.h:45
EITHelper::CompleteEvent
void CompleteEvent(uint atsc_major, uint atsc_minor, const ATSCEvent &event, const QString &ett)
Definition: eithelper.cpp:753
uint
unsigned int uint
Definition: compat.h:140
EITHelper
Definition: eithelper.h:93
ATSCEtt::IsStale
bool IsStale() const
Definition: eithelper.h:60
ServiceToChanID
QMap< unsigned long long, uint > ServiceToChanID
Definition: eithelper.h:77
ATSCEvent::m_desc
const unsigned char * m_desc
Definition: eithelper.h:46
EITHelper::GetChanID
uint GetChanID(uint atsc_major, uint atsc_minor)
Definition: eithelper.cpp:787
EventIDToETT
QMap< uint, ATSCEtt > EventIDToETT
Definition: eithelper.h:75
ATSCEvent::m_etm
uint32_t m_etm
Definition: eithelper.h:43
ATSCEtt::m_scanTime
time_t m_scanTime
Definition: eithelper.h:71
EITHelper::GetGPSOffset
uint GetGPSOffset(void) const
Definition: eithelper.h:102
EITHelper::SetLanguagePreferences
void SetLanguagePreferences(const QStringList &langPref)
Definition: eithelper.cpp:112
EITHelper::m_seenEITother
bool m_seenEITother
if false we only reschedule the active mplex
Definition: eithelper.h:154
DBEventEIT
Definition: programdata.h:165
EITHelper::ProcessEvents
uint ProcessEvents(void)
Inserts events in EIT list.
Definition: eithelper.cpp:63
MythDeque< DBEventEIT * >
EITHelper::SetGPSOffset
void SetGPSOffset(uint _gps_offset)
Definition: eithelper.h:105
EITHelper::m_srvToChanid
ServiceToChanID m_srvToChanid
Definition: eithelper.h:143
EITHelper::kChunkSize
static const uint kChunkSize
Maximum number of DB inserts per ProcessEvents call.
Definition: eithelper.h:164
EITHelper::GetListSize
uint GetListSize(void) const
Definition: eithelper.cpp:52
EITHelper::PruneEITCache
static void PruneEITCache(uint timestamp)
Definition: eithelper.cpp:739
ExtendedTextTable
ExtendedTextTable contain additional text not contained in EventInformationTables.
Definition: atsctables.h:621
ATSCEvent::m_startTime
uint32_t m_startTime
Definition: eithelper.h:41
d
static const iso6937table * d
Definition: iso6937tables.cpp:1025
ATSCEvent
Definition: eithelper.h:26
EITHelper::SetSourceID
void SetSourceID(uint _sourceid)
Definition: eithelper.cpp:129
FixupMap
QMap< FixupKey, FixupValue > FixupMap
Definition: eithelper.h:81
EITHelper::s_eitCache
static EITCache * s_eitCache
Definition: eithelper.h:146
ATSCSRCToEvents
QMap< uint, EventIDToATSCEvent > ATSCSRCToEvents
Definition: eithelper.h:76
EITHelper::m_maxStarttime
QDateTime m_maxStarttime
latest starttime of changed events
Definition: eithelper.h:153
EITCache
Definition: eitcache.h:23
GPS_LEAP_SECONDS
#define GPS_LEAP_SECONDS
Leap seconds as of June 30th, 2012.
Definition: mpegtables.h:34