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