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 {
47  LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
48 
50 
52 
56 }
57 
62 {
63  LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
66 }
67 
72 {
73  LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- begin");
75  if (GetStreamData())
77  m_streamHandlerStarted = false;
78 
79  LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- end");
80 }
81 
83 {
84  return dynamic_cast<HDHRChannel*>(m_channel);
85 }
86 
94 {
95  if (!m_running || m_exit)
96  return;
97 
99  {
100  EmitStatus();
101  if (IsAllGood())
103 
104  // TODO dtv signals...
105 
106  m_updateDone = true;
107  return;
108  }
109 
110  struct hdhomerun_tuner_status_t status {};
112 
113  uint sig = status.signal_strength;
114  uint snq = status.signal_to_noise_quality;
115  uint seq = status.symbol_error_quality;
116 
117  (void) snq; // TODO should convert to S/N
118  (void) seq; // TODO should report this...
119 
120  LOG(VB_RECORD, LOG_DEBUG, LOC + "Tuner status: " + QString("'%1:%2:%3'")
121  .arg(sig).arg(snq).arg(seq));
122 
123  // Set SignalMonitorValues from info from card.
124  bool isLocked = false;
125  {
126  QMutexLocker locker(&m_statusLock);
128  m_signalLock.SetValue(static_cast<int>(status.lock_supported));
129  isLocked = m_signalLock.IsGood();
130  }
131 
132  EmitStatus();
133  if (IsAllGood())
135 
136  // Start table monitoring if we are waiting on any table
137  // and we have a lock.
138  if (isLocked && GetStreamData() &&
142  {
144  m_streamHandlerStarted = true;
145  }
146 
147  m_updateDone = true;
148 }
DTVSignalMonitor::AddFlags
void AddFlags(uint64_t _flags) override
Definition: dtvsignalmonitor.cpp:143
hdhrsignalmonitor.h
HDHRSignalMonitor::Stop
void Stop(void) override
Stop signal monitoring and table monitoring threads.
Definition: hdhrsignalmonitor.cpp:71
HDHRSignalMonitor::HDHRSignalMonitor
HDHRSignalMonitor(void)
SignalMonitorValue::SetValue
void SetValue(int _value)
Definition: signalmonitorvalue.h:75
SignalMonitorValue::SetThreshold
void SetThreshold(int _threshold)
Definition: signalmonitorvalue.h:85
SignalMonitor::m_channel
ChannelBase * m_channel
Definition: signalmonitor.h:203
SignalMonitor::kDTVSigMon_WaitForMGT
static const uint64_t kDTVSigMon_WaitForMGT
Definition: signalmonitor.h:183
arg
arg(title).arg(filename).arg(doDelete))
SignalMonitor::m_exit
volatile bool m_exit
Definition: signalmonitor.h:227
mythdbcon.h
DTVSignalMonitor::GetStreamData
MPEGStreamData * GetStreamData()
Returns the MPEG stream data if it exists.
Definition: dtvsignalmonitor.h:60
atscstreamdata.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
SignalMonitor::m_running
volatile bool m_running
Definition: signalmonitor.h:226
SignalMonitor::HasAnyFlag
bool HasAnyFlag(uint64_t _flags) const
Definition: signalmonitor.cpp:282
SignalMonitor::kSigMon_WaitForSig
static const uint64_t kSigMon_WaitForSig
Definition: signalmonitor.h:187
HDHRChannel
Definition: hdhrchannel.h:21
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:78
LOC
#define LOC
Definition: hdhrsignalmonitor.cpp:24
HDHRSignalMonitor::GetHDHRChannel
HDHRChannel * GetHDHRChannel(void)
Definition: hdhrsignalmonitor.cpp:82
SignalMonitor::m_signalStrength
SignalMonitorValue m_signalStrength
Definition: signalmonitor.h:219
mythlogging.h
SignalMonitor::m_inputid
int m_inputid
Definition: signalmonitor.h:205
HDHRStreamHandler::Return
static void Return(HDHRStreamHandler *&ref, int inputid)
Definition: hdhrstreamhandler.cpp:63
SignalMonitor::m_signalLock
SignalMonitorValue m_signalLock
Definition: signalmonitor.h:218
SignalMonitor::SendMessageAllGood
void SendMessageAllGood(void)
Definition: signalmonitor.cpp:467
SignalMonitor::kDTVSigMon_WaitForPMT
static const uint64_t kDTVSigMon_WaitForPMT
Definition: signalmonitor.h:182
SignalMonitor::kDTVSigMon_WaitForPAT
static const uint64_t kDTVSigMon_WaitForPAT
Definition: signalmonitor.h:181
SignalMonitor::m_updateDone
bool m_updateDone
Definition: signalmonitor.h:210
SignalMonitor::kDTVSigMon_WaitForNIT
static const uint64_t kDTVSigMon_WaitForNIT
Definition: signalmonitor.h:185
SignalMonitor::EmitStatus
virtual void EmitStatus(void)
Definition: signalmonitor.cpp:474
SignalMonitor::kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_WaitForSDT
Definition: signalmonitor.h:186
hdhrrecorder.h
mpegtables.h
uint
unsigned int uint
Definition: compat.h:140
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:57
HDHRSignalMonitor::~HDHRSignalMonitor
~HDHRSignalMonitor() override
Stops signal monitoring and table monitoring threads.
Definition: hdhrsignalmonitor.cpp:61
HDHRSignalMonitor::m_streamHandlerStarted
bool m_streamHandlerStarted
Definition: hdhrsignalmonitor.h:30
HDHRSignalMonitor::m_streamHandler
HDHRStreamHandler * m_streamHandler
Definition: hdhrsignalmonitor.h:31
HDHRSignalMonitor::UpdateValues
void UpdateValues(void) override
Fills in frontend stats and emits status Qt signals.
Definition: hdhrsignalmonitor.cpp:93
HDHRStreamHandler::GetTunerStatus
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
Definition: hdhrstreamhandler.cpp:495
SignalMonitor::m_statusLock
QMutex m_statusLock
Definition: signalmonitor.h:229
DTVSignalMonitor
This class is intended to detect the presence of needed tables.
Definition: dtvsignalmonitor.h:20
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:857
HDHRStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, QString output_file=QString()) override
Definition: hdhrstreamhandler.h:53
DTVSignalMonitor::IsAllGood
bool IsAllGood(void) const override
Definition: dtvsignalmonitor.cpp:566
SignalMonitor::kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForVCT
Definition: signalmonitor.h:184