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(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 flags; }
59  virtual bool HasExtraSlowTuning(void) const { return false; }
60 
61  // // // // // // // // // // // // // // // // // // // // // // // //
62  // Gets // // // // // // // // // // // // // // // // // // // // //
63 
66  bool GetNotifyFrontend() const { return notify_frontend; }
68  int GetUpdateRate() const { return update_rate; }
69  virtual QStringList GetStatusList(void) const;
70 
73  bool HasSignalLock(void) const
74  {
75  QMutexLocker locker(&statusLock);
76  return scriptStatus.IsGood() && signalLock.IsGood();
77  }
78 
79  virtual bool IsAllGood(void) const { return HasSignalLock(); }
80  bool IsErrored(void) const { return !error.isEmpty(); }
81 
82  // // // // // // // // // // // // // // // // // // // // // // // //
83  // Sets // // // // // // // // // // // // // // // // // // // // //
84 
90  void SetNotifyFrontend(bool notify) { notify_frontend = notify; }
91 
98  void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
99  { pParent = parent; eit_scan = EITscan, tablemon = monitor; }
100 
107  void SetUpdateRate(int msec)
108  { update_rate = max(msec, (int)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:
203  int inputid;
204  volatile uint64_t flags;
210  bool tablemon;
211  bool eit_scan;
212  QString error;
213 
217 
218  vector<SignalMonitorListener*> listeners;
219 
221  QWaitCondition startStopWait; // protected by startStopLock
222  volatile bool running; // protected by startStopLock
223  volatile bool exit; // protected by startStopLock
224 
225  mutable QMutex statusLock;
226  mutable QMutex listenerLock;
227 };
228 
229 inline QString sm_flags_to_string(uint64_t flags)
230 {
231  QString str("Seen(");
233  str += "PAT,";
235  str += "PMT,";
237  str += "MGT,";
239  str += "VCT,";
241  str += "TVCT,";
243  str += "CVCT,";
245  str += "NIT,";
247  str += "SDT,";
249  str += "STB,";
251  str += "Crypt,";
252 
253  str += ") Match(";
255  str += "PAT,";
257  str += "PMT,";
259  str += "MGT,";
261  str += "VCT,";
263  str += "TVCT,";
265  str += "CVCT,";
267  str += "NIT,";
269  str += "SDT,";
271  str += "STB,";
273  str += "Crypt,";
274 
275  str += ") Wait(";
277  str += "PAT,";
279  str += "PMT,";
281  str += "MGT,";
283  str += "VCT,";
285  str += "NIT,";
287  str += "SDT,";
289  str += "Sig,";
291  str += "STB,";
293  str += "Crypt,";
294 
296  str += "SNR,";
298  str += "BER,";
300  str += "UB,";
302  str += "Pos,";
303 
304  str += ")";
305  return str;
306 }
307 
308 inline bool SignalMonitor::IsRequired(const QString &cardtype)
309 {
310  return (cardtype != "IMPORT" && cardtype != "DEMO");
311 }
312 
313 inline bool SignalMonitor::IsSupported(const QString &cardtype)
314 {
315  return IsRequired(cardtype);
316 }
317 
318 
319 #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
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 void error(const char *str,...)
Definition: vbi.c:41
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)
SignalMonitorValue signalLock
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
vector< SignalMonitorListener * > listeners
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
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.
uint minimum_update_rate
volatile uint64_t flags
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
QMutex startStopLock
Abstract class providing a generic interface to tuning hardware.
Definition: channelbase.h:31
SignalMonitorMessageType
static const uint64_t kDTVSigMon_CVCTMatch
We've seen a CVCT matching our requirements.
static const uint64_t kDTVSigMon_WaitForSDT
QWaitCondition startStopWait
static const uint64_t kDTVSigMon_MGTMatch
We've seen an MGT matching our requirements.
SignalMonitorValue signalStrength
static const uint64_t kFWSigMon_WaitForPower
SignalMonitorValue scriptStatus
void SetUpdateRate(int msec)
Sets the number of milliseconds between signal monitoring attempts in the signal monitoring thread.
ChannelBase * channel
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
volatile bool running
QMutex listenerLock
volatile bool exit
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.
virtual bool HasExtraSlowTuning(void) const
Definition: signalmonitor.h:59
int GetUpdateRate() const
Returns milliseconds between signal monitoring events.
Definition: signalmonitor.h:68
virtual bool IsAllGood(void) const
Definition: signalmonitor.h:79
static const uint64_t kDTVSigMon_PMTMatch
We've seen a PMT matching our requirements.