MythTV  master
hdhrsignalmonitor.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2006, Daniel Thor Kristjansson
3 
4 #include <cerrno>
5 #include <cstring>
6 
7 #include <fcntl.h>
8 #include <unistd.h>
9 #ifndef _WIN32
10 #include <sys/select.h>
11 #endif
12 
13 #include "mythlogging.h"
14 #include "mythdbcon.h"
15 #include "hdhrsignalmonitor.h"
16 #include "atscstreamdata.h"
17 #include "mpegtables.h"
18 #include "atsctables.h"
19 
20 #include "hdhrchannel.h"
21 #include "hdhrrecorder.h"
22 #include "hdhrstreamhandler.h"
23 
24 #define LOC QString("HDHRSigMon[%1](%2): ") \
25  .arg(m_inputid).arg(m_channel->GetDevice())
26 
42  HDHRChannel* _channel,
43  bool _release_stream,
44  uint64_t _flags)
45  : DTVSignalMonitor(db_cardnum, _channel, _release_stream, _flags),
46  m_signalToNoise (QCoreApplication::translate("(Common)",
47  "Signal To Noise"), "snr",
48  0, true, 0, 100, 0ms)
49 {
50  LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
51 
53 
55 
59 }
60 
65 {
66  LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
69 }
70 
75 {
76  LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- begin");
78  if (GetStreamData())
80  m_streamHandlerStarted = false;
81 
82  LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- end");
83 }
84 
86 {
87  return dynamic_cast<HDHRChannel*>(m_channel);
88 }
89 
97 {
98  if (!m_running || m_exit)
99  return;
100 
102  {
103  EmitStatus();
104  if (IsAllGood())
106 
107  // Update signal status for display
108  struct hdhomerun_tuner_status_t status {};
110 
111  // Get info from card
112  uint sig = status.signal_strength;
113  uint snq = status.signal_to_noise_quality;
114  uint seq = status.symbol_error_quality;
115 
116  LOG(VB_RECORD, LOG_DEBUG, LOC + "Tuner status: " + QString("'sig:%1 snq:%2 seq:%3'")
117  .arg(sig).arg(snq).arg(seq));
118 
119  // Set SignalMonitorValues from info from card.
120  {
121  QMutexLocker locker(&m_statusLock);
124  }
125 
126  m_updateDone = true;
127  return;
128  }
129 
130  struct hdhomerun_tuner_status_t status {};
132 
133  uint sig = status.signal_strength;
134  uint snq = status.signal_to_noise_quality;
135  uint seq = status.symbol_error_quality;
136 
137  LOG(VB_RECORD, LOG_DEBUG, LOC + "Tuner status: " + QString("'sig:%1 snq:%2 seq:%3'")
138  .arg(sig).arg(snq).arg(seq));
139 
140  // Set SignalMonitorValues from info from card.
141  bool wasLocked = false;
142  bool isLocked = false;
143  {
144  QMutexLocker locker(&m_statusLock);
147  wasLocked = m_signalLock.IsGood();
148  m_signalLock.SetValue(static_cast<int>(status.lock_supported));
149  isLocked = m_signalLock.IsGood();
150  }
151 
152  // Signal lock change
153  if (wasLocked != isLocked)
154  {
155  LOG(VB_CHANNEL, LOG_INFO, LOC + "UpdateValues -- Signal " +
156  (isLocked ? "Locked" : "Lost"));
157  }
158 
159  EmitStatus();
160  if (IsAllGood())
162 
163  // Start table monitoring if we are waiting on any table
164  // and we have a lock.
165  if (isLocked && GetStreamData() &&
169  {
171  m_streamHandlerStarted = true;
172  }
173 
174  m_updateDone = true;
175 }
176 
178 {
179  // Emit signals..
182 }
DTVSignalMonitor::AddFlags
void AddFlags(uint64_t _flags) override
Definition: dtvsignalmonitor.cpp:140
hdhrsignalmonitor.h
HDHRSignalMonitor::Stop
void Stop(void) override
Stop signal monitoring and table monitoring threads.
Definition: hdhrsignalmonitor.cpp:74
HDHRSignalMonitor::HDHRSignalMonitor
HDHRSignalMonitor(void)
HDHRSignalMonitor::m_signalToNoise
SignalMonitorValue m_signalToNoise
Definition: hdhrsignalmonitor.h:31
SignalMonitorValue::SetValue
void SetValue(int _value)
Definition: signalmonitorvalue.h:74
SignalMonitorValue::SetThreshold
void SetThreshold(int _threshold)
Definition: signalmonitorvalue.h:84
HDHRStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: hdhrstreamhandler.h:55
SignalMonitor::m_channel
ChannelBase * m_channel
Definition: signalmonitor.h:205
SignalMonitor::kDTVSigMon_WaitForMGT
static const uint64_t kDTVSigMon_WaitForMGT
Definition: signalmonitor.h:185
SignalMonitor::SendMessage
void SendMessage(SignalMonitorMessageType type, const SignalMonitorValue &val)
Definition: signalmonitor.cpp:412
SignalMonitor::m_exit
volatile bool m_exit
Definition: signalmonitor.h:229
mythdbcon.h
DTVSignalMonitor::GetStreamData
MPEGStreamData * GetStreamData()
Returns the MPEG stream data if it exists.
Definition: dtvsignalmonitor.h:59
atscstreamdata.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
SignalMonitor::m_running
volatile bool m_running
Definition: signalmonitor.h:228
SignalMonitor::HasAnyFlag
bool HasAnyFlag(uint64_t _flags) const
Definition: signalmonitor.cpp:282
true
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
SignalMonitor::kSigMon_WaitForSig
static const uint64_t kSigMon_WaitForSig
Definition: signalmonitor.h:189
HDHRChannel
Definition: hdhrchannel.h:20
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:78
LOC
#define LOC
Definition: hdhrsignalmonitor.cpp:24
SignalMonitor::m_statusLock
QRecursiveMutex m_statusLock
Definition: signalmonitor.h:234
HDHRSignalMonitor::GetHDHRChannel
HDHRChannel * GetHDHRChannel(void)
Definition: hdhrsignalmonitor.cpp:85
SignalMonitor::m_signalStrength
SignalMonitorValue m_signalStrength
Definition: signalmonitor.h:221
mythlogging.h
SignalMonitor::m_inputid
int m_inputid
Definition: signalmonitor.h:207
HDHRStreamHandler::Return
static void Return(HDHRStreamHandler *&ref, int inputid)
Definition: hdhrstreamhandler.cpp:63
SignalMonitor::m_signalLock
SignalMonitorValue m_signalLock
Definition: signalmonitor.h:220
SignalMonitor::SendMessageAllGood
void SendMessageAllGood(void)
Definition: signalmonitor.cpp:467
SignalMonitor::kDTVSigMon_WaitForPMT
static const uint64_t kDTVSigMon_WaitForPMT
Definition: signalmonitor.h:184
SignalMonitor::kDTVSigMon_WaitForPAT
static const uint64_t kDTVSigMon_WaitForPAT
Definition: signalmonitor.h:183
SignalMonitor::m_updateDone
bool m_updateDone
Definition: signalmonitor.h:212
SignalMonitor::kDTVSigMon_WaitForNIT
static const uint64_t kDTVSigMon_WaitForNIT
Definition: signalmonitor.h:187
SignalMonitor::EmitStatus
virtual void EmitStatus(void)
Definition: signalmonitor.cpp:474
SignalMonitor::kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_WaitForSDT
Definition: signalmonitor.h:188
hdhrrecorder.h
mpegtables.h
uint
unsigned int uint
Definition: compat.h:144
kStatusSignalToNoise
@ kStatusSignalToNoise
Definition: signalmonitorlistener.h:15
SignalMonitorValue::IsGood
bool IsGood() const
Returns true if the value is equal to the threshold, or on the right side of the threshold (depends o...
Definition: signalmonitorvalue.h:56
HDHRSignalMonitor::~HDHRSignalMonitor
~HDHRSignalMonitor() override
Stops signal monitoring and table monitoring threads.
Definition: hdhrsignalmonitor.cpp:64
HDHRSignalMonitor::m_streamHandlerStarted
bool m_streamHandlerStarted
Definition: hdhrsignalmonitor.h:33
HDHRSignalMonitor::m_streamHandler
HDHRStreamHandler * m_streamHandler
Definition: hdhrsignalmonitor.h:34
HDHRSignalMonitor::EmitStatus
void EmitStatus(void) override
Definition: hdhrsignalmonitor.cpp:177
HDHRSignalMonitor::UpdateValues
void UpdateValues(void) override
Fills in frontend stats and emits status Qt signals.
Definition: hdhrsignalmonitor.cpp:96
HDHRStreamHandler::GetTunerStatus
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
Definition: hdhrstreamhandler.cpp:503
DTVSignalMonitor
This class is intended to detect the presence of needed tables.
Definition: dtvsignalmonitor.h:14
ChannelBase::GetInputID
virtual int GetInputID(void) const
Definition: channelbase.h:67
atsctables.h
ChannelBase::GetDevice
virtual QString GetDevice(void) const
Returns String representing device, useful for debugging.
Definition: channelbase.h:78
HDHRStreamHandler::Get
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
Definition: hdhrstreamhandler.cpp:32
hdhrstreamhandler.h
SignalMonitor::Stop
virtual void Stop()
Stop signal monitoring thread.
Definition: signalmonitor.cpp:306
hdhrchannel.h
ChannelBase::GetMajorID
int GetMajorID(void)
Definition: channelbase.cpp:852
DTVSignalMonitor::IsAllGood
bool IsAllGood(void) const override
Definition: dtvsignalmonitor.cpp:580
SignalMonitor::kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForVCT
Definition: signalmonitor.h:186