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);
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  virtual ~SignalMonitor();
44 
45  // // // // // // // // // // // // // // // // // // // // // // // //
46  // Control // // // // // // // // // // // // // // // // // // // //
47 
48  virtual void Start();
49  virtual void Stop();
50 
51  // // // // // // // // // // // // // // // // // // // // // // // //
52  // Flags // // // // // // // // // // // // // // // // // // // // //
53 
54  virtual void AddFlags(uint64_t _flags);
55  virtual void RemoveFlags(uint64_t _flags);
56  bool HasFlags(uint64_t _flags) const;
57  bool HasAnyFlag(uint64_t _flags) const;
58  uint64_t GetFlags(void) const { return m_flags; }
59  virtual bool HasExtraSlowTuning(void) const { return false; }
60 
61  // // // // // // // // // // // // // // // // // // // // // // // //
62  // Gets // // // // // // // // // // // // // // // // // // // // //
63 
66  bool GetNotifyFrontend() const { return m_notify_frontend; }
68  int GetUpdateRate() const { return m_update_rate; }
69  virtual QStringList GetStatusList(void) const;
70 
73  bool HasSignalLock(void) const
74  {
75  QMutexLocker locker(&m_statusLock);
76  return m_scriptStatus.IsGood() && m_signalLock.IsGood();
77  }
78 
79  virtual bool IsAllGood(void) const { return HasSignalLock(); }
80  bool IsErrored(void) const { return !m_error.isEmpty(); }
81 
82  // // // // // // // // // // // // // // // // // // // // // // // //
83  // Sets // // // // // // // // // // // // // // // // // // // // //
84 
90  void SetNotifyFrontend(bool notify) { m_notify_frontend = notify; }
91 
98  void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
99  { m_pParent = parent; m_eit_scan = EITscan, m_tablemon = monitor; }
100 
107  void SetUpdateRate(int msec)
108  { m_update_rate = max(msec, (int)m_minimum_update_rate); }
109 
110  // // // // // // // // // // // // // // // // // // // // // // // //
111  // Listeners // // // // // // // // // // // // // // // // // // //
112  void AddListener(SignalMonitorListener *listener);
113  void RemoveListener(SignalMonitorListener *listener);
115  const SignalMonitorValue &val);
116  void SendMessageAllGood(void);
117  virtual void EmitStatus(void);
118 
119  protected:
120  SignalMonitor(int _inputid, ChannelBase *_channel,
121  bool _release_stream, uint64_t wait_for_mask);
122  // Prevent implicit conversion of wrongly ordered arguments
123  SignalMonitor(int, ChannelBase *, uint64_t, bool) = delete;
124 
125  void run(void) override; // MThread
126 
128  virtual void UpdateValues(void);
129 
130  public:
133  static const uint64_t kDTVSigMon_PATSeen = 0x0000000001ULL;
136  static const uint64_t kDTVSigMon_PMTSeen = 0x0000000002ULL;
139  static const uint64_t kDTVSigMon_MGTSeen = 0x0000000004ULL;
142  static const uint64_t kDTVSigMon_VCTSeen = 0x0000000008ULL;
144  static const uint64_t kDTVSigMon_TVCTSeen = 0x0000000010ULL;
146  static const uint64_t kDTVSigMon_CVCTSeen = 0x0000000020ULL;
149  static const uint64_t kDTVSigMon_NITSeen = 0x0000000040ULL;
152  static const uint64_t kDTVSigMon_SDTSeen = 0x0000000080ULL;
154  static const uint64_t kFWSigMon_PowerSeen = 0x0000000100ULL;
156  static const uint64_t kDTVSigMon_CryptSeen = 0x0000000200ULL;
157 
159  static const uint64_t kDTVSigMon_PATMatch = 0x0000001000ULL;
161  static const uint64_t kDTVSigMon_PMTMatch = 0x0000002000ULL;
163  static const uint64_t kDTVSigMon_MGTMatch = 0x0000004000ULL;
165  static const uint64_t kDTVSigMon_VCTMatch = 0x0000008000ULL;
167  static const uint64_t kDTVSigMon_TVCTMatch = 0x0000010000ULL;
169  static const uint64_t kDTVSigMon_CVCTMatch = 0x0000020000ULL;
171  static const uint64_t kDTVSigMon_NITMatch = 0x0000040000ULL;
173  static const uint64_t kDTVSigMon_SDTMatch = 0x0000080000ULL;
175  static const uint64_t kFWSigMon_PowerMatch = 0x0000100000ULL;
177  static const uint64_t kDTVSigMon_CryptMatch = 0x0000200000ULL;
178 
179  static const uint64_t kDTVSigMon_WaitForPAT = 0x0001000000ULL;
180  static const uint64_t kDTVSigMon_WaitForPMT = 0x0002000000ULL;
181  static const uint64_t kDTVSigMon_WaitForMGT = 0x0004000000ULL;
182  static const uint64_t kDTVSigMon_WaitForVCT = 0x0008000000ULL;
183  static const uint64_t kDTVSigMon_WaitForNIT = 0x0010000000ULL;
184  static const uint64_t kDTVSigMon_WaitForSDT = 0x0020000000ULL;
185  static const uint64_t kSigMon_WaitForSig = 0x0040000000ULL;
186  static const uint64_t kFWSigMon_WaitForPower= 0x0080000000ULL;
187  static const uint64_t kDTVSigMon_WaitForCrypt=0x0100000000ULL;
188 
189  static const uint64_t kDTVSigMon_WaitForAll = 0x01FF000000ULL;
190 
192  static const uint64_t kDVBSigMon_WaitForSNR = 0x1000000000ULL;
194  static const uint64_t kDVBSigMon_WaitForBER = 0x2000000000ULL;
196  static const uint64_t kDVBSigMon_WaitForUB = 0x4000000000ULL;
198  static const uint64_t kDVBSigMon_WaitForPos = 0x8000000000ULL;
199 
200  protected:
201  ChannelBase *m_channel {nullptr};
202  TVRec *m_pParent {nullptr};
204  volatile uint64_t m_flags;
206  int m_update_rate {25};
207  uint m_minimum_update_rate {5};
208  bool m_update_done {false};
209  bool m_notify_frontend {true};
210  bool m_tablemon {false};
211  bool m_eit_scan {false};
212 
213  // not to be confused with StreamHandler::m_bError.
214  QString m_error;
215 
219 
220  vector<SignalMonitorListener*> m_listeners;
221 
223  QWaitCondition m_startStopWait; // protected by startStopLock
224  volatile bool m_running {false}; // protected by startStopLock
225  volatile bool m_exit {false}; // protected by startStopLock
226 
227  mutable QMutex m_statusLock {QMutex::Recursive};
228  mutable QMutex m_listenerLock;
229 };
230 
231 inline QString sm_flags_to_string(uint64_t flags)
232 {
233  QString str("Seen(");
235  str += "PAT,";
237  str += "PMT,";
239  str += "MGT,";
241  str += "VCT,";
243  str += "TVCT,";
245  str += "CVCT,";
247  str += "NIT,";
249  str += "SDT,";
251  str += "STB,";
253  str += "Crypt,";
254 
255  str += ") Match(";
257  str += "PAT,";
259  str += "PMT,";
261  str += "MGT,";
263  str += "VCT,";
265  str += "TVCT,";
267  str += "CVCT,";
269  str += "NIT,";
271  str += "SDT,";
273  str += "STB,";
275  str += "Crypt,";
276 
277  str += ") Wait(";
279  str += "PAT,";
281  str += "PMT,";
283  str += "MGT,";
285  str += "VCT,";
287  str += "NIT,";
289  str += "SDT,";
291  str += "Sig,";
293  str += "STB,";
295  str += "Crypt,";
296 
298  str += "SNR,";
300  str += "BER,";
302  str += "UB,";
304  str += "Pos,";
305 
306  str += ")";
307  return str;
308 }
309 
310 inline bool SignalMonitor::IsRequired(const QString &cardtype)
311 {
312  return (cardtype != "IMPORT" && cardtype != "DEMO");
313 }
314 
315 inline bool SignalMonitor::IsSupported(const QString &cardtype)
316 {
317  return IsRequired(cardtype);
318 }
319 
320 
321 #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.
Definition: signalmonitor.h:98
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:90
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:66
static const uint64_t kDTVSigMon_WaitForPAT
bool HasSignalLock(void) const
Returns true iff scriptStatus.IsGood() and signalLock.IsGood() return true.
Definition: signalmonitor.h:73
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.
unsigned int uint
Definition: compat.h:140
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
QString sm_flags_to_string(uint64_t)
static const uint64_t kDTVSigMon_CryptSeen
We've seen something indicating whether the data stream is encrypted.
bool IsErrored(void) const
Definition: signalmonitor.h:80
static const uint64_t kDTVSigMon_WaitForNIT
static int run(MythMediaDevice *dev=nullptr, bool startRandomShow=false)
static const uint64_t kSigMon_WaitForSig
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:150
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.
uint64_t GetFlags(void) const
Definition: signalmonitor.h:58
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.
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:59
int GetUpdateRate() const
Returns milliseconds between signal monitoring events.
Definition: signalmonitor.h:68
QMutex m_listenerLock
virtual bool IsAllGood(void) const
Definition: signalmonitor.h:79
static const uint64_t kDTVSigMon_PMTMatch
We've seen a PMT matching our requirements.