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_stream_handler = nullptr;
64  }
65 }
66 
68 {
69  if (m_stream_handler)
71  else
72  m_loc = GetDevice();
73 
74  return m_loc;
75 }
76 
78 {
79  if (m_stream_handler)
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_stream_handler->HasTuner())
98  return true;
99 
100  QString result;
101 
102  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + channum);
103 
104  if (!m_stream_handler->ProcessCommand("TuneChannel:" + channum, result,
105  20000))
106  {
107  LOG(VB_CHANNEL, LOG_ERR, LOC + QString
108  ("Failed to Tune %1: %2").arg(channum).arg(result));
109  return false;
110  }
111 
113 
114  return true;
115 }
116 
117 bool ExternalChannel::Tune(const QString &freqid, int /*finetune*/)
118 {
119  return ExternalChannel::Tune(freqid);
120 }
121 
123 {
124  Close();
125  return true;
126 }
bool Open(void) override
Opens the channel changing hardware for use.
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
bool Tune(const DTVMultiplex &) override
This performs the actual frequency tuning and in some cases input switching.
bool HasError(void) const
Definition: streamhandler.h:64
uint m_inputid
Definition: channelbase.h:137
QString UpdateDescription(void)
bool IsOpen(void) const override
Reports whether channel is already open.
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
ExternalStreamHandler * m_stream_handler
QString GetDescription(void)
static ExternalStreamHandler * Get(const QString &devname, int inputid, int majorid)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool ProcessCommand(const QString &cmd, QString &result, int timeout=4000, uint retry_cnt=3)
#define LOC
-*- Mode: c++ -*- Class ExternalChannel
void Close(void) override
Closes the channel changing hardware to use.
virtual int GetInputID(void) const
Definition: channelbase.h:67
static void Return(ExternalStreamHandler *&ref, int inputid)
int GetMajorID(void)
virtual bool InitializeInput(void)
Fills in input map from DB.