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
15
16#include "hdhrchannel.h"
17#include "hdhrrecorder.h"
18#include "hdhrsignalmonitor.h"
19#include "hdhrstreamhandler.h"
20#include "mpeg/atscstreamdata.h"
21#include "mpeg/atsctables.h"
22#include "mpeg/mpegtables.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())
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 {
172 }
173
174 m_updateDone = true;
175}
176
178{
179 // Emit signals..
182}
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: freesurround.h:24
#define LOC
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
@ kStatusSignalToNoise
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:95