MythTV  master
atscstreamdata.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2003-2004, Daniel Thor Kristjansson
3 #ifndef ATSCSTREAMDATA_H_
4 #define ATSCSTREAMDATA_H_
5 
6 #include "mpegstreamdata.h"
7 #include "mythtvexp.h"
8 #include "tablestatus.h"
9 
10 using pid_tsid_vec_t = QMap<uint, uint_vec_t>;
15 using tvct_vec_t = vector<const TerrestrialVirtualChannelTable *>;
16 using cvct_vec_t = vector<const CableVirtualChannelTable *>;
17 using tvct_cache_t = QMap<uint, tvct_ptr_t>;
18 using cvct_cache_t = QMap<uint, cvct_ptr_t>;
19 using atsc_eit_pid_map_t = QMap<uint, uint>;
20 using atsc_ett_pid_map_t = QMap<uint, uint>;
21 
22 using atsc_main_listener_vec_t = vector<ATSCMainStreamListener *>;
23 using scte_main_listener_vec_t = vector<SCTEMainStreamListener *>;
24 using atsc_aux_listener_vec_t = vector<ATSCAuxStreamListener *>;
25 using atsc_eit_listener_vec_t = vector<ATSCEITStreamListener *>;
26 using atsc81_eit_listener_vec_t = vector<ATSC81EITStreamListener *>;
27 
29 {
30  public:
31  ATSCStreamData(int desiredMajorChannel,
32  int desiredMinorChannel,
33  int cardnum, bool cacheTables = false);
34  ~ATSCStreamData() override;
35 
36  void Reset(void) override { Reset(-1, -1); } // MPEGStreamData
37  void Reset(int desiredProgram) override; // MPEGStreamData
38  void Reset(int desiredMajorChannel, int desiredMinorChannel);
39  void SetDesiredChannel(int major, int minor);
40 
41  // Table processing
42  bool HandleTables(uint pid, const PSIPTable &psip) override; // MPEGStreamData
43  bool IsRedundant(uint pid, const PSIPTable &psip) const override; // MPEGStreamData
44 
46  uint GPSOffset(void) const { return m_gpsUtcOffset; }
47 
48  inline uint GetATSCMajorMinor(uint eit_sourceid) const;
49  inline bool HasATSCMajorMinorMap(void) const;
50  bool HasEITPIDChanges(const uint_vec_t &in_use_pid) const override; // MPEGStreamData
51  bool GetEITPIDChanges(const uint_vec_t &cur_pids,
52  uint_vec_t &add_pids,
53  uint_vec_t &del_pids) const override; // MPEGStreamData
54 
55  // Table versions
57  { m_mgtVersion = version; }
58  void SetVersionTVCT(uint tsid, int version)
59  { m_tvctVersion[tsid] = version; }
60  void SetVersionCVCT(uint tsid, int version)
61  { m_cvctVersion[tsid] = version; }
62  void SetVersionRRT(uint region, int version)
63  { m_rrtVersion[region&0xff] = version; }
64 
65  int VersionMGT() const { return m_mgtVersion; }
66  inline int VersionTVCT(uint tsid) const;
67  inline int VersionCVCT(uint tsid) const;
68  inline int VersionRRT(uint region) const;
69 
70  // Caching
71  bool HasCachedMGT(bool current = true) const;
72  bool HasCachedTVCT(uint pid, bool current = true) const;
73  bool HasCachedCVCT(uint pid, bool current = true) const;
74 
75  bool HasCachedAllTVCTs(bool current = true) const;
76  bool HasCachedAllCVCTs(bool current = true) const;
77  bool HasCachedAllVCTs(bool current = true) const
78  { return HasCachedAllTVCTs(current) && HasCachedAllCVCTs(current); }
79 
80  bool HasCachedAnyTVCTs(bool current = true) const;
81  bool HasCachedAnyCVCTs(bool current = true) const;
82  bool HasCachedAnyVCTs(bool current = true) const
83  { return HasCachedAnyTVCTs(current) || HasCachedAnyCVCTs(current); }
84 
85  const MasterGuideTable *GetCachedMGT(bool current = true) const;
86  tvct_const_ptr_t GetCachedTVCT(uint pid, bool current = true) const;
87  cvct_const_ptr_t GetCachedCVCT(uint pid, bool current = true) const;
88 
89  tvct_vec_t GetCachedTVCTs(bool current = true) const;
90  cvct_vec_t GetCachedCVCTs(bool current = true) const;
91 
92  void ReturnCachedTVCTTables(tvct_vec_t &tvcts) const;
93  void ReturnCachedCVCTTables(cvct_vec_t &cvcts) const;
94 
95  bool HasChannel(uint major, uint minor) const;
96 
97  // Single channel stuff
98  int DesiredMajorChannel(void) const { return m_desiredMajorChannel; }
99  int DesiredMinorChannel(void) const { return m_desiredMinorChannel; }
100 
101  void AddATSCMainListener(ATSCMainStreamListener *val);
102  void AddSCTEMainListener(SCTEMainStreamListener *val);
103  void AddATSCAuxListener(ATSCAuxStreamListener *val);
104  void AddATSCEITListener(ATSCEITStreamListener *val);
105  void AddATSC81EITListener(ATSC81EITStreamListener *val);
106 
107  void RemoveATSCMainListener(ATSCMainStreamListener *val);
108  void RemoveSCTEMainListener(SCTEMainStreamListener *val);
109  void RemoveATSCAuxListener(ATSCAuxStreamListener *val);
110  void RemoveATSCEITListener(ATSCEITStreamListener *val);
111  void RemoveATSC81EITListener(ATSC81EITStreamListener *val);
112 
113  private:
114  void ProcessMGT(const MasterGuideTable *mgt);
115  void ProcessVCT(uint tsid, const VirtualChannelTable *vct);
116  void ProcessTVCT(uint tsid, const TerrestrialVirtualChannelTable *vct);
117  void ProcessCVCT(uint tsid, const CableVirtualChannelTable *vct);
118 
119  // Caching
120  void CacheMGT(MasterGuideTable *mgt);
121  void CacheTVCT(uint pid, TerrestrialVirtualChannelTable *tvct);
122  void CacheCVCT(uint pid, CableVirtualChannelTable *cvct);
123  protected:
124  bool DeleteCachedTable(const PSIPTable *psip) const override; // MPEGStreamData
125 
126  private:
127  uint m_gpsUtcOffset { GPS_LEAP_SECONDS };
128  mutable bool m_atscEitReset { false };
131 
132  QMap<uint,uint> m_sourceIdToAtscMajMin;
133 
134 
135  // Signals
141 
142  // Table versions
143  int m_mgtVersion { -1 };
144  QMap<uint, int> m_tvctVersion;
145  QMap<uint, int> m_cvctVersion;
146  QMap<uint, int> m_rrtVersion;
148 
149  // Caching
150  mutable MasterGuideTable *m_cachedMgt { nullptr };
151  mutable tvct_cache_t m_cachedTvcts; // pid->tvct
152  mutable cvct_cache_t m_cachedCvcts; // pid->cvct
153 
154  // Single program variables
157 };
158 
159 
160 inline uint ATSCStreamData::GetATSCMajorMinor(uint eit_sourceid) const
161 {
162  QMutexLocker locker(&m_listenerLock);
163  return m_sourceIdToAtscMajMin[eit_sourceid];
164 }
165 
167 {
168  QMutexLocker locker(&m_listenerLock);
169  return !m_sourceIdToAtscMajMin.empty();
170 }
171 
172 inline int ATSCStreamData::VersionTVCT(uint tsid) const
173 {
174  const QMap<uint, int>::const_iterator it = m_tvctVersion.find(tsid);
175  if (it == m_tvctVersion.end())
176  return -1;
177  return *it;
178 }
179 
180 inline int ATSCStreamData::VersionCVCT(uint tsid) const
181 {
182  const QMap<uint, int>::const_iterator it = m_cvctVersion.find(tsid);
183  if (it == m_cvctVersion.end())
184  return -1;
185  return *it;
186 }
187 
188 inline int ATSCStreamData::VersionRRT(uint region) const
189 {
190  const QMap<uint, int>::const_iterator it = m_rrtVersion.find(region&0xff);
191  if (it == m_rrtVersion.end())
192  return -1;
193  return *it;
194 }
195 
196 #endif
QMap< uint, uint > m_sourceIdToAtscMajMin
virtual void Reset(void)
int VersionTVCT(uint tsid) const
void SetVersionRRT(uint region, int version)
int DesiredMinorChannel(void) const
void SetVersionCVCT(uint tsid, int version)
int VersionMGT() const
#define GPS_LEAP_SECONDS
Leap seconds as of June 30th, 2012.
Definition: mpegtables.h:34
QMap< uint, int > m_rrtVersion
vector< ATSCEITStreamListener * > atsc_eit_listener_vec_t
void SetVersionTVCT(uint tsid, int version)
virtual bool HandleTables(uint pid, const PSIPTable &psip)
Process PSIP packets.
vector< ATSCAuxStreamListener * > atsc_aux_listener_vec_t
vector< ATSC81EITStreamListener * > atsc81_eit_listener_vec_t
TableStatusMap m_eitStatus
vector< uint > uint_vec_t
QMap< uint, tvct_ptr_t > tvct_cache_t
virtual bool DeleteCachedTable(const PSIPTable *psip) const
int DesiredMajorChannel(void) const
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
Definition: mpegtables.h:386
atsc_main_listener_vec_t m_atscMainListeners
bool HasCachedAnyVCTs(bool current=true) const
This table contains information about the cable channels transmitted on this multiplex.
Definition: atsctables.h:414
bool HasATSCMajorMinorMap(void) const
virtual bool IsRedundant(uint pid, const PSIPTable &psip) const
Returns true if table already seen.
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
QMap< uint, uint > atsc_ett_pid_map_t
#define minor(X)
Definition: compat.h:138
vector< ATSCMainStreamListener * > atsc_main_listener_vec_t
atsc81_eit_listener_vec_t m_atsc81EitListeners
unsigned int uint
Definition: compat.h:140
QMap< uint, int > m_tvctVersion
vector< const TerrestrialVirtualChannelTable * > tvct_vec_t
vector< const CableVirtualChannelTable * > cvct_vec_t
atsc_aux_listener_vec_t m_atscAuxListeners
atsc_eit_listener_vec_t m_atscEitListeners
QMap< uint, uint > atsc_eit_pid_map_t
int VersionCVCT(uint tsid) const
vector< SCTEMainStreamListener * > scte_main_listener_vec_t
This table tells the decoder on which PIDs to find other tables, and their sizes and each table's cur...
Definition: atsctables.h:74
scte_main_listener_vec_t m_scteMainlisteners
uint GPSOffset(void) const
Current UTC to GPS time offset in seconds.
void SetVersionMGT(int version)
bool HasCachedAllVCTs(bool current=true) const
This table contains information about the channels transmitted on this multiplex.
Definition: atsctables.h:189
uint GetATSCMajorMinor(uint eit_sourceid) const
atsc_eit_pid_map_t m_atscEitPids
int VersionRRT(uint region) const
QMap< uint, int > m_cvctVersion
virtual bool HasEITPIDChanges(const uint_vec_t &) const
QMap< uint, cvct_ptr_t > cvct_cache_t
cvct_cache_t m_cachedCvcts
tvct_cache_t m_cachedTvcts
atsc_ett_pid_map_t m_atscEttPids
This table contains information about the terrestrial channels transmitted on this multiplex.
Definition: atsctables.h:345
QMap< uint, uint_vec_t > pid_tsid_vec_t
Encapsulates data about ATSC stream and emits events for most tables.
virtual bool GetEITPIDChanges(const uint_vec_t &, uint_vec_t &, uint_vec_t &) const
Encapsulates data about MPEG stream and emits events for each table.
void Reset(void) override