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_update_done = 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(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_update_done = true;
148 }
QMutex m_statusLock
static const uint64_t kDTVSigMon_WaitForPMT
static const uint64_t kDTVSigMon_WaitForPAT
bool HasAnyFlag(uint64_t _flags) const
virtual void RemoveListener(MPEGStreamData *data)
static const uint64_t kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForMGT
HDHRChannel * GetHDHRChannel(void)
void SetValue(int _value)
static const uint64_t kDTVSigMon_WaitForNIT
static void Return(HDHRStreamHandler *&ref, int inputid)
Overall structure.
#define LOC
virtual void Stop()
Stop signal monitoring thread.
static const uint64_t kSigMon_WaitForSig
ChannelBase * m_channel
volatile bool m_exit
MPEGStreamData * GetStreamData()
Returns the MPEG stream data if it exists.
~HDHRSignalMonitor() override
Stops signal monitoring and table monitoring threads.
unsigned int uint
Definition: compat.h:140
void SendMessageAllGood(void)
volatile bool m_running
This class is intended to detect the presence of needed tables.
virtual QString GetDevice(void) const
Returns String representing device, useful for debugging.
Definition: channelbase.h:78
void AddFlags(uint64_t _flags) override
void UpdateValues(void) override
Fills in frontend stats and emits status Qt signals.
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool IsAllGood(void) const override
SignalMonitorValue m_signalStrength
HDHRStreamHandler * m_streamHandler
static const uint64_t kDTVSigMon_WaitForSDT
virtual int GetInputID(void) const
Definition: channelbase.h:67
bool IsGood() const
Returns true if the value is equal to the threshold, or on the right side of the threshold (depends o...
void SetThreshold(int _threshold)
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
SignalMonitorValue m_signalLock
int GetMajorID(void)
virtual void EmitStatus(void)
void AddListener(MPEGStreamData *data, bool=false, bool=false, QString output_file=QString()) override
void Stop(void) override
Stop signal monitoring and table monitoring threads.