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 <utility>
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 "libmythbase/mythconfig.h"
21#include "libmythtv/mpeg/mpegtables.h" // for GPS_LEAP_SECONDS
22
23class MSqlQuery;
24
25// An entry from the EIT table containing event details.
27{
28 public:
29 ATSCEvent(uint a, uint b, uint c, QString d,
30 const unsigned char *e, uint f)
31 : m_startTime(a), m_length(b), m_etm(c), m_descLength(f),
32 m_title(std::move(d)), m_desc(e),
33 m_scanTime(SystemClock::now()) {}
34
35 bool IsStale() const {
36 // The minimum recommended repetition time for EIT events according to
37 // http://atsc.org/wp-content/uploads/2015/03/Program-and-system-information-protocol-implementation-guidelines-for-broadcaster.pdf
38 // is one minute. Consider any EIT event seen > 2 minutes in the past as stale.
39 return m_scanTime + 2min < SystemClock::now();
40 }
41
42 uint32_t m_startTime;
43 uint32_t m_length;
44 uint32_t m_etm;
45 uint32_t m_descLength;
46 QString m_title;
47 const unsigned char *m_desc {nullptr};
48
49 private:
50 // The time the event was created.
52};
53
54// An entry from the ETT table containing description text for an event.
56{
57 public:
58 explicit ATSCEtt(QString text) :
59 m_ett_text(std::move(text)), m_scanTime(SystemClock::now()) {}
60
61 bool IsStale() const {
62 // The minimum recommended repetition time for ETT events according to
63 // http://atsc.org/wp-content/uploads/2015/03/Program-and-system-information-protocol-implementation-guidelines-for-broadcaster.pdf
64 // is one minute. Consider any ETT event seen > 2 minutes in the past as stale.
65 return m_scanTime + 2min < SystemClock::now();
66 }
67
68 QString m_ett_text;
69
70 private:
71 // The time the ETT was created.
73};
74
75using EventIDToATSCEvent = QMap<uint,ATSCEvent> ;
76using EventIDToETT = QMap<uint,ATSCEtt>;
77using ATSCSRCToEvents = QMap<uint,EventIDToATSCEvent>;
78using ServiceToChanID = QMap<uint64_t,uint>;
79
80using FixupKey = uint64_t;
81using FixupValue = uint64_t;
82using FixupMap = QMap<FixupKey, FixupValue>;
83
84class DBEventEIT;
85class EITFixUp;
86class EITCache;
87
92
94{
95 public:
96 explicit EITHelper(uint cardnum);
97 EITHelper &operator=(const EITHelper &) = delete;
98 EITHelper(const EITHelper& rhs);
99 virtual ~EITHelper(void);
100
101 uint GetListSize(void) const;
102 uint ProcessEvents(void);
103 bool EventQueueFull(void) const;
104
105 uint GetGPSOffset(void) const { return (uint) (0 - m_gpsOffset); }
106
107 void SetChannelID(uint channelid);
108 void SetGPSOffset(uint gps_offset) { m_gpsOffset = 0 - gps_offset; }
109 void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup);
110 void SetLanguagePreferences(const QStringList &langPref);
111 void SetSourceID(uint sourceid);
112 void RescheduleRecordings(void);
113
114#if CONFIG_BACKEND
115 void AddEIT(uint atsc_major, uint atsc_minor,
116 const EventInformationTable *eit);
117 void AddETT(uint atsc_major, uint atsc_minor,
118 const ExtendedTextTable *ett);
119 void AddEIT(const DVBEventInformationTable *eit);
121#else // !CONFIG_BACKEND
122 void AddEIT(uint /*atsc_major*/, uint /*atsc_minor*/, const EventInformationTable */*eit*/) {}
123 void AddETT(uint /*atsc_major*/, uint /*atsc_minor*/, const ExtendedTextTable */*ett*/) {}
124 void AddEIT(const DVBEventInformationTable */*eit*/) {}
126#endif // !CONFIG_BACKEND
127
128 // EIT cache handling
129 static void PruneEITCache(uint timestamp);
130 static void WriteEITCache(void);
131
132 private:
133 uint GetChanID(uint atsc_major, uint atsc_minor); // Only ATSC
134 uint GetChanID(uint serviceid, uint networkid, uint tsid); // Only DVB
135 uint GetChanID(uint program_number); // Any DTV
136
137 void CompleteEvent(uint atsc_major, uint atsc_minor, // Only ATSC
138 const ATSCEvent &event,
139 const QString &ett);
140
141 mutable QMutex m_eitListLock;
143
145
147
148 // Carry some values to optimize channel lookup and reschedules
149 uint m_cardnum {0}; // Card ID
150 uint m_sourceid {0}; // Video source ID
151 uint m_channelid {0}; // Channel ID
152 QDateTime m_maxStarttime; // Latest starttime of changed events
153 bool m_seenEITother {false}; // If false we only reschedule the active mplex
154 uint m_chunkSize {20}; // Maximum number of DB inserts per ProcessEvents call
155 uint m_queueSize {1000}; // Maximum number of events waiting to be processed
156
159
161
162 QMap<uint,uint> m_languagePreferences;
163
164 static const uint kMaxQueueSize; // Maximum queue size for events waiting to be processed
165};
166
167#endif // EIT_HELPER_H
SystemTime m_scanTime
Definition: eithelper.h:72
QString m_ett_text
Definition: eithelper.h:68
ATSCEtt(QString text)
Definition: eithelper.h:58
bool IsStale() const
Definition: eithelper.h:61
uint32_t m_length
Definition: eithelper.h:43
uint32_t m_startTime
Definition: eithelper.h:42
QString m_title
Definition: eithelper.h:46
const unsigned char * m_desc
Definition: eithelper.h:47
uint32_t m_descLength
Definition: eithelper.h:45
uint32_t m_etm
Definition: eithelper.h:44
SystemTime m_scanTime
Definition: eithelper.h:51
ATSCEvent(uint a, uint b, uint c, QString d, const unsigned char *e, uint f)
Definition: eithelper.h:29
bool IsStale() const
Definition: eithelper.h:35
EIT Fix Up Functions.
Definition: eitfixup.h:12
void SetSourceID(uint sourceid)
Definition: eithelper.cpp:156
static void PruneEITCache(uint timestamp)
Definition: eithelper.cpp:780
uint GetListSize(void) const
Definition: eithelper.cpp:66
void AddETT(uint, uint, const ExtendedTextTable *)
Definition: eithelper.h:123
uint ProcessEvents(void)
Get events from queue and insert into DB after processing.
Definition: eithelper.cpp:87
uint m_chunkSize
Definition: eithelper.h:154
uint m_cardnum
Definition: eithelper.h:149
void SetFixup(uint atsc_major, uint atsc_minor, FixupValue eitfixup)
Definition: eithelper.cpp:132
FixupMap m_fixup
Definition: eithelper.h:157
uint GetGPSOffset(void) const
Definition: eithelper.h:105
static EITCache * s_eitCache
Definition: eithelper.h:144
static const uint kMaxQueueSize
Definition: eithelper.h:164
EITHelper(uint cardnum)
Definition: eithelper.cpp:40
uint GetChanID(uint atsc_major, uint atsc_minor)
Definition: eithelper.cpp:832
void SetLanguagePreferences(const QStringList &langPref)
Definition: eithelper.cpp:139
ServiceToChanID m_srvToChanid
Definition: eithelper.h:142
void CompleteEvent(uint atsc_major, uint atsc_minor, const ATSCEvent &event, const QString &ett)
Definition: eithelper.cpp:794
QDateTime m_maxStarttime
Definition: eithelper.h:152
uint m_queueSize
Definition: eithelper.h:155
void RescheduleRecordings(void)
Tells scheduler about programming changes.
Definition: eithelper.cpp:1365
uint m_sourceid
Definition: eithelper.h:150
static void WriteEITCache(void)
Definition: eithelper.cpp:785
QMutex m_eitListLock
Definition: eithelper.h:141
MythDeque< DBEventEIT * > m_dbEvents
Definition: eithelper.h:160
ATSCSRCToEvents m_incompleteEvents
Definition: eithelper.h:158
void AddEIT(const DVBEventInformationTable *)
Definition: eithelper.h:124
bool m_seenEITother
Definition: eithelper.h:153
QMap< uint, uint > m_languagePreferences
Definition: eithelper.h:162
uint m_channelid
Definition: eithelper.h:151
virtual ~EITHelper(void)
Definition: eithelper.cpp:59
EITHelper(const EITHelper &rhs)
void AddEIT(uint, uint, const EventInformationTable *)
Definition: eithelper.h:122
bool EventQueueFull(void) const
Definition: eithelper.cpp:72
int m_gpsOffset
Definition: eithelper.h:146
EITHelper & operator=(const EITHelper &)=delete
void SetGPSOffset(uint gps_offset)
Definition: eithelper.h:108
void AddEIT(const PremiereContentInformationTable *)
Definition: eithelper.h:125
void SetChannelID(uint channelid)
Definition: eithelper.cpp:162
EventInformationTables contain program titles, start times, and channel information.
Definition: atsctables.h:529
ExtendedTextTable contain additional text not contained in EventInformationTables.
Definition: atsctables.h:630
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
uint64_t FixupValue
Definition: eithelper.h:81
QMap< uint, ATSCEtt > EventIDToETT
Definition: eithelper.h:76
QMap< uint64_t, uint > ServiceToChanID
Definition: eithelper.h:78
QMap< uint, EventIDToATSCEvent > ATSCSRCToEvents
Definition: eithelper.h:77
uint64_t FixupKey
Definition: eithelper.h:80
QMap< FixupKey, FixupValue > FixupMap
Definition: eithelper.h:82
QMap< uint, ATSCEvent > EventIDToATSCEvent
Definition: eithelper.h:75
unsigned int uint
Definition: freesurround.h:24
static const iso6937table * d
static constexpr uint8_t GPS_LEAP_SECONDS
Leap seconds as of June 30th, 2022.
Definition: mpegtables.h:34
std::chrono::system_clock SystemClock
Definition: mythchrono.h:66
std::chrono::time_point< SystemClock > SystemTime
Definition: mythchrono.h:67
STL namespace.