MythTV  master
ExternalChannel.cpp
Go to the documentation of this file.
1 
5 // MythTV includes
6 #include "mythlogging.h"
7 #include "mpegtables.h"
8 #include "ExternalChannel.h"
9 #include "tv_rec.h"
10 
11 #define LOC QString("ExternChan[%1](%2): ").arg(m_inputId).arg(m_loc)
12 
14 {
17 }
18 
20 {
21  LOG(VB_CHANNEL, LOG_INFO, LOC + "Open()");
22 
23  if (m_device.isEmpty())
24  return false;
25 
26  if (IsOpen())
27  {
29  return true;
30 
31  LOG(VB_GENERAL, LOG_ERR, LOC +
32  QString("Valid stream handler, but app is not open! Resetting."));
33  Close();
34  }
35 
36 
37  if (!InitializeInput())
38  return false;
39 
40  if (!m_inputId)
41  return false;
42 
44  GetMajorID());
46  {
47  LOG(VB_GENERAL, LOG_ERR, LOC + "Open failed");
48  Close();
49  return false;
50  }
51 
53  LOG(VB_RECORD, LOG_INFO, LOC + "Opened");
54  return true;
55 }
56 
58 {
59  LOG(VB_CHANNEL, LOG_INFO, LOC + "Close()");
60 
62  {
64  m_streamHandler = nullptr;
65  }
66 }
67 
69 {
70  if (m_streamHandler)
72  else
73  m_loc = GetDevice();
74 
75  return m_loc;
76 }
77 
79 {
80  if (m_streamHandler)
82  else
83  m_loc = GetDevice();
84 
85  return m_loc;
86 }
87 
88 bool ExternalChannel::Tune(const QString &channum)
89 {
90  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Tune(%1)").arg(channum));
91 
92  if (!IsOpen())
93  {
94  LOG(VB_CHANNEL, LOG_ERR, LOC + "Tune failed, not open");
95  return false;
96  }
97 
98  if (!m_streamHandler->HasTuner())
99  return true;
100 
101  QString result;
102  if (m_tuneTimeout < 0ms)
103  {
104  if (!m_streamHandler->ProcessCommand("LockTimeout?", result))
105  {
106  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
107  ("Failed to retrieve LockTimeout: %1").arg(result));
108  m_tuneTimeout = 60s;
109  }
110  else
111  m_tuneTimeout = std::chrono::milliseconds(result.split(":")[1].toInt());
112 
113  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Using Tune timeout of %1ms")
114  .arg(m_tuneTimeout.count()));
115  }
116 
117  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + channum);
118 
119  if (!m_streamHandler->ProcessCommand("TuneChannel:" + channum,
120  result, m_tuneTimeout))
121  {
122  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
123  ("Failed to Tune %1: %2").arg(channum).arg(result));
124  return false;
125  }
126 
128  m_backgroundTuning = result.startsWith("OK:InProgress");
129 
130  return true;
131 }
132 
133 bool ExternalChannel::Tune(const QString &freqid, int /*finetune*/)
134 {
135  return ExternalChannel::Tune(freqid);
136 }
137 
139 {
140  Close();
141  return true;
142 }
143 
145 {
146 
147  if (!m_backgroundTuning)
148  return 3;
149 
150  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("GetScriptStatus() %1")
151  .arg(m_systemStatus));
152 
153  QString result;
154  int ret = 0;
155 
156  if (!m_streamHandler->ProcessCommand("TuneStatus?", result))
157  {
158  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
159  ("Failed to Tune: %1").arg(result));
160  ret = 2;
161  m_backgroundTuning = false;
162  }
163  else
164  {
165  if (result.startsWith("OK:InProgress"))
166  ret = 1;
167  else
168  {
169  ret = 3;
170  m_backgroundTuning = false;
172  }
173  }
174 
175  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("GetScriptStatus() %1 -> %2")
176  .arg(m_systemStatus). arg(ret));
177 
178  return ret;
179 }
LOC
#define LOC
-*- Mode: c++ -*- Class ExternalChannel
Definition: ExternalChannel.cpp:11
ExternalChannel::GetDescription
QString GetDescription(void)
Definition: ExternalChannel.cpp:78
StreamHandler::HasError
bool HasError(void) const
Definition: streamhandler.h:66
ExternalChannel::m_loc
QString m_loc
Definition: ExternalChannel.h:61
ExternalStreamHandler::HasTuner
bool HasTuner(void) const
Definition: ExternalStreamHandler.h:83
ChannelBase::m_inputId
uint m_inputId
Definition: channelbase.h:137
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
ExternalChannel::m_streamHandler
ExternalStreamHandler * m_streamHandler
Definition: ExternalChannel.h:60
ExternalChannel::Close
void Close(void) override
Closes the channel changing hardware to use.
Definition: ExternalChannel.cpp:57
ExternalChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: ExternalChannel.h:41
mythlogging.h
ExternalStreamHandler::Get
static ExternalStreamHandler * Get(const QString &devname, int inputid, int majorid)
Definition: ExternalStreamHandler.cpp:455
mpegtables.h
ExternalChannel::Open
bool Open(void) override
Opens the channel changing hardware for use.
Definition: ExternalChannel.cpp:19
uint
unsigned int uint
Definition: compat.h:140
ExternalStreamHandler::UpdateDescription
QString UpdateDescription(void)
Definition: ExternalStreamHandler.cpp:891
ExternalStreamHandler::IsAppOpen
bool IsAppOpen(void)
Definition: ExternalStreamHandler.cpp:999
ExternalChannel::Tune
bool Tune(const DTVMultiplex &) override
This performs the actual frequency tuning and in some cases input switching.
Definition: ExternalChannel.h:31
ChannelBase::m_systemStatus
uint m_systemStatus
These get mapped from the GENERIC_EXIT_* to these values for use with the signalmonitor code.
Definition: channelbase.h:150
ExternalChannel::GetTuneStatus
uint GetTuneStatus(void)
Definition: ExternalChannel.cpp:144
ExternalChannel::EnterPowerSavingMode
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: ExternalChannel.cpp:138
ExternalChannel.h
ExternalChannel::~ExternalChannel
~ExternalChannel(void) override
Definition: ExternalChannel.cpp:13
ExternalChannel::m_tuneTimeout
std::chrono::milliseconds m_tuneTimeout
Definition: ExternalChannel.h:56
ExternalChannel::m_backgroundTuning
bool m_backgroundTuning
Definition: ExternalChannel.h:57
ExternalStreamHandler::ProcessCommand
bool ProcessCommand(const QString &cmd, QString &result, std::chrono::milliseconds timeout=4s, uint retry_cnt=3)
Definition: ExternalStreamHandler.cpp:1231
tv_rec.h
ChannelBase::GetInputID
virtual int GetInputID(void) const
Definition: channelbase.h:67
ExternalChannel::UpdateDescription
QString UpdateDescription(void)
Definition: ExternalChannel.cpp:68
ExternalChannel::IsOpen
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: ExternalChannel.h:39
ExternalChannel::m_device
QString m_device
Definition: ExternalChannel.h:58
ChannelBase::GetMajorID
int GetMajorID(void)
Definition: channelbase.cpp:852
ChannelBase::InitializeInput
virtual bool InitializeInput(void)
Fills in input map from DB.
Definition: channelbase.cpp:541
ExternalStreamHandler::Return
static void Return(ExternalStreamHandler *&ref, int inputid)
Definition: ExternalStreamHandler.cpp:486
ExternalStreamHandler::GetDescription
QString GetDescription(void)
Definition: ExternalStreamHandler.h:79