MythTV  master
signalmonitor.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2005, Daniel Thor Kristjansson
3 
4 #ifndef SIGNALMONITOR_H
5 #define SIGNALMONITOR_H
6 
7 // C++ headers
8 #include <vector>
9 #include <algorithm>
10 
11 // Qt headers
12 #include <QWaitCondition>
13 #include <QMutex>
14 #include <QCoreApplication>
15 
16 // MythTV headers
17 #include "signalmonitorlistener.h"
18 #include "signalmonitorvalue.h"
19 #include "channelbase.h"
20 #include "mythtimer.h"
21 #include "cardutil.h"
22 #include "mthread.h"
23 
24 #define DBG_SM(FUNC, MSG) LOG(VB_CHANNEL, LOG_DEBUG, \
25  QString("SM(%1)::%2: %3") .arg(channel->GetDevice()).arg(FUNC).arg(<(MSG)));
26 
27 inline QString sm_flags_to_string(uint64_t flags);
28 
29 class TVRec;
30 
31 class SignalMonitor : protected MThread
32 {
34 
35  public:
37  static inline bool IsRequired(const QString &cardtype);
38  static inline bool IsSupported(const QString &cardtype);
39  static SignalMonitor *Init(const QString& cardtype, int db_cardnum,
41  bool release_stream);
42  ~SignalMonitor() override;
43 
44  // Prevent implicit conversion of wrongly ordered arguments
45  SignalMonitor(int, ChannelBase *, uint64_t, bool) = delete;
46 
47  // // // // // // // // // // // // // // // // // // // // // // // //
48  // Control // // // // // // // // // // // // // // // // // // // //
49 
50  virtual void Start();
51  virtual void Stop();
52 
53  // // // // // // // // // // // // // // // // // // // // // // // //
54  // Flags // // // // // // // // // // // // // // // // // // // // //
55 
56  virtual void AddFlags(uint64_t _flags);
57  virtual void RemoveFlags(uint64_t _flags);
58  bool HasFlags(uint64_t _flags) const;
59  bool HasAnyFlag(uint64_t _flags) const;
60  uint64_t GetFlags(void) const { return m_flags; }
61  virtual bool HasExtraSlowTuning(void) const { return false; }
62 
63  // // // // // // // // // // // // // // // // // // // // // // // //
64  // Gets // // // // // // // // // // // // // // // // // // // // //
65 
68  bool GetNotifyFrontend() const { return m_notifyFrontend; }
70  std::chrono::milliseconds GetUpdateRate() const { return m_updateRate; }
71  virtual QStringList GetStatusList(void) const;
73 
76  bool HasSignalLock(void) const
77  {
78  QMutexLocker locker(&m_statusLock);
80  }
81 
82  virtual bool IsAllGood(void) const { return HasSignalLock(); }
83  bool IsErrored(void) const { return !m_error.isEmpty(); }
84 
85  // // // // // // // // // // // // // // // // // // // // // // // //
86  // Sets // // // // // // // // // // // // // // // // // // // // //
87 
93  void SetNotifyFrontend(bool notify) { m_notifyFrontend = notify; }
94 
101  void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
102  { m_pParent = parent; m_eitScan = EITscan, m_tablemon = monitor; }
103 
110  void SetUpdateRate(std::chrono::milliseconds msec)
111  { m_updateRate = std::max(msec, m_minimumUpdateRate); }
112 
113  // // // // // // // // // // // // // // // // // // // // // // // //
114  // Listeners // // // // // // // // // // // // // // // // // // //
115  void AddListener(SignalMonitorListener *listener);
116  void RemoveListener(SignalMonitorListener *listener);
118  const SignalMonitorValue &val);
119  void SendMessageAllGood(void);
120  virtual void EmitStatus(void);
121 
122  protected:
123  SignalMonitor(int _inputid, ChannelBase *_channel,
124  bool _release_stream, uint64_t wait_for_mask);
125 
126  void run(void) override; // MThread
127 
129  virtual void UpdateValues(void);
130 
131  public:
134  static const uint64_t kDTVSigMon_PATSeen = 0x0000000001ULL;
137  static const uint64_t kDTVSigMon_PMTSeen = 0x0000000002ULL;
140  static const uint64_t kDTVSigMon_MGTSeen = 0x0000000004ULL;
143  static const uint64_t kDTVSigMon_VCTSeen = 0x0000000008ULL;
145  static const uint64_t kDTVSigMon_TVCTSeen = 0x0000000010ULL;
147  static const uint64_t kDTVSigMon_CVCTSeen = 0x0000000020ULL;
150  static const uint64_t kDTVSigMon_NITSeen = 0x0000000040ULL;
153  static const uint64_t kDTVSigMon_SDTSeen = 0x0000000080ULL;
155  static const uint64_t kFWSigMon_PowerSeen = 0x0000000100ULL;
157  static const uint64_t kDTVSigMon_CryptSeen = 0x0000000200ULL;
158 
160  static const uint64_t kDTVSigMon_PATMatch = 0x0000001000ULL;
162  static const uint64_t kDTVSigMon_PMTMatch = 0x0000002000ULL;
164  static const uint64_t kDTVSigMon_MGTMatch = 0x0000004000ULL;
166  static const uint64_t kDTVSigMon_VCTMatch = 0x0000008000ULL;
168  static const uint64_t kDTVSigMon_TVCTMatch = 0x0000010000ULL;
170  static const uint64_t kDTVSigMon_CVCTMatch = 0x0000020000ULL;
172  static const uint64_t kDTVSigMon_NITMatch = 0x0000040000ULL;
174  static const uint64_t kDTVSigMon_SDTMatch = 0x0000080000ULL;
176  static const uint64_t kFWSigMon_PowerMatch = 0x0000100000ULL;
178  static const uint64_t kDTVSigMon_CryptMatch = 0x0000200000ULL;
179 
180  static const uint64_t kDTVSigMon_WaitForPAT = 0x0001000000ULL;
181  static const uint64_t kDTVSigMon_WaitForPMT = 0x0002000000ULL;
182  static const uint64_t kDTVSigMon_WaitForMGT = 0x0004000000ULL;
183  static const uint64_t kDTVSigMon_WaitForVCT = 0x0008000000ULL;
184  static const uint64_t kDTVSigMon_WaitForNIT = 0x0010000000ULL;
185  static const uint64_t kDTVSigMon_WaitForSDT = 0x0020000000ULL;
186  static const uint64_t kSigMon_WaitForSig = 0x0040000000ULL;
187  static const uint64_t kFWSigMon_WaitForPower= 0x0080000000ULL;
188  static const uint64_t kDTVSigMon_WaitForCrypt=0x0100000000ULL;
189 
190  static const uint64_t kDTVSigMon_WaitForAll = 0x01FF000000ULL;
191 
193  static const uint64_t kDVBSigMon_WaitForSNR = 0x1000000000ULL;
195  static const uint64_t kDVBSigMon_WaitForBER = 0x2000000000ULL;
197  static const uint64_t kDVBSigMon_WaitForUB = 0x4000000000ULL;
199  static const uint64_t kDVBSigMon_WaitForPos = 0x8000000000ULL;
200 
201  protected:
202  ChannelBase *m_channel {nullptr};
203  TVRec *m_pParent {nullptr};
205  volatile uint64_t m_flags;
207  std::chrono::milliseconds m_updateRate {25ms};
208  std::chrono::milliseconds m_minimumUpdateRate {5ms};
209  bool m_updateDone {false};
210  bool m_notifyFrontend {true};
211  bool m_tablemon {false};
212  bool m_eitScan {false};
213 
214  // not to be confused with StreamHandler::m_bError.
215  QString m_error;
216 
220 
221  std::vector<SignalMonitorListener*> m_listeners;
222 
224  QWaitCondition m_startStopWait; // protected by startStopLock
225  volatile bool m_running {false}; // protected by startStopLock
226  volatile bool m_exit {false}; // protected by startStopLock
227 
228  mutable QMutex m_statusLock {QMutex::Recursive};
229  mutable QMutex m_listenerLock;
230 };
231 
232 inline QString sm_flags_to_string(uint64_t flags)
233 {
234  QString str("Seen(");
236  str += "PAT,";
238  str += "PMT,";
240  str += "MGT,";
242  str += "VCT,";
244  str += "TVCT,";
246  str += "CVCT,";
248  str += "NIT,";
250  str += "SDT,";
252  str += "STB,";
254  str += "Crypt,";
255 
256  str += ") Match(";
258  str += "PAT,";
260  str += "PMT,";
262  str += "MGT,";
264  str += "VCT,";
266  str += "TVCT,";
268  str += "CVCT,";
270  str += "NIT,";
272  str += "SDT,";
274  str += "STB,";
276  str += "Crypt,";
277 
278  str += ") Wait(";
280  str += "PAT,";
282  str += "PMT,";
284  str += "MGT,";
286  str += "VCT,";
288  str += "NIT,";
290  str += "SDT,";
292  str += "Sig,";
294  str += "STB,";
296  str += "Crypt,";
297 
299  str += "SNR,";
301  str += "BER,";
303  str += "UB,";
305  str += "Pos,";
306 
307  str += ")";
308  return str;
309 }
310 
311 inline bool SignalMonitor::IsRequired(const QString &cardtype)
312 {
313  return (cardtype != "IMPORT" && cardtype != "DEMO");
314 }
315 
316 inline bool SignalMonitor::IsSupported(const QString &cardtype)
317 {
318  return IsRequired(cardtype);
319 }
320 
321 
322 #endif // SIGNALMONITOR_H
channel
QDomElement channel
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:501
SignalMonitor::m_flags
volatile uint64_t m_flags
Definition: signalmonitor.h:205
SignalMonitor::kDTVSigMon_WaitForAll
static const uint64_t kDTVSigMon_WaitForAll
Definition: signalmonitor.h:190
SignalMonitor::m_minimumUpdateRate
std::chrono::milliseconds m_minimumUpdateRate
Definition: signalmonitor.h:208
SignalMonitor::kFWSigMon_WaitForPower
static const uint64_t kFWSigMon_WaitForPower
Definition: signalmonitor.h:187
SignalMonitor::IsAllGood
virtual bool IsAllGood(void) const
Definition: signalmonitor.h:82
SignalMonitor::kDTVSigMon_NITMatch
static const uint64_t kDTVSigMon_NITMatch
We've seen an NIT matching our requirements.
Definition: signalmonitor.h:172
SignalMonitor::IsSupported
static bool IsSupported(const QString &cardtype)
Definition: signalmonitor.h:316
SignalMonitor::kDTVSigMon_VCTMatch
static const uint64_t kDTVSigMon_VCTMatch
We've seen a VCT matching our requirements.
Definition: signalmonitor.h:166
SignalMonitor::m_channel
ChannelBase * m_channel
Definition: signalmonitor.h:202
SignalMonitorValue::GetNormalizedValue
int GetNormalizedValue(int newmin, int newmax) const
Returns the value normalized to the [newmin, newmax] range.
Definition: signalmonitorvalue.h:63
SignalMonitor::kDTVSigMon_WaitForMGT
static const uint64_t kDTVSigMon_WaitForMGT
Definition: signalmonitor.h:182
SignalMonitor::kDVBSigMon_WaitForSNR
static const uint64_t kDVBSigMon_WaitForSNR
Wait for the Signal to Noise Ratio to rise above a threshold.
Definition: signalmonitor.h:193
SignalMonitor::SendMessage
void SendMessage(SignalMonitorMessageType type, const SignalMonitorValue &val)
Definition: signalmonitor.cpp:412
SignalMonitor::m_exit
volatile bool m_exit
Definition: signalmonitor.h:226
SignalMonitor::kDTVSigMon_CVCTSeen
static const uint64_t kDTVSigMon_CVCTSeen
We've seen a CVCT, the cable version of the VCT.
Definition: signalmonitor.h:147
SignalMonitor::GetSignalStrength
int GetSignalStrength(void)
Definition: signalmonitor.h:72
signalmonitorvalue.h
SignalMonitor::GetUpdateRate
std::chrono::milliseconds GetUpdateRate() const
Returns milliseconds between signal monitoring events.
Definition: signalmonitor.h:70
SignalMonitor::kDTVSigMon_SDTMatch
static const uint64_t kDTVSigMon_SDTMatch
We've seen an SDT matching our requirements.
Definition: signalmonitor.h:174
channelbase.h
SignalMonitor::m_running
volatile bool m_running
Definition: signalmonitor.h:225
SignalMonitor::kDVBSigMon_WaitForBER
static const uint64_t kDVBSigMon_WaitForBER
Wait for the Bit Error Rate to fall below a threshold.
Definition: signalmonitor.h:195
SignalMonitorListener
Definition: signalmonitorlistener.h:21
SignalMonitor::kDTVSigMon_PMTMatch
static const uint64_t kDTVSigMon_PMTMatch
We've seen a PMT matching our requirements.
Definition: signalmonitor.h:162
SignalMonitor::HasAnyFlag
bool HasAnyFlag(uint64_t _flags) const
Definition: signalmonitor.cpp:282
SignalMonitor::AddFlags
virtual void AddFlags(uint64_t _flags)
Definition: signalmonitor.cpp:265
SignalMonitor::kSigMon_WaitForSig
static const uint64_t kSigMon_WaitForSig
Definition: signalmonitor.h:186
SignalMonitor::m_error
QString m_error
Definition: signalmonitor.h:215
SignalMonitor::m_startStopLock
QMutex m_startStopLock
Definition: signalmonitor.h:223
SignalMonitor::m_scriptStatus
SignalMonitorValue m_scriptStatus
Definition: signalmonitor.h:219
SignalMonitor::IsRequired
static bool IsRequired(const QString &cardtype)
Returns true iff the card type supports signal monitoring.
Definition: signalmonitor.h:311
SignalMonitor::kDVBSigMon_WaitForUB
static const uint64_t kDVBSigMon_WaitForUB
Wait for uncorrected FEC blocks to fall below a threshold.
Definition: signalmonitor.h:197
SignalMonitor::RemoveFlags
virtual void RemoveFlags(uint64_t _flags)
Definition: signalmonitor.cpp:271
SignalMonitor::m_signalStrength
SignalMonitorValue m_signalStrength
Definition: signalmonitor.h:218
SignalMonitor::m_inputid
int m_inputid
Definition: signalmonitor.h:204
SignalMonitor::kDVBSigMon_WaitForPos
static const uint64_t kDVBSigMon_WaitForPos
Wait for rotor to complete turning the antenna.
Definition: signalmonitor.h:199
signalmonitorlistener.h
ChannelBase
Abstract class providing a generic interface to tuning hardware.
Definition: channelbase.h:31
SignalMonitor::m_notifyFrontend
bool m_notifyFrontend
Definition: signalmonitor.h:210
SignalMonitor::kFWSigMon_PowerSeen
static const uint64_t kFWSigMon_PowerSeen
We've seen the FireWire STB power state.
Definition: signalmonitor.h:155
sm_flags_to_string
QString sm_flags_to_string(uint64_t flags)
Definition: signalmonitor.h:232
SignalMonitor::m_releaseStream
bool m_releaseStream
Definition: signalmonitor.h:206
SignalMonitor::m_signalLock
SignalMonitorValue m_signalLock
Definition: signalmonitor.h:217
SignalMonitor::m_updateRate
std::chrono::milliseconds m_updateRate
Definition: signalmonitor.h:207
SignalMonitor::run
void run(void) override
Basic signal monitoring loop.
Definition: signalmonitor.cpp:344
SignalMonitor::SendMessageAllGood
void SendMessageAllGood(void)
Definition: signalmonitor.cpp:467
SignalMonitor::kDTVSigMon_CVCTMatch
static const uint64_t kDTVSigMon_CVCTMatch
We've seen a CVCT matching our requirements.
Definition: signalmonitor.h:170
SignalMonitor::~SignalMonitor
~SignalMonitor() override
Stops monitoring thread.
Definition: signalmonitor.cpp:259
SignalMonitor::kDTVSigMon_WaitForPMT
static const uint64_t kDTVSigMon_WaitForPMT
Definition: signalmonitor.h:181
SignalMonitor::kDTVSigMon_WaitForPAT
static const uint64_t kDTVSigMon_WaitForPAT
Definition: signalmonitor.h:180
SignalMonitor::m_updateDone
bool m_updateDone
Definition: signalmonitor.h:209
SignalMonitor::kDTVSigMon_WaitForNIT
static const uint64_t kDTVSigMon_WaitForNIT
Definition: signalmonitor.h:184
SignalMonitor::EmitStatus
virtual void EmitStatus(void)
Definition: signalmonitor.cpp:474
SignalMonitor::kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_WaitForSDT
Definition: signalmonitor.h:185
SignalMonitor::UpdateValues
virtual void UpdateValues(void)
This should be overridden to actually do signal monitoring.
Definition: signalmonitor.cpp:458
SignalMonitor::kDTVSigMon_SDTSeen
static const uint64_t kDTVSigMon_SDTSeen
We've seen a SDT, which maps DVB Channels to MPEG program numbers, and provides additional data.
Definition: signalmonitor.h:153
SignalMonitor::kFWSigMon_PowerMatch
static const uint64_t kFWSigMon_PowerMatch
We've seen a FireWire STB power state matching our requirements.
Definition: signalmonitor.h:176
SignalMonitor::kDTVSigMon_NITSeen
static const uint64_t kDTVSigMon_NITSeen
We've seen a NIT, which tells us where to find SDT and other DVB tables.
Definition: signalmonitor.h:150
SignalMonitorValue
Definition: signalmonitorvalue.h:13
SignalMonitor::kDTVSigMon_TVCTSeen
static const uint64_t kDTVSigMon_TVCTSeen
We've seen a TVCT, the terrestrial version of the VCT.
Definition: signalmonitor.h:145
SignalMonitor::kDTVSigMon_PATSeen
static const uint64_t kDTVSigMon_PATSeen
We've seen a PAT, which maps MPEG program numbers to pids where we find PMTs.
Definition: signalmonitor.h:134
SignalMonitor::kDTVSigMon_PMTSeen
static const uint64_t kDTVSigMon_PMTSeen
We've seen a PMT, which maps program to audio, video and other stream PIDs.
Definition: signalmonitor.h:137
SignalMonitor::m_startStopWait
QWaitCondition m_startStopWait
Definition: signalmonitor.h:224
SignalMonitor
Signal monitoring base class.
Definition: signalmonitor.h:31
SignalMonitorValue::IsGood
bool IsGood() const
Returns true if the value is equal to the threshold, or on the right side of the threshold (depends o...
Definition: signalmonitorvalue.h:56
SignalMonitor::Init
static SignalMonitor * Init(const QString &cardtype, int db_cardnum, ChannelBase *channel, bool release_stream)
Definition: signalmonitor.cpp:90
SignalMonitor::kDTVSigMon_VCTSeen
static const uint64_t kDTVSigMon_VCTSeen
We've seen a VCT, which maps ATSC Channels to MPEG program numbers, and provides additional data.
Definition: signalmonitor.h:143
SignalMonitor::HasExtraSlowTuning
virtual bool HasExtraSlowTuning(void) const
Definition: signalmonitor.h:61
SignalMonitor::kDTVSigMon_CryptSeen
static const uint64_t kDTVSigMon_CryptSeen
We've seen something indicating whether the data stream is encrypted.
Definition: signalmonitor.h:157
SignalMonitor::SetUpdateRate
void SetUpdateRate(std::chrono::milliseconds msec)
Sets the number of milliseconds between signal monitoring attempts in the signal monitoring thread.
Definition: signalmonitor.h:110
SignalMonitor::kDTVSigMon_MGTMatch
static const uint64_t kDTVSigMon_MGTMatch
We've seen an MGT matching our requirements.
Definition: signalmonitor.h:164
SignalMonitor::GetNotifyFrontend
bool GetNotifyFrontend() const
Returns whether or not a SIGNAL MythEvent is being sent regularly to the frontend.
Definition: signalmonitor.h:68
SignalMonitor::HasFlags
bool HasFlags(uint64_t _flags) const
Definition: signalmonitor.cpp:277
SignalMonitor::AddListener
void AddListener(SignalMonitorListener *listener)
Definition: signalmonitor.cpp:387
SignalMonitor::m_eitScan
bool m_eitScan
Definition: signalmonitor.h:212
SignalMonitor::kDTVSigMon_MGTSeen
static const uint64_t kDTVSigMon_MGTSeen
We've seen a MGT, which tells us on which PIDs to find VCT and other ATSC tables.
Definition: signalmonitor.h:140
SignalMonitor::SetMonitoring
void SetMonitoring(TVRec *parent, bool EITscan, bool monitor)
Indicate if table monitoring is needed.
Definition: signalmonitor.h:101
cardutil.h
SignalMonitor::RemoveListener
void RemoveListener(SignalMonitorListener *listener)
Definition: signalmonitor.cpp:398
SignalMonitorMessageType
SignalMonitorMessageType
Definition: signalmonitorlistener.h:10
SignalMonitor::m_statusLock
QMutex m_statusLock
Definition: signalmonitor.h:228
SignalMonitor::kDTVSigMon_PATMatch
static const uint64_t kDTVSigMon_PATMatch
We've seen a PAT matching our requirements.
Definition: signalmonitor.h:160
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
mthread.h
SignalMonitor::kDTVSigMon_TVCTMatch
static const uint64_t kDTVSigMon_TVCTMatch
We've seen a TVCT matching our requirements.
Definition: signalmonitor.h:168
SignalMonitor::Start
virtual void Start()
Start signal monitoring thread.
Definition: signalmonitor.cpp:290
SignalMonitor::m_tablemon
bool m_tablemon
Definition: signalmonitor.h:211
SignalMonitor::SetNotifyFrontend
void SetNotifyFrontend(bool notify)
Enables or disables frontend notification of the current signal value.
Definition: signalmonitor.h:93
mythtimer.h
SignalMonitor::m_listeners
std::vector< SignalMonitorListener * > m_listeners
Definition: signalmonitor.h:221
SignalMonitor::GetStatusList
virtual QStringList GetStatusList(void) const
Returns QStringList containing all signals and their current values.
Definition: signalmonitor.cpp:330
SignalMonitor::IsErrored
bool IsErrored(void) const
Definition: signalmonitor.h:83
SignalMonitor::m_listenerLock
QMutex m_listenerLock
Definition: signalmonitor.h:229
SignalMonitor::GetFlags
uint64_t GetFlags(void) const
Definition: signalmonitor.h:60
SignalMonitor::HasSignalLock
bool HasSignalLock(void) const
Returns true iff scriptStatus.IsGood() and signalLock.IsGood() return true.
Definition: signalmonitor.h:76
SignalMonitor::kDTVSigMon_CryptMatch
static const uint64_t kDTVSigMon_CryptMatch
We've seen unencrypted data in data stream.
Definition: signalmonitor.h:178
SignalMonitor::Stop
virtual void Stop()
Stop signal monitoring thread.
Definition: signalmonitor.cpp:306
SignalMonitor::m_pParent
TVRec * m_pParent
Definition: signalmonitor.h:203
SignalMonitor::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(SignalMonitor)
SignalMonitor::kDTVSigMon_WaitForCrypt
static const uint64_t kDTVSigMon_WaitForCrypt
Definition: signalmonitor.h:188
SignalMonitor::SignalMonitor
SignalMonitor(int, ChannelBase *, uint64_t, bool)=delete
SignalMonitor::kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForVCT
Definition: signalmonitor.h:183