MythTV  master
satipsignalmonitor.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2006, Daniel Thor Kristjansson
3 
4 #include "mythlogging.h"
5 #include "mythdbcon.h"
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 
23  m_signalStrength.SetRange(0, 255);
24  m_signalStrength.SetTimeout(3s); // TODO Use value from database
25 
27 
29 }
30 
32 {
33  LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
36 }
37 
39 {
40  LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- begin");
42  if (GetStreamData())
43  {
45  }
46  m_streamHandlerStarted = false;
47 
48  LOG(VB_CHANNEL, LOG_INFO, LOC + "Stop() -- end");
49 }
50 
52 {
53  return dynamic_cast<SatIPChannel*>(m_channel);
54 }
55 
57 {
58  if (!m_running || m_exit)
59  return;
60 
62  {
63  if (!m_streamHandler->IsRunning())
64  {
65  m_error = tr("Error: stream handler died");
66  m_updateDone = true;
67  return;
68  }
69 
70  EmitStatus();
71  if (IsAllGood())
72  {
74  }
75 
76  // Update signal status
77  int signalStrength = m_streamHandler->m_rtsp->GetSignalStrength();
78  m_signalStrength.SetValue(signalStrength);
79 
80  m_updateDone = true;
81  return;
82  }
83 
84  // Update signal status
85  bool wasLocked = false;
86  bool isLocked = false;
87  {
88  QMutexLocker locker(&m_statusLock);
89  int signalStrength = m_streamHandler->m_rtsp->GetSignalStrength();
90  bool hasLock = m_streamHandler->m_rtsp->HasLock();
91  m_signalStrength.SetValue(signalStrength);
92  wasLocked = m_signalLock.IsGood();
93  m_signalLock.SetValue(hasLock);
94  isLocked = m_signalLock.IsGood();
95  }
96 
97  // Signal lock change
98  if (wasLocked != isLocked)
99  {
100  LOG(VB_CHANNEL, LOG_INFO, LOC + "UpdateValues -- Signal " +
101  (isLocked ? "Locked" : "Lost"));
102  }
103 
104 
105  EmitStatus();
106  if (IsAllGood())
107  {
109  }
110 
111  // Start table monitoring if we are waiting on any table and we have a lock.
112  if (isLocked && GetStreamData() &&
116  {
118  m_streamHandlerStarted = true;
119  }
120 
121  m_updateDone = true;
122 }
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
SatIPRTSP::GetSignalStrength
int GetSignalStrength()
Definition: satiprtsp.cpp:253
SignalMonitor::m_channel
ChannelBase * m_channel
Definition: signalmonitor.h:205
SignalMonitor::kDTVSigMon_WaitForMGT
static const uint64_t kDTVSigMon_WaitForMGT
Definition: signalmonitor.h:185
SignalMonitor::m_exit
volatile bool m_exit
Definition: signalmonitor.h:229
mythdbcon.h
DTVSignalMonitor::GetStreamData
MPEGStreamData * GetStreamData()
Returns the MPEG stream data if it exists.
Definition: dtvsignalmonitor.h:59
SatIPStreamHandler::m_rtsp
SatIPRTSP * m_rtsp
Definition: satipstreamhandler.h:81
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
SignalMonitor::m_running
volatile bool m_running
Definition: signalmonitor.h:228
satipchannel.h
SignalMonitor::HasAnyFlag
bool HasAnyFlag(uint64_t _flags) const
Definition: signalmonitor.cpp:282
SatIPSignalMonitor::m_streamHandlerStarted
bool m_streamHandlerStarted
Definition: satipsignalmonitor.h:25
SignalMonitor::kSigMon_WaitForSig
static const uint64_t kSigMon_WaitForSig
Definition: signalmonitor.h:189
SignalMonitor::m_error
QString m_error
Definition: signalmonitor.h:218
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:78
SignalMonitor::m_statusLock
QRecursiveMutex m_statusLock
Definition: signalmonitor.h:234
SatIPSignalMonitor::m_streamHandler
SatIPStreamHandler * m_streamHandler
Definition: satipsignalmonitor.h:26
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:221
mythlogging.h
SignalMonitor::m_inputid
int m_inputid
Definition: signalmonitor.h:207
SatIPStreamHandler::Return
static void Return(SatIPStreamHandler *&ref, int inputid)
Definition: satipstreamhandler.cpp:61
SignalMonitor::m_signalLock
SignalMonitorValue m_signalLock
Definition: signalmonitor.h:220
SignalMonitor::SendMessageAllGood
void SendMessageAllGood(void)
Definition: signalmonitor.cpp:467
SatIPRTSP::HasLock
bool HasLock()
Definition: satiprtsp.cpp:247
SignalMonitor::kDTVSigMon_WaitForPMT
static const uint64_t kDTVSigMon_WaitForPMT
Definition: signalmonitor.h:184
SignalMonitor::kDTVSigMon_WaitForPAT
static const uint64_t kDTVSigMon_WaitForPAT
Definition: signalmonitor.h:183
SignalMonitor::m_updateDone
bool m_updateDone
Definition: signalmonitor.h:212
SignalMonitor::kDTVSigMon_WaitForNIT
static const uint64_t kDTVSigMon_WaitForNIT
Definition: signalmonitor.h:187
SignalMonitor::EmitStatus
virtual void EmitStatus(void)
Definition: signalmonitor.cpp:474
SignalMonitor::kDTVSigMon_WaitForSDT
static const uint64_t kDTVSigMon_WaitForSDT
Definition: signalmonitor.h:188
SatIPSignalMonitor::GetSatIPChannel
SatIPChannel * GetSatIPChannel(void)
Definition: satipsignalmonitor.cpp:51
satipsignalmonitor.h
SatIPSignalMonitor::UpdateValues
void UpdateValues(void) override
This should be overridden to actually do signal monitoring.
Definition: satipsignalmonitor.cpp:56
SignalMonitorValue::SetRange
void SetRange(int _min, int _max)
Sets the minimum and maximum values.
Definition: signalmonitorvalue.h:93
satiprecorder.h
SatIPSignalMonitor::Stop
void Stop(void) override
Stop signal monitoring thread.
Definition: satipsignalmonitor.cpp:38
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:38
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:31
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:28
SatIPStreamHandler::Get
static SatIPStreamHandler * Get(const QString &devname, int inputid)
Definition: satipstreamhandler.cpp:30
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:161
SignalMonitor::Stop
virtual void Stop()
Stop signal monitoring thread.
Definition: signalmonitor.cpp:306
DTVSignalMonitor::IsAllGood
bool IsAllGood(void) const override
Definition: dtvsignalmonitor.cpp:580
SignalMonitor::kDTVSigMon_WaitForVCT
static const uint64_t kDTVSigMon_WaitForVCT
Definition: signalmonitor.h:186