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 using namespace std;
11 
12 // Qt headers
13 #include <QWaitCondition>
14 #include <QMutex>
15 #include <QCoreApplication>
16 
17 // MythTV headers
18 #include "signalmonitorlistener.h"
19 #include "signalmonitorvalue.h"
20 #include "channelbase.h"
21 #include "mythtimer.h"
22 #include "cardutil.h"
23 #include "mthread.h"
24 
25 #define DBG_SM(FUNC, MSG) LOG(VB_CHANNEL, LOG_DEBUG, \
26  QString("SM(%1)::%2: %3") .arg(channel->GetDevice()).arg(FUNC).arg(<(MSG)));
27 
28 inline QString sm_flags_to_string(uint64_t flags);
29 
30 class TVRec;
31 
32 class SignalMonitor : protected MThread
33 {
34  Q_DECLARE_TR_FUNCTIONS(SignalMonitor);
35 
36  public:
38  static inline bool IsRequired(const QString &cardtype);
39  static inline bool IsSupported(const QString &cardtype);
40  static SignalMonitor *Init(const QString& cardtype, int db_cardnum,
41  ChannelBase *channel,
42  bool release_stream);
43  ~SignalMonitor() override;
44 
45  // Prevent implicit conversion of wrongly ordered arguments
46  SignalMonitor(int, ChannelBase *, uint64_t, bool) = delete;
47 
48  // // // // // // // // // // // // // // // // // // // // // // // //
49  // Control // // // // // // // // // // // // // // // // // // // //
50 
51  virtual void Start();
52  virtual void Stop();
53 
54  // // // // // // // // // // // // // // // // // // // // // // // //
55  // Flags // // // // // // // // // // // // // // // // // // // // //
56 
57  virtual void AddFlags(uint64_t _flags);
58  virtual void RemoveFlags(uint64_t _flags);
59  bool HasFlags(uint64_t _flags) const;
60  bool HasAnyFlag(uint64_t _flags) const;
61  uint64_t GetFlags(void) const { return m_flags; }
62  virtual bool HasExtraSlowTuning(void) const { return false; }
63 
64  // // // // // // // // // // // // // // // // // // // // // // // //
65  // Gets // // // // // // // // // // // // // // // // // // // // //
66 
69  bool GetNotifyFrontend() const { return m_notify_frontend; }
71  int GetUpdateRate() const { return m_update_rate; }
72  virtual QStringList GetStatusList(void) const;
73 
76  bool HasSignalLock(void) const
77  {
78  QMutexLocker locker(&m_statusLock);
79  return m_scriptStatus.IsGood() && m_signalLock.IsGood();
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_notify_frontend = notify; }
94 
101  void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
102  { m_pParent = parent; m_eit_scan = EITscan, m_tablemon = monitor; }
103 
110  void SetUpdateRate(int msec)
111  { m_update_rate = max(msec, (int)m_minimum_update_rate); }
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  int m_update_rate {25};
208  uint m_minimum_update_rate {5};
209  bool m_update_done {false};
210  bool m_notify_frontend {true};
211  bool m_tablemon {false};
212  bool m_eit_scan {false};
213 
214  // not to be confused with StreamHandler::m_bError.
215  QString m_error;
216 
220 
221  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
static const uint64_t kDTVSigMon_SDTSeen
We've seen a SDT, which maps DVB Channels to MPEG program numbers, and provides additional data.
void SetMonitoring(TVRec *parent, bool EITscan, bool monitor)
Indicate if table monitoring is needed.
SignalMonitorValue m_scriptStatus
static const uint64_t kDTVSigMon_MGTSeen
We've seen a MGT, which tells us on which PIDs to find VCT and other ATSC tables.
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
static const uint64_t kDTVSigMon_PATSeen
We've seen a PAT, which maps MPEG program numbers to pids where we find PMTs.
static const uint64_t kDVBSigMon_WaitForPos
Wait for rotor to complete turning the antenna.
void SetNotifyFrontend(bool notify)
Enables or disables frontend notification of the current signal value.
Definition: signalmonitor.h:93
static const uint64_t kDTVSigMon_VCTSeen
We've seen a VCT, which maps ATSC Channels to MPEG program numbers, and provides additional data.
static const uint64_t kDTVSigMon_WaitForPMT
static const uint64_t kDVBSigMon_WaitForBER
Wait for the Bit Error Rate to fall below a threshold.
bool GetNotifyFrontend() const
Returns whether or not a SIGNAL MythEvent is being sent regularly to the frontend.
Definition: signalmonitor.h:69
static const uint64_t kDTVSigMon_WaitForPAT
bool HasSignalLock(void) const
Returns true iff scriptStatus.IsGood() and signalLock.IsGood() return true.
Definition: signalmonitor.h:76
static int SendMessage(const MythUtilCommandLineParser &cmdline)
static const uint64_t kDTVSigMon_CryptMatch
We've seen unencrypted data in data stream.
static const uint64_t kFWSigMon_PowerMatch
We've seen a FireWire STB power state matching our requirements.
static const uint64_t kDTVSigMon_PMTSeen
We've seen a PMT, which maps program to audio, video and other stream PIDs.
static const uint64_t kDTVSigMon_TVCTSeen
We've seen a TVCT, the terrestrial version of the VCT.
static const uint64_t kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForMGT
static const uint64_t kDTVSigMon_CryptSeen
We've seen something indicating whether the data stream is encrypted.
bool IsErrored(void) const
Definition: signalmonitor.h:83
static const uint64_t kDTVSigMon_WaitForNIT
static const uint64_t kSigMon_WaitForSig
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
QWaitCondition m_startStopWait
static bool IsRequired(const QString &cardtype)
Returns true iff the card type supports signal monitoring.
static const uint64_t kDTVSigMon_CVCTSeen
We've seen a CVCT, the cable version of the VCT.
static const uint64_t kDTVSigMon_SDTMatch
We've seen an SDT matching our requirements.
static const uint64_t kFWSigMon_PowerSeen
We've seen the FireWire STB power state.
unsigned int uint
Definition: compat.h:140
uint64_t GetFlags(void) const
Definition: signalmonitor.h:61
static const uint64_t kDTVSigMon_VCTMatch
We've seen a VCT matching our requirements.
QMutex m_startStopLock
static const uint64_t kDTVSigMon_PATMatch
We've seen a PAT matching our requirements.
static const uint64_t kDTVSigMon_NITSeen
We've seen a NIT, which tells us where to find SDT and other DVB tables.
QString sm_flags_to_string(uint64_t flags)
Signal monitoring base class.
Definition: signalmonitor.h:32
Abstract class providing a generic interface to tuning hardware.
Definition: channelbase.h:31
SignalMonitorValue m_signalStrength
volatile uint64_t m_flags
SignalMonitorMessageType
static const uint64_t kDTVSigMon_CVCTMatch
We've seen a CVCT matching our requirements.
static const uint64_t kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_MGTMatch
We've seen an MGT matching our requirements.
static const uint64_t kFWSigMon_WaitForPower
void SetUpdateRate(int msec)
Sets the number of milliseconds between signal monitoring attempts in the signal monitoring thread.
static const uint64_t kDTVSigMon_NITMatch
We've seen an NIT matching our requirements.
static bool IsSupported(const QString &cardtype)
static const uint64_t kDTVSigMon_WaitForCrypt
vector< SignalMonitorListener * > m_listeners
static const uint64_t kDVBSigMon_WaitForUB
Wait for uncorrected FEC blocks to fall below a threshold.
static const uint64_t kDVBSigMon_WaitForSNR
Wait for the Signal to Noise Ratio to rise above a threshold.
static const uint64_t kDTVSigMon_TVCTMatch
We've seen a TVCT matching our requirements.
SignalMonitorValue m_signalLock
virtual bool HasExtraSlowTuning(void) const
Definition: signalmonitor.h:62
int GetUpdateRate() const
Returns milliseconds between signal monitoring events.
Definition: signalmonitor.h:71
QMutex m_listenerLock
virtual bool IsAllGood(void) const
Definition: signalmonitor.h:82
static const uint64_t kDTVSigMon_PMTMatch
We've seen a PMT matching our requirements.