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 <QtGlobal>
8#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
9#include <QtSystemDetection>
10#endif
11
12#include <fcntl.h>
13#include <unistd.h>
14#ifndef Q_OS_WINDOWS
15#include <sys/select.h>
16#endif
17
20
21#include "hdhrchannel.h"
22#include "hdhrrecorder.h"
23#include "hdhrsignalmonitor.h"
24#include "hdhrstreamhandler.h"
25#include "mpeg/atscstreamdata.h"
26#include "mpeg/atsctables.h"
27#include "mpeg/mpegtables.h"
28
29#define LOC QString("HDHRSigMon[%1](%2): ") \
30 .arg(m_inputid).arg(m_channel->GetDevice())
31
47 HDHRChannel* _channel,
48 bool _release_stream,
49 uint64_t _flags)
50 : DTVSignalMonitor(db_cardnum, _channel, _release_stream, _flags),
51 m_signalToNoise (QCoreApplication::translate("(Common)",
52 "Signal To Noise"), "snr",
53 0, true, 0, 100, 0ms)
54{
55 LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
56
58
60
64}
65
70{
71 LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
74}
75
80{
81 LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- begin");
83 if (GetStreamData())
86
87 LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- end");
88}
89
91{
92 return dynamic_cast<HDHRChannel*>(m_channel);
93}
94
102{
103 if (!m_running || m_exit)
104 return;
105
107 {
108 EmitStatus();
109 if (IsAllGood())
111
112 // Update signal status for display
113 struct hdhomerun_tuner_status_t status {};
115
116 // Get info from card
117 uint sig = status.signal_strength;
118 uint snq = status.signal_to_noise_quality;
119 uint seq = status.symbol_error_quality;
120
121 LOG(VB_RECORD, LOG_DEBUG, LOC + "Tuner status: " + QString("'sig:%1 snq:%2 seq:%3'")
122 .arg(sig).arg(snq).arg(seq));
123
124 // Set SignalMonitorValues from info from card.
125 {
126 QMutexLocker locker(&m_statusLock);
129 }
130
131 m_updateDone = true;
132 return;
133 }
134
135 struct hdhomerun_tuner_status_t status {};
137
138 uint sig = status.signal_strength;
139 uint snq = status.signal_to_noise_quality;
140 uint seq = status.symbol_error_quality;
141
142 LOG(VB_RECORD, LOG_DEBUG, LOC + "Tuner status: " + QString("'sig:%1 snq:%2 seq:%3'")
143 .arg(sig).arg(snq).arg(seq));
144
145 // Set SignalMonitorValues from info from card.
146 bool wasLocked = false;
147 bool isLocked = false;
148 {
149 QMutexLocker locker(&m_statusLock);
152 wasLocked = m_signalLock.IsGood();
153 m_signalLock.SetValue(static_cast<int>(status.lock_supported));
154 isLocked = m_signalLock.IsGood();
155 }
156
157 // Signal lock change
158 if (wasLocked != isLocked)
159 {
160 LOG(VB_CHANNEL, LOG_INFO, LOC + "UpdateValues -- Signal " +
161 (isLocked ? "Locked" : "Lost"));
162 }
163
164 EmitStatus();
165 if (IsAllGood())
167
168 // Start table monitoring if we are waiting on any table
169 // and we have a lock.
170 if (isLocked && GetStreamData() &&
174 {
177 }
178
179 m_updateDone = true;
180}
181
183{
184 // Emit signals..
187}
Overall structure.
virtual int GetInputID(void) const
Definition: channelbase.h:67
int GetMajorID(void)
virtual QString GetDevice(void) const
Returns String representing device, useful for debugging.
Definition: channelbase.h:78
This class is intended to detect the presence of needed tables.
bool IsAllGood(void) const override
void AddFlags(uint64_t _flags) override
MPEGStreamData * GetStreamData()
Returns the MPEG stream data if it exists.
~HDHRSignalMonitor() override
Stops signal monitoring and table monitoring threads.
SignalMonitorValue m_signalToNoise
void Stop(void) override
Stop signal monitoring and table monitoring threads.
HDHRChannel * GetHDHRChannel(void)
void UpdateValues(void) override
Fills in frontend stats and emits status Qt signals.
void EmitStatus(void) override
HDHRStreamHandler * m_streamHandler
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
static void Return(HDHRStreamHandler *&ref, int inputid)
void SetThreshold(int _threshold)
bool IsGood() const
Returns true if the value is equal to the threshold, or on the right side of the threshold (depends o...
void SetValue(int _value)
static const uint64_t kDTVSigMon_WaitForVCT
QRecursiveMutex m_statusLock
volatile bool m_exit
void SendMessageAllGood(void)
SignalMonitorValue m_signalLock
static const uint64_t kDTVSigMon_WaitForNIT
void SendMessage(SignalMonitorMessageType type, const SignalMonitorValue &val)
static const uint64_t kDTVSigMon_WaitForSDT
virtual void Stop()
Stop signal monitoring thread.
volatile bool m_running
ChannelBase * m_channel
static const uint64_t kDTVSigMon_WaitForPMT
virtual void EmitStatus(void)
static const uint64_t kSigMon_WaitForSig
static const uint64_t kDTVSigMon_WaitForPAT
static const uint64_t kDTVSigMon_WaitForMGT
SignalMonitorValue m_signalStrength
bool HasAnyFlag(uint64_t _flags) const
virtual void RemoveListener(MPEGStreamData *data)
unsigned int uint
Definition: compat.h:60
#define LOC
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
@ kStatusSignalToNoise
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:86