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,
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  int GetSignalStrength(void) { return m_signalStrength.GetNormalizedValue(0,100); }
74 
77  bool HasSignalLock(void) const
78  {
79  QMutexLocker locker(&m_statusLock);
80  return m_scriptStatus.IsGood() && m_signalLock.IsGood();
81  }
82 
83  virtual bool IsAllGood(void) const { return HasSignalLock(); }
84  bool IsErrored(void) const { return !m_error.isEmpty(); }
85 
86  // // // // // // // // // // // // // // // // // // // // // // // //
87  // Sets // // // // // // // // // // // // // // // // // // // // //
88 
94  void SetNotifyFrontend(bool notify) { m_notify_frontend = notify; }
95 
102  void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
103  { m_pParent = parent; m_eit_scan = EITscan, m_tablemon = monitor; }
104 
111  void SetUpdateRate(int msec)
112  { m_update_rate = max(msec, (int)m_minimum_update_rate); }
113 
114  // // // // // // // // // // // // // // // // // // // // // // // //
115  // Listeners // // // // // // // // // // // // // // // // // // //
116  void AddListener(SignalMonitorListener *listener);
117  void RemoveListener(SignalMonitorListener *listener);
119  const SignalMonitorValue &val);
120  void SendMessageAllGood(void);
121  virtual void EmitStatus(void);
122 
123  protected:
124  SignalMonitor(int _inputid, ChannelBase *_channel,
125  bool _release_stream, uint64_t wait_for_mask);
126 
127  void run(void) override; // MThread
128 
130  virtual void UpdateValues(void);
131 
132  public:
135  static const uint64_t kDTVSigMon_PATSeen = 0x0000000001ULL;
138  static const uint64_t kDTVSigMon_PMTSeen = 0x0000000002ULL;
141  static const uint64_t kDTVSigMon_MGTSeen = 0x0000000004ULL;
144  static const uint64_t kDTVSigMon_VCTSeen = 0x0000000008ULL;
146  static const uint64_t kDTVSigMon_TVCTSeen = 0x0000000010ULL;
148  static const uint64_t kDTVSigMon_CVCTSeen = 0x0000000020ULL;
151  static const uint64_t kDTVSigMon_NITSeen = 0x0000000040ULL;
154  static const uint64_t kDTVSigMon_SDTSeen = 0x0000000080ULL;
156  static const uint64_t kFWSigMon_PowerSeen = 0x0000000100ULL;
158  static const uint64_t kDTVSigMon_CryptSeen = 0x0000000200ULL;
159 
161  static const uint64_t kDTVSigMon_PATMatch = 0x0000001000ULL;
163  static const uint64_t kDTVSigMon_PMTMatch = 0x0000002000ULL;
165  static const uint64_t kDTVSigMon_MGTMatch = 0x0000004000ULL;
167  static const uint64_t kDTVSigMon_VCTMatch = 0x0000008000ULL;
169  static const uint64_t kDTVSigMon_TVCTMatch = 0x0000010000ULL;
171  static const uint64_t kDTVSigMon_CVCTMatch = 0x0000020000ULL;
173  static const uint64_t kDTVSigMon_NITMatch = 0x0000040000ULL;
175  static const uint64_t kDTVSigMon_SDTMatch = 0x0000080000ULL;
177  static const uint64_t kFWSigMon_PowerMatch = 0x0000100000ULL;
179  static const uint64_t kDTVSigMon_CryptMatch = 0x0000200000ULL;
180 
181  static const uint64_t kDTVSigMon_WaitForPAT = 0x0001000000ULL;
182  static const uint64_t kDTVSigMon_WaitForPMT = 0x0002000000ULL;
183  static const uint64_t kDTVSigMon_WaitForMGT = 0x0004000000ULL;
184  static const uint64_t kDTVSigMon_WaitForVCT = 0x0008000000ULL;
185  static const uint64_t kDTVSigMon_WaitForNIT = 0x0010000000ULL;
186  static const uint64_t kDTVSigMon_WaitForSDT = 0x0020000000ULL;
187  static const uint64_t kSigMon_WaitForSig = 0x0040000000ULL;
188  static const uint64_t kFWSigMon_WaitForPower= 0x0080000000ULL;
189  static const uint64_t kDTVSigMon_WaitForCrypt=0x0100000000ULL;
190 
191  static const uint64_t kDTVSigMon_WaitForAll = 0x01FF000000ULL;
192 
194  static const uint64_t kDVBSigMon_WaitForSNR = 0x1000000000ULL;
196  static const uint64_t kDVBSigMon_WaitForBER = 0x2000000000ULL;
198  static const uint64_t kDVBSigMon_WaitForUB = 0x4000000000ULL;
200  static const uint64_t kDVBSigMon_WaitForPos = 0x8000000000ULL;
201 
202  protected:
203  ChannelBase *m_channel {nullptr};
204  TVRec *m_pParent {nullptr};
206  volatile uint64_t m_flags;
208  int m_update_rate {25};
209  uint m_minimum_update_rate {5};
210  bool m_update_done {false};
211  bool m_notify_frontend {true};
212  bool m_tablemon {false};
213  bool m_eit_scan {false};
214 
215  // not to be confused with StreamHandler::m_bError.
216  QString m_error;
217 
221 
222  vector<SignalMonitorListener*> m_listeners;
223 
225  QWaitCondition m_startStopWait; // protected by startStopLock
226  volatile bool m_running {false}; // protected by startStopLock
227  volatile bool m_exit {false}; // protected by startStopLock
228 
229  mutable QMutex m_statusLock {QMutex::Recursive};
230  mutable QMutex m_listenerLock;
231 };
232 
233 inline QString sm_flags_to_string(uint64_t flags)
234 {
235  QString str("Seen(");
237  str += "PAT,";
239  str += "PMT,";
241  str += "MGT,";
243  str += "VCT,";
245  str += "TVCT,";
247  str += "CVCT,";
249  str += "NIT,";
251  str += "SDT,";
253  str += "STB,";
255  str += "Crypt,";
256 
257  str += ") Match(";
259  str += "PAT,";
261  str += "PMT,";
263  str += "MGT,";
265  str += "VCT,";
267  str += "TVCT,";
269  str += "CVCT,";
271  str += "NIT,";
273  str += "SDT,";
275  str += "STB,";
277  str += "Crypt,";
278 
279  str += ") Wait(";
281  str += "PAT,";
283  str += "PMT,";
285  str += "MGT,";
287  str += "VCT,";
289  str += "NIT,";
291  str += "SDT,";
293  str += "Sig,";
295  str += "STB,";
297  str += "Crypt,";
298 
300  str += "SNR,";
302  str += "BER,";
304  str += "UB,";
306  str += "Pos,";
307 
308  str += ")";
309  return str;
310 }
311 
312 inline bool SignalMonitor::IsRequired(const QString &cardtype)
313 {
314  return (cardtype != "IMPORT" && cardtype != "DEMO");
315 }
316 
317 inline bool SignalMonitor::IsSupported(const QString &cardtype)
318 {
319  return IsRequired(cardtype);
320 }
321 
322 
323 #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:94
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:77
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
int GetSignalStrength(void)
Definition: signalmonitor.h:73
static const uint64_t kDTVSigMon_CryptSeen
We've seen something indicating whether the data stream is encrypted.
bool IsErrored(void) const
Definition: signalmonitor.h:84
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:83
static const uint64_t kDTVSigMon_PMTMatch
We've seen a PMT matching our requirements.