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#include <QRecursiveMutex>
16
17// MythTV headers
18#include "libmythbase/mthread.h"
20
21#include "cardutil.h"
22#include "channelbase.h"
24#include "signalmonitorvalue.h"
25
26inline QString sm_flags_to_string(uint64_t flags);
27
28class TVRec;
29
30class SignalMonitor : protected MThread
31{
33
34 public:
36 static inline bool IsRequired(const QString &cardtype);
37 static inline bool IsSupported(const QString &cardtype);
38 static SignalMonitor *Init(const QString& cardtype, int db_cardnum,
39 ChannelBase *channel,
40 bool release_stream);
41 ~SignalMonitor() override;
42
43 // Prevent implicit conversion of wrongly ordered arguments
44 SignalMonitor(int, ChannelBase *, uint64_t, bool) = delete;
45
46 // // // // // // // // // // // // // // // // // // // // // // // //
47 // Control // // // // // // // // // // // // // // // // // // // //
48
49 virtual void Start();
50 virtual void Stop();
51
52 // // // // // // // // // // // // // // // // // // // // // // // //
53 // Flags // // // // // // // // // // // // // // // // // // // // //
54
55 virtual void AddFlags(uint64_t _flags);
56 virtual void RemoveFlags(uint64_t _flags);
57 bool HasFlags(uint64_t _flags) const;
58 bool HasAnyFlag(uint64_t _flags) const;
59 uint64_t GetFlags(void) const { return m_flags; }
60 virtual bool HasExtraSlowTuning(void) const { return false; }
61
62 // // // // // // // // // // // // // // // // // // // // // // // //
63 // Gets // // // // // // // // // // // // // // // // // // // // //
64
67 bool GetNotifyFrontend() const { return m_notifyFrontend; }
69 std::chrono::milliseconds GetUpdateRate() const { return m_updateRate; }
70 virtual QStringList GetStatusList(void) const;
72
75 bool HasSignalLock(void) const
76 {
77 QMutexLocker locker(&m_statusLock);
79 }
80
81 virtual bool IsAllGood(void) const { return HasSignalLock(); }
82 bool IsErrored(void) const { return !m_error.isEmpty(); }
83
84 // // // // // // // // // // // // // // // // // // // // // // // //
85 // Sets // // // // // // // // // // // // // // // // // // // // //
86
92 void SetNotifyFrontend(bool notify) { m_notifyFrontend = notify; }
93
100 void SetMonitoring(TVRec * parent, bool EITscan, bool monitor)
101 { m_pParent = parent; m_eitScan = EITscan, m_tablemon = monitor; }
102
109 void SetUpdateRate(std::chrono::milliseconds msec)
110 { m_updateRate = std::max(msec, m_minimumUpdateRate); }
111
112 // // // // // // // // // // // // // // // // // // // // // // // //
113 // Listeners // // // // // // // // // // // // // // // // // // //
114 void AddListener(SignalMonitorListener *listener);
117 const SignalMonitorValue &val);
118 void SendMessageAllGood(void);
119 virtual void EmitStatus(void);
120
121 protected:
122 SignalMonitor(int _inputid, ChannelBase *_channel,
123 bool _release_stream, uint64_t wait_for_mask);
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:
202 TVRec *m_pParent {nullptr};
204 volatile uint64_t m_flags;
206 std::chrono::milliseconds m_updateRate {25ms};
207 std::chrono::milliseconds m_minimumUpdateRate {5ms};
208 bool m_updateDone {false};
209 bool m_notifyFrontend {true};
210 bool m_tablemon {false};
211 bool m_eitScan {false};
212
213 // not to be confused with StreamHandler::m_bError.
214 QString m_error;
215
219
220 std::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 QRecursiveMutex m_statusLock;
228 mutable QMutex m_listenerLock;
229};
230
231inline 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
310inline bool SignalMonitor::IsRequired(const QString &cardtype)
311{
312 return (cardtype != "IMPORT" && cardtype != "DEMO");
313}
314
315inline bool SignalMonitor::IsSupported(const QString &cardtype)
316{
317 return IsRequired(cardtype);
318}
319
320
321#endif // SIGNALMONITOR_H
Abstract class providing a generic interface to tuning hardware.
Definition: channelbase.h:32
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
int GetNormalizedValue(int newmin, int newmax) const
Returns the value normalized to the [newmin, newmax] range.
bool IsGood() const
Returns true if the value is equal to the threshold, or on the right side of the threshold (depends o...
Signal monitoring base class.
Definition: signalmonitor.h:31
~SignalMonitor() override
Stops monitoring thread.
static const uint64_t kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_VCTMatch
We've seen a VCT matching our requirements.
std::chrono::milliseconds m_updateRate
void RemoveListener(SignalMonitorListener *listener)
QRecursiveMutex m_statusLock
volatile bool m_exit
virtual void RemoveFlags(uint64_t _flags)
static const uint64_t kDTVSigMon_CryptSeen
We've seen something indicating whether the data stream is encrypted.
QMutex m_listenerLock
void SendMessageAllGood(void)
void AddListener(SignalMonitorListener *listener)
static SignalMonitor * Init(const QString &cardtype, int db_cardnum, ChannelBase *channel, bool release_stream)
SignalMonitorValue m_signalLock
std::chrono::milliseconds GetUpdateRate() const
Returns milliseconds between signal monitoring events.
Definition: signalmonitor.h:69
static const uint64_t kDTVSigMon_WaitForNIT
void SetMonitoring(TVRec *parent, bool EITscan, bool monitor)
Indicate if table monitoring is needed.
std::vector< SignalMonitorListener * > m_listeners
static const uint64_t kDTVSigMon_PMTMatch
We've seen a PMT matching our requirements.
void SendMessage(SignalMonitorMessageType type, const SignalMonitorValue &val)
virtual QStringList GetStatusList(void) const
Returns QStringList containing all signals and their current values.
SignalMonitorValue m_scriptStatus
static const uint64_t kDVBSigMon_WaitForPos
Wait for rotor to complete turning the antenna.
bool HasFlags(uint64_t _flags) const
static const uint64_t kDTVSigMon_CVCTSeen
We've seen a CVCT, the cable version of the VCT.
static const uint64_t kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_NITSeen
We've seen a NIT, which tells us where to find SDT and other DVB tables.
virtual void Stop()
Stop signal monitoring thread.
volatile bool m_running
uint64_t GetFlags(void) const
Definition: signalmonitor.h:59
TVRec * m_pParent
bool IsErrored(void) const
Definition: signalmonitor.h:82
SignalMonitor(int, ChannelBase *, uint64_t, bool)=delete
ChannelBase * m_channel
virtual bool HasExtraSlowTuning(void) const
Definition: signalmonitor.h:60
virtual bool IsAllGood(void) const
Definition: signalmonitor.h:81
static const uint64_t kDTVSigMon_MGTMatch
We've seen an MGT matching our requirements.
static bool IsSupported(const QString &cardtype)
static const uint64_t kDTVSigMon_CryptMatch
We've seen unencrypted data in data stream.
static const uint64_t kDTVSigMon_WaitForPMT
void SetUpdateRate(std::chrono::milliseconds msec)
Sets the number of milliseconds between signal monitoring attempts in the signal monitoring thread.
virtual void EmitStatus(void)
static const uint64_t kDTVSigMon_SDTSeen
We've seen a SDT, which maps DVB Channels to MPEG program numbers, and provides additional data.
static const uint64_t kSigMon_WaitForSig
int GetSignalStrength(void)
Definition: signalmonitor.h:71
static const uint64_t kDTVSigMon_WaitForPAT
QWaitCondition m_startStopWait
static const uint64_t kDTVSigMon_WaitForCrypt
void SetNotifyFrontend(bool notify)
Enables or disables frontend notification of the current signal value.
Definition: signalmonitor.h:92
Q_DECLARE_TR_FUNCTIONS(SignalMonitor)
static const uint64_t kDTVSigMon_PATMatch
We've seen a PAT matching our requirements.
static const uint64_t kDTVSigMon_CVCTMatch
We've seen a CVCT matching our requirements.
static const uint64_t kDTVSigMon_WaitForMGT
static const uint64_t kDVBSigMon_WaitForUB
Wait for uncorrected FEC blocks to fall below a threshold.
void run(void) override
Basic signal monitoring loop.
virtual void UpdateValues(void)
This should be overridden to actually do signal monitoring.
static const uint64_t kFWSigMon_PowerSeen
We've seen the FireWire STB power state.
static const uint64_t kDTVSigMon_TVCTMatch
We've seen a TVCT matching our requirements.
static bool IsRequired(const QString &cardtype)
Returns true iff the card type supports signal monitoring.
bool GetNotifyFrontend() const
Returns whether or not a SIGNAL MythEvent is being sent regularly to the frontend.
Definition: signalmonitor.h:67
virtual void AddFlags(uint64_t _flags)
static const uint64_t kDTVSigMon_TVCTSeen
We've seen a TVCT, the terrestrial version of the VCT.
static const uint64_t kFWSigMon_PowerMatch
We've seen a FireWire STB power state matching our requirements.
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_MGTSeen
We've seen a MGT, which tells us on which PIDs to find VCT and other ATSC tables.
static const uint64_t kDTVSigMon_SDTMatch
We've seen an SDT matching our requirements.
static const uint64_t kFWSigMon_WaitForPower
SignalMonitorValue m_signalStrength
bool HasSignalLock(void) const
Returns true iff scriptStatus.IsGood() and signalLock.IsGood() return true.
Definition: signalmonitor.h:75
static const uint64_t kDTVSigMon_PMTSeen
We've seen a PMT, which maps program to audio, video and other stream PIDs.
QMutex m_startStopLock
static const uint64_t kDTVSigMon_NITMatch
We've seen an NIT matching our requirements.
std::chrono::milliseconds m_minimumUpdateRate
static const uint64_t kDVBSigMon_WaitForSNR
Wait for the Signal to Noise Ratio to rise above a threshold.
virtual void Start()
Start signal monitoring thread.
static const uint64_t kDVBSigMon_WaitForBER
Wait for the Bit Error Rate to fall below a threshold.
volatile uint64_t m_flags
bool HasAnyFlag(uint64_t _flags) const
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 kDTVSigMon_WaitForAll
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
QString sm_flags_to_string(uint64_t flags)
SignalMonitorMessageType