MythTV  master
hdhrchannel.cpp
Go to the documentation of this file.
1 
7 // C includes
8 #include <unistd.h>
9 #include <sys/types.h>
10 #ifndef _WIN32
11 #include <sys/socket.h>
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
14 #include <netdb.h>
15 #endif
16 #include <sys/time.h>
17 #include <fcntl.h>
18 
19 // C++ includes
20 #include <algorithm>
21 #include <utility>
22 
23 using namespace std;
24 
25 // MythTV includes
26 #include "mythdbcon.h"
27 #include "mythlogging.h"
28 #include "hdhrchannel.h"
29 #include "videosource.h"
30 #include "channelutil.h"
31 #include "hdhrstreamhandler.h"
32 
33 #define LOC QString("HDHRChan[%1](%2): ").arg(m_inputId).arg(HDHRChannel::GetDevice())
34 
35 HDHRChannel::HDHRChannel(TVRec *parent, QString device)
36  : DTVChannel(parent),
37  m_deviceId(std::move(device))
38 {
40 }
41 
43 {
46 }
47 
48 bool HDHRChannel::IsMaster(void) const
49 {
51  bool is_master = (master == static_cast<const DTVChannel*>(this));
53  return is_master;
54 }
55 
57 {
58  LOG(VB_CHANNEL, LOG_INFO, LOC + "Opening HDHR channel");
59 
60  if (IsOpen())
61  return true;
62 
64  GetMajorID());
65 
67  m_tunerType = (m_tunerTypes.empty()) ?
69 
70  if (!InitializeInput())
71  {
72  Close();
73  return false;
74  }
75 
76  return m_streamHandler->IsConnected();
77 }
78 
80 {
81  LOG(VB_CHANNEL, LOG_INFO, LOC + "Closing HDHR channel");
82 
83  if (!HDHRChannel::IsOpen())
84  return; // this caller didn't have it open in the first place..
85 
87 }
88 
90 {
91  Close();
92  return true;
93 }
94 
95 bool HDHRChannel::IsOpen(void) const
96 {
97  return m_streamHandler;
98 }
99 
101 bool HDHRChannel::Tune(const QString &freqid, int /*finetune*/)
102 {
103  return m_streamHandler->TuneVChannel(freqid);
104 }
105 
106 static QString format_modulation(const DTVMultiplex &tuning)
107 {
109  return "qam256";
111  return "qam128";
113  return "qam64";
115  return "qam16";
117  return "qpsk";
119  return "8vsb";
120 
121  return "auto";
122 }
123 
124 static QString format_dvbt(const DTVMultiplex &tuning, const QString &mod)
125 {
126  const QChar b = tuning.m_bandwidth.toChar();
127 
128  if ((QChar('a') == b) || (mod == "auto"))
129  return "auto"; // uses bandwidth from channel map
130  if (QChar('a') != b)
131  return QString("t%1%2").arg(b).arg(mod);
132  return QString("auto%1t").arg(b);
133 }
134 
135 static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
136 {
137  const QChar b = tuning.m_bandwidth.toChar();
138 
139  // need bandwidth to set modulation and symbol rate
140  if ((QChar('a') == b) && (mod != "auto") && (tuning.m_symbolRate > 0))
141  return QString("a8%1-%2")
142  .arg(mod).arg(tuning.m_symbolRate/1000);
143  if ((QChar('a') == b) || (mod == "auto"))
144  return "auto"; // uses bandwidth from channel map
145  if ((QChar('a') != b) && (tuning.m_symbolRate > 0))
146  return QString("a%1%2-%3")
147  .arg(b).arg(mod).arg(tuning.m_symbolRate/1000);
148  return QString("auto%1c").arg(b);
149 }
150 
151 static QString get_tune_spec(
152  const DTVTunerType &tunerType, const DTVMultiplex &tuning)
153 {
154  const QString mod = format_modulation(tuning);
155 
156  if (DTVTunerType::kTunerTypeATSC == tunerType)
157  // old atsc firmware does no recognize "auto"
158  return (mod == "auto") ? "qam" : mod;
159  if (DTVTunerType::kTunerTypeDVBC == tunerType)
160  return format_dvbc(tuning, mod);
161  if (DTVTunerType::kTunerTypeDVBT == tunerType)
162  return format_dvbt(tuning, mod);
163 
164  return "auto";
165 }
166 
167 bool HDHRChannel::Tune(const DTVMultiplex &tuning)
168 {
169  QString spec = get_tune_spec(m_tunerType, tuning);
170  QString chan = QString("%1:%2").arg(spec).arg(tuning.m_frequency);
171 
172  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + chan);
173 
174  if (m_streamHandler->TuneChannel(chan))
175  {
176  SetSIStandard(tuning.m_sistandard);
177  return true;
178  }
179 
180  return false;
181 }
182 
183 bool HDHRChannel::SetChannelByString(const QString &channum)
184 {
185  bool ok = DTVChannel::SetChannelByString(channum);
186 
187  // HACK HACK HACK -- BEGIN
188  // if the DTVTunerType were specified in tuning we wouldn't
189  // need to try alternative tuning...
191  {
192  bool has_dvbc = false;
193  bool has_dvbt = false;
194  for (auto type : m_tunerTypes)
195  {
196  has_dvbt |= (DTVTunerType::kTunerTypeDVBT == type);
197  has_dvbc |= (DTVTunerType::kTunerTypeDVBC == type);
198  }
199 
200  if (has_dvbt && has_dvbc)
201  {
203  ok = DTVChannel::SetChannelByString(channum);
204  if (!ok)
205  {
207  return false;
208  }
209  }
210  }
211  // HACK HACK HACK -- END
212 
213  return ok;
214 }
void Close(void) override
Closes the channel changing hardware to use.
Definition: hdhrchannel.cpp:79
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: hdhrchannel.cpp:95
vector< DTVTunerType > m_tunerTypes
Definition: hdhrchannel.h:54
uint64_t m_symbolRate
Definition: dtvmultiplex.h:95
static const int kTunerTypeDVBT
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
~HDHRChannel(void) override
Definition: hdhrchannel.cpp:42
static const int kTunerTypeATSC
static const int kTunerTypeUnknown
bool Tune(const DTVMultiplex &tuning) override
This performs the actual frequency tuning and in some cases input switching.
vector< DTVTunerType > GetTunerTypes(void) const
bool TuneVChannel(const QString &vchn)
HDHRStreamHandler * m_streamHandler
Definition: hdhrchannel.h:53
static QString format_dvbt(const DTVMultiplex &tuning, const QString &mod)
DTVTunerType m_tunerType
Definition: dtvchannel.h:163
bool SetChannelByString(const QString &channum) override
static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
static void Return(HDHRStreamHandler *&ref, int inputid)
void RegisterForMaster(const QString &key)
Definition: dtvchannel.cpp:113
DTVModulation m_modulation
Definition: dtvmultiplex.h:100
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: hdhrchannel.h:35
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:34
static const int kTunerTypeDVBC
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
static DTVChannel * GetMasterLock(const QString &key)
Definition: dtvchannel.cpp:135
#define LOC
Definition: hdhrchannel.cpp:33
QChar toChar() const
bool IsConnected(void) const
static QString get_tune_spec(const DTVTunerType &tunerType, const DTVMultiplex &tuning)
QString m_sistandard
Definition: dtvmultiplex.h:111
bool TuneChannel(const QString &chanid)
void SetSIStandard(const QString &si_std)
Sets PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:50
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: hdhrchannel.cpp:89
static void ReturnMasterLock(DTVChannelP &chan)
Definition: dtvchannel.cpp:147
virtual int GetInputID(void) const
Definition: channelbase.h:67
bool SetChannelByString(const QString &chan) override
Definition: dtvchannel.cpp:156
static QString format_modulation(const DTVMultiplex &tuning)
void DeregisterForMaster(const QString &key)
Definition: dtvchannel.cpp:120
HDHRChannel(TVRec *parent, QString device)
Definition: hdhrchannel.cpp:35
bool IsMaster(void) const override
Returns true if this is the first of a number of multi-rec devs.
Definition: hdhrchannel.cpp:48
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
QString m_deviceId
Definition: hdhrchannel.h:52
bool Open(void) override
Opens the channel changing hardware for use.
Definition: hdhrchannel.cpp:56
int GetMajorID(void)
virtual bool InitializeInput(void)
Fills in input map from DB.
uint64_t m_frequency
Definition: dtvmultiplex.h:94
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23