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  return false;
49  }
50 
52  LOG(VB_RECORD, LOG_INFO, LOC + "Opened");
53  return true;
54 }
55 
57 {
58  LOG(VB_CHANNEL, LOG_INFO, LOC + "Close()");
59 
61  {
63  m_streamHandler = nullptr;
64  }
65 }
66 
68 {
69  if (m_streamHandler)
71  else
72  m_loc = GetDevice();
73 
74  return m_loc;
75 }
76 
78 {
79  if (m_streamHandler)
81  else
82  m_loc = GetDevice();
83 
84  return m_loc;
85 }
86 
87 bool ExternalChannel::Tune(const QString &channum)
88 {
89  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Tune(%1)").arg(channum));
90 
91  if (!IsOpen())
92  {
93  LOG(VB_CHANNEL, LOG_ERR, LOC + "Tune failed, not open");
94  return false;
95  }
96 
97  if (!m_streamHandler->HasTuner())
98  return true;
99 
100  QString result;
101  if (m_tuneTimeout < 0)
102  {
103  // When mythbackend first starts up, just retrive the
104  // tuneTimeout for subsequent tune requests.
105 
106  if (!m_streamHandler->ProcessCommand("LockTimeout?", result))
107  {
108  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
109  ("Failed to retrieve LockTimeout: %1").arg(result));
110  m_tuneTimeout = 60000;
111  }
112  else
113  m_tuneTimeout = result.split(":")[1].toInt();
114 
115  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Using Tune timeout of %1ms")
116  .arg(m_tuneTimeout));
117  }
118  else
119  {
120  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + channum);
121 
122  if (!m_streamHandler->ProcessCommand("TuneChannel:" + channum,
123  result, m_tuneTimeout))
124  {
125  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
126  ("Failed to Tune %1: %2").arg(channum).arg(result));
127  return false;
128  }
129 
131  m_backgroundTuning = result.startsWith("OK:InProgress");
132  }
133 
134  return true;
135 }
136 
137 bool ExternalChannel::Tune(const QString &freqid, int /*finetune*/)
138 {
139  return ExternalChannel::Tune(freqid);
140 }
141 
143 {
144  Close();
145  return true;
146 }
147 
149 {
150 
151  if (!m_backgroundTuning)
152  return 3;
153 
154  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("GetScriptStatus() %1")
155  .arg(m_systemStatus));
156 
157  QString result;
158  int ret = 0;
159 
160  if (!m_streamHandler->ProcessCommand("TuneStatus?", result))
161  {
162  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
163  ("Failed to Tune: %1").arg(result));
164  ret = 2;
165  m_backgroundTuning = false;
166  }
167  else
168  {
169  if (result.startsWith("OK:InProgress"))
170  ret = 1;
171  else
172  {
173  ret = 3;
174  m_backgroundTuning = false;
176  }
177  }
178 
179  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("GetScriptStatus() %1 -> %2")
180  .arg(m_systemStatus). arg(ret));
181 
182  return ret;
183 }
ExternalStreamHandler::ProcessCommand
bool ProcessCommand(const QString &cmd, QString &result, int timeout=4000, uint retry_cnt=3)
Definition: ExternalStreamHandler.cpp:1227
LOC
#define LOC
-*- Mode: c++ -*- Class ExternalChannel
Definition: ExternalChannel.cpp:11
ExternalChannel::GetDescription
QString GetDescription(void)
Definition: ExternalChannel.cpp:77
StreamHandler::HasError
bool HasError(void) const
Definition: streamhandler.h:64
ExternalChannel::m_loc
QString m_loc
Definition: ExternalChannel.h:62
arg
arg(title).arg(filename).arg(doDelete))
ExternalStreamHandler::HasTuner
bool HasTuner(void) const
Definition: ExternalStreamHandler.h:84
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:61
ExternalChannel::Close
void Close(void) override
Closes the channel changing hardware to use.
Definition: ExternalChannel.cpp:56
ExternalChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: ExternalChannel.h:42
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:887
ExternalStreamHandler::IsAppOpen
bool IsAppOpen(void)
Definition: ExternalStreamHandler.cpp:995
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:148
ExternalChannel::EnterPowerSavingMode
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: ExternalChannel.cpp:142
ExternalChannel.h
ExternalChannel::~ExternalChannel
~ExternalChannel(void) override
Definition: ExternalChannel.cpp:13
ExternalChannel::m_backgroundTuning
bool m_backgroundTuning
Definition: ExternalChannel.h:58
tv_rec.h
ChannelBase::GetInputID
virtual int GetInputID(void) const
Definition: channelbase.h:67
ExternalChannel::UpdateDescription
QString UpdateDescription(void)
Definition: ExternalChannel.cpp:67
ExternalChannel::Tune
virtual bool Tune(const DTVMultiplex &tuning)=0
This performs the actual frequency tuning and in some cases input switching.
ExternalChannel::IsOpen
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: ExternalChannel.h:40
ExternalChannel::m_device
QString m_device
Definition: ExternalChannel.h:59
ChannelBase::GetMajorID
int GetMajorID(void)
Definition: channelbase.cpp:857
ChannelBase::InitializeInput
virtual bool InitializeInput(void)
Fills in input map from DB.
Definition: channelbase.cpp:547
ExternalStreamHandler::Return
static void Return(ExternalStreamHandler *&ref, int inputid)
Definition: ExternalStreamHandler.cpp:484
ExternalStreamHandler::GetDescription
QString GetDescription(void)
Definition: ExternalStreamHandler.h:80
ExternalChannel::m_tuneTimeout
int m_tuneTimeout
Definition: ExternalChannel.h:57