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  // When mythbackend first starts up, just retrive the
105  // tuneTimeout for subsequent tune requests.
106 
107  if (!m_streamHandler->ProcessCommand("LockTimeout?", result))
108  {
109  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
110  ("Failed to retrieve LockTimeout: %1").arg(result));
111  m_tuneTimeout = 60s;
112  }
113  else
114  m_tuneTimeout = std::chrono::milliseconds(result.split(":")[1].toInt());
115 
116  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Using Tune timeout of %1ms")
117  .arg(m_tuneTimeout.count()));
118  }
119  else
120  {
121  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + channum);
122 
123  if (!m_streamHandler->ProcessCommand("TuneChannel:" + channum,
124  result, m_tuneTimeout))
125  {
126  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
127  ("Failed to Tune %1: %2").arg(channum).arg(result));
128  return false;
129  }
130 
132  m_backgroundTuning = result.startsWith("OK:InProgress");
133  }
134 
135  return true;
136 }
137 
138 bool ExternalChannel::Tune(const QString &freqid, int /*finetune*/)
139 {
140  return ExternalChannel::Tune(freqid);
141 }
142 
144 {
145  Close();
146  return true;
147 }
148 
150 {
151 
152  if (!m_backgroundTuning)
153  return 3;
154 
155  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("GetScriptStatus() %1")
156  .arg(m_systemStatus));
157 
158  QString result;
159  int ret = 0;
160 
161  if (!m_streamHandler->ProcessCommand("TuneStatus?", result))
162  {
163  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
164  ("Failed to Tune: %1").arg(result));
165  ret = 2;
166  m_backgroundTuning = false;
167  }
168  else
169  {
170  if (result.startsWith("OK:InProgress"))
171  ret = 1;
172  else
173  {
174  ret = 3;
175  m_backgroundTuning = false;
177  }
178  }
179 
180  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("GetScriptStatus() %1 -> %2")
181  .arg(m_systemStatus). arg(ret));
182 
183  return ret;
184 }
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:63
ExternalChannel::m_loc
QString m_loc
Definition: ExternalChannel.h:61
arg
arg(title).arg(filename).arg(doDelete))
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:886
ExternalStreamHandler::IsAppOpen
bool IsAppOpen(void)
Definition: ExternalStreamHandler.cpp:994
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:149
ExternalChannel::EnterPowerSavingMode
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: ExternalChannel.cpp:143
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:1226
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:851
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:484
ExternalStreamHandler::GetDescription
QString GetDescription(void)
Definition: ExternalStreamHandler.h:79