MythTV  master
satipsignalmonitor.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2006, Daniel Thor Kristjansson
3 
6 
7 #include "satipsignalmonitor.h"
8 #include "satipstreamhandler.h"
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 
41  m_signalStrength.SetRange(0, 255);
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  }
64  m_streamHandlerStarted = false;
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  {
81  if (!m_streamHandler->IsRunning())
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  {
135  m_streamHandlerStarted = true;
136  }
137 
138  m_updateDone = true;
139 }
DTVSignalMonitor::AddFlags
void AddFlags(uint64_t _flags) override
Definition: dtvsignalmonitor.cpp:140
SignalMonitorValue::SetValue
void SetValue(int _value)
Definition: signalmonitorvalue.h:74
LOC
#define LOC
Definition: satipsignalmonitor.cpp:12
SignalMonitorValue::SetThreshold
void SetThreshold(int _threshold)
Definition: signalmonitorvalue.h:84
MThread::wait
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
SignalMonitor::m_channel
ChannelBase * m_channel
Definition: signalmonitor.h:201
SignalMonitor::kDTVSigMon_WaitForMGT
static const uint64_t kDTVSigMon_WaitForMGT
Definition: signalmonitor.h:181
SignalMonitor::m_exit
volatile bool m_exit
Definition: signalmonitor.h:225
mythdbcon.h
DTVSignalMonitor::GetStreamData
MPEGStreamData * GetStreamData()
Returns the MPEG stream data if it exists.
Definition: dtvsignalmonitor.h:59
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
SignalMonitor::m_running
volatile bool m_running
Definition: signalmonitor.h:224
satipchannel.h
SignalMonitor::HasAnyFlag
bool HasAnyFlag(uint64_t _flags) const
Definition: signalmonitor.cpp:280
SatIPSignalMonitor::m_streamHandlerStarted
bool m_streamHandlerStarted
Definition: satipsignalmonitor.h:27
SignalMonitor::kSigMon_WaitForSig
static const uint64_t kSigMon_WaitForSig
Definition: signalmonitor.h:185
SignalMonitor::m_error
QString m_error
Definition: signalmonitor.h:214
SatIPStreamHandler::HasLock
bool HasLock()
Definition: satipstreamhandler.cpp:492
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:80
SignalMonitor::m_statusLock
QRecursiveMutex m_statusLock
Definition: signalmonitor.h:227
SatIPSignalMonitor::m_streamHandler
SatIPStreamHandler * m_streamHandler
Definition: satipsignalmonitor.h:28
SatIPChannel
Definition: satipchannel.h:12
SignalMonitorValue::SetTimeout
void SetTimeout(std::chrono::milliseconds _timeout)
Definition: signalmonitorvalue.h:98
SignalMonitor::m_signalStrength
SignalMonitorValue m_signalStrength
Definition: signalmonitor.h:217
mythlogging.h
SignalMonitor::m_inputid
int m_inputid
Definition: signalmonitor.h:203
SatIPStreamHandler::Return
static void Return(SatIPStreamHandler *&ref, int inputid)
Definition: satipstreamhandler.cpp:63
SignalMonitor::m_signalLock
SignalMonitorValue m_signalLock
Definition: signalmonitor.h:216
SignalMonitor::SendMessageAllGood
void SendMessageAllGood(void)
Definition: signalmonitor.cpp:465
SignalMonitor::kDTVSigMon_WaitForPMT
static const uint64_t kDTVSigMon_WaitForPMT
Definition: signalmonitor.h:180
SignalMonitor::kDTVSigMon_WaitForPAT
static const uint64_t kDTVSigMon_WaitForPAT
Definition: signalmonitor.h:179
SignalMonitor::m_updateDone
bool m_updateDone
Definition: signalmonitor.h:208
SignalMonitor::kDTVSigMon_WaitForNIT
static const uint64_t kDTVSigMon_WaitForNIT
Definition: signalmonitor.h:183
SignalMonitor::EmitStatus
virtual void EmitStatus(void)
Definition: signalmonitor.cpp:472
SignalMonitor::kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_WaitForSDT
Definition: signalmonitor.h:184
SatIPSignalMonitor::GetSatIPChannel
SatIPChannel * GetSatIPChannel(void)
Definition: satipsignalmonitor.cpp:69
satipsignalmonitor.h
SatIPStreamHandler::GetSignalStrength
int GetSignalStrength()
Definition: satipstreamhandler.cpp:498
SatIPSignalMonitor::UpdateValues
void UpdateValues(void) override
This should be overridden to actually do signal monitoring.
Definition: satipsignalmonitor.cpp:74
SignalMonitorValue::SetRange
void SetRange(int _min, int _max)
Sets the minimum and maximum values.
Definition: signalmonitorvalue.h:93
CardUtil::GetTimeouts
static bool GetTimeouts(uint inputid, std::chrono::milliseconds &signal_timeout, std::chrono::milliseconds &channel_timeout)
Definition: cardutil.cpp:2286
satiprecorder.h
SatIPSignalMonitor::Stop
void Stop(void) override
Stop signal monitoring thread.
Definition: satipsignalmonitor.cpp:56
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:56
SatIPStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: satipstreamhandler.h:30
SatIPSignalMonitor::SatIPSignalMonitor
SatIPSignalMonitor(int db_cardnum, SatIPChannel *channel, bool release_stream, uint64_t flags=0)
Definition: satipsignalmonitor.cpp:14
SatIPSignalMonitor::~SatIPSignalMonitor
~SatIPSignalMonitor() override
Definition: satipsignalmonitor.cpp:49
DTVSignalMonitor
This class is intended to detect the presence of needed tables.
Definition: dtvsignalmonitor.h:14
satipstreamhandler.h
SatIPChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: satipchannel.h:29
SatIPStreamHandler::Get
static SatIPStreamHandler * Get(const QString &devname, int inputid)
Definition: satipstreamhandler.cpp:32
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:163
SignalMonitor::Stop
virtual void Stop()
Stop signal monitoring thread.
Definition: signalmonitor.cpp:304
DTVSignalMonitor::IsAllGood
bool IsAllGood(void) const override
Definition: dtvsignalmonitor.cpp:585
SignalMonitor::kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForVCT
Definition: signalmonitor.h:182