MythTV master
satipsignalmonitor.cpp
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2// Copyright (c) 2006, Daniel Thor Kristjansson
3
6
9#include "satiprecorder.h"
10#include "satipchannel.h"
11
12#define LOC QString("SatIPSigMon[%1]: ").arg(m_inputid)
13
15 SatIPChannel* channel,
16 bool release_stream,
17 uint64_t flags) :
18 DTVSignalMonitor(db_cardnum, channel, release_stream, flags)
19{
20 LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
21
22 // Tuning timeout time for channel lock from database.
23 std::chrono::milliseconds wait = 3s; // Minimum timeout time 3 seconds
24 std::chrono::milliseconds signal_timeout = 0ms; // Not used here
25 std::chrono::milliseconds tuning_timeout = 0ms; // Maximum time for channel lock
26 CardUtil::GetTimeouts(db_cardnum, signal_timeout, tuning_timeout);
27 if (tuning_timeout < wait)
28 {
29 LOG(VB_CHANNEL, LOG_INFO, LOC +
30 QString("Tuning timeout from database: %1 ms is too small, using %2 ms")
31 .arg(tuning_timeout.count()).arg(wait.count()));
32 }
33 else
34 {
35 wait = tuning_timeout; // Use value from database
36 LOG(VB_CHANNEL, LOG_INFO, LOC +
37 QString("Tuning timeout: %1 ms").arg(wait.count()));
38 }
39
43
45
47}
48
50{
51 LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
54}
55
57{
58 LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- begin");
60 if (GetStreamData())
61 {
63 }
65
66 LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- end");
67}
68
70{
71 return dynamic_cast<SatIPChannel*>(m_channel);
72}
73
75{
76 if (!m_running || m_exit)
77 return;
78
80 {
82 {
83 m_error = tr("Error: stream handler died");
84 m_updateDone = true;
85 return;
86 }
87
88 EmitStatus();
89 if (IsAllGood())
90 {
92 }
93
94 // Update signal status
95 int signalStrength = m_streamHandler->GetSignalStrength();
96 m_signalStrength.SetValue(signalStrength);
97
98 m_updateDone = true;
99 return;
100 }
101
102 // Update signal status
103 bool wasLocked = false;
104 bool isLocked = false;
105 {
106 QMutexLocker locker(&m_statusLock);
107 int signalStrength = m_streamHandler->GetSignalStrength();
108 bool hasLock = m_streamHandler->HasLock();
109 m_signalStrength.SetValue(signalStrength);
110 wasLocked = m_signalLock.IsGood();
111 m_signalLock.SetValue(hasLock);
112 isLocked = m_signalLock.IsGood();
113 }
114
115 // Signal lock change
116 if (wasLocked != isLocked)
117 {
118 LOG(VB_CHANNEL, LOG_INFO, LOC + "UpdateValues -- Signal " +
119 (isLocked ? "Locked" : "Lost"));
120 }
121
122 EmitStatus();
123 if (IsAllGood())
124 {
126 }
127
128 // Start table monitoring if we are waiting on any table and we have a lock.
129 if (isLocked && GetStreamData() &&
133 {
136 }
137
138 m_updateDone = true;
139}
static bool GetTimeouts(uint inputid, std::chrono::milliseconds &signal_timeout, std::chrono::milliseconds &channel_timeout)
Definition: cardutil.cpp:2288
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.
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: satipchannel.h:29
SatIPChannel * GetSatIPChannel(void)
SatIPSignalMonitor(int db_cardnum, SatIPChannel *channel, bool release_stream, uint64_t flags=0)
void UpdateValues(void) override
This should be overridden to actually do signal monitoring.
void Stop(void) override
Stop signal monitoring thread.
SatIPStreamHandler * m_streamHandler
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
static SatIPStreamHandler * Get(const QString &devname, int inputid)
static void Return(SatIPStreamHandler *&ref, int inputid)
void SetTimeout(std::chrono::milliseconds _timeout)
void SetThreshold(int _threshold)
void SetRange(int _min, int _max)
Sets the minimum and maximum values.
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
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
bool IsRunning(void) const
virtual void RemoveListener(MPEGStreamData *data)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
#define LOC