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 using namespace std;
22 
23 // MythTV includes
24 #include "mythdbcon.h"
25 #include "mythlogging.h"
26 #include "hdhrchannel.h"
27 #include "videosource.h"
28 #include "channelutil.h"
29 #include "hdhrstreamhandler.h"
30 
31 #define LOC QString("HDHRChan[%1](%2): ").arg(m_inputid).arg(HDHRChannel::GetDevice())
32 
33 HDHRChannel::HDHRChannel(TVRec *parent, const QString &device)
34  : DTVChannel(parent),
35  m_device_id(device)
36 {
38 }
39 
41 {
44 }
45 
46 bool HDHRChannel::IsMaster(void) const
47 {
49  bool is_master = (master == static_cast<const DTVChannel*>(this));
51  return is_master;
52 }
53 
55 {
56  LOG(VB_CHANNEL, LOG_INFO, LOC + "Opening HDHR channel");
57 
58  if (IsOpen())
59  return true;
60 
62  GetMajorID());
63 
65  m_tunerType = (m_tuner_types.empty()) ?
67 
68  if (!InitializeInput())
69  {
70  Close();
71  return false;
72  }
73 
74  return m_stream_handler->IsConnected();
75 }
76 
78 {
79  LOG(VB_CHANNEL, LOG_INFO, LOC + "Closing HDHR channel");
80 
81  if (!HDHRChannel::IsOpen())
82  return; // this caller didn't have it open in the first place..
83 
85 }
86 
88 {
89  Close();
90  return true;
91 }
92 
93 bool HDHRChannel::IsOpen(void) const
94 {
95  return m_stream_handler;
96 }
97 
99 bool HDHRChannel::Tune(const QString &freqid, int /*finetune*/)
100 {
101  return m_stream_handler->TuneVChannel(freqid);
102 }
103 
104 static QString format_modulation(const DTVMultiplex &tuning)
105 {
107  return "qam256";
109  return "qam128";
111  return "qam64";
113  return "qam16";
115  return "qpsk";
117  return "8vsb";
118 
119  return "auto";
120 }
121 
122 static QString format_dvbt(const DTVMultiplex &tuning, const QString &mod)
123 {
124  const QChar b = tuning.m_bandwidth.toChar();
125 
126  if ((QChar('a') == b) || (mod == "auto"))
127  return "auto"; // uses bandwidth from channel map
128  if (QChar('a') != b)
129  return QString("t%1%2").arg(b).arg(mod);
130  return QString("auto%1t").arg(b);
131 }
132 
133 static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
134 {
135  const QChar b = tuning.m_bandwidth.toChar();
136 
137  if ((QChar('a') == b) || (mod == "auto"))
138  return "auto"; // uses bandwidth from channel map
139  if ((QChar('a') != b) && (tuning.m_symbolrate > 0))
140  return QString("a%1%2-%3")
141  .arg(b).arg(mod).arg(tuning.m_symbolrate/1000);
142  return QString("auto%1c").arg(b);
143 }
144 
145 static QString get_tune_spec(
146  const DTVTunerType &tunerType, const DTVMultiplex &tuning)
147 {
148  const QString mod = format_modulation(tuning);
149 
150  if (DTVTunerType::kTunerTypeATSC == tunerType)
151  // old atsc firmware does no recognize "auto"
152  return (mod == "auto") ? "qam" : mod;
153  if (DTVTunerType::kTunerTypeDVBC == tunerType)
154  return format_dvbc(tuning, mod);
155  if (DTVTunerType::kTunerTypeDVBT == tunerType)
156  return format_dvbt(tuning, mod);
157 
158  return "auto";
159 }
160 
161 bool HDHRChannel::Tune(const DTVMultiplex &tuning)
162 {
163  QString spec = get_tune_spec(m_tunerType, tuning);
164  QString chan = QString("%1:%2").arg(spec).arg(tuning.m_frequency);
165 
166  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + chan);
167 
168  if (m_stream_handler->TuneChannel(chan))
169  {
170  SetSIStandard(tuning.m_sistandard);
171  return true;
172  }
173 
174  return false;
175 }
176 
177 bool HDHRChannel::SetChannelByString(const QString &channum)
178 {
179  bool ok = DTVChannel::SetChannelByString(channum);
180 
181  // HACK HACK HACK -- BEGIN
182  // if the DTVTunerType were specified in tuning we wouldn't
183  // need to try alternative tuning...
185  {
186  bool has_dvbc = false, has_dvbt = false;
187  vector<DTVTunerType>::const_iterator it = m_tuner_types.begin();
188  for (; it != m_tuner_types.end(); ++it)
189  {
190  has_dvbt |= (DTVTunerType::kTunerTypeDVBT == *it);
191  has_dvbc |= (DTVTunerType::kTunerTypeDVBC == *it);
192  }
193 
194  if (has_dvbt && has_dvbc)
195  {
197  ok = DTVChannel::SetChannelByString(channum);
198  if (!ok)
199  {
201  return false;
202  }
203  }
204  }
205  // HACK HACK HACK -- END
206 
207  return ok;
208 }
void Close(void) override
Closes the channel changing hardware to use.
Definition: hdhrchannel.cpp:77
uint64_t m_symbolrate
Definition: dtvmultiplex.h:95
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: hdhrchannel.cpp:93
static const int kTunerTypeDVBT
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
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)
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)
unsigned char b
Definition: ParseText.cpp:329
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:150
HDHRStreamHandler * m_stream_handler
Definition: hdhrchannel.h:53
static DTVChannel * GetMasterLock(const QString &key)
Definition: dtvchannel.cpp:135
#define LOC
Definition: hdhrchannel.cpp:31
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
vector< DTVTunerType > m_tuner_types
Definition: hdhrchannel.h:54
bool TuneChannel(const QString &chanid)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetSIStandard(const QString &)
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:87
static void ReturnMasterLock(DTVChannelP &)
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
bool IsMaster(void) const override
Returns true if this is the first of a number of multi-rec devs.
Definition: hdhrchannel.cpp:46
~HDHRChannel(void)
Definition: hdhrchannel.cpp:40
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
HDHRChannel(TVRec *parent, const QString &device)
Definition: hdhrchannel.cpp:33
bool Open(void) override
Opens the channel changing hardware for use.
Definition: hdhrchannel.cpp:54
int GetMajorID(void)
virtual bool InitializeInput(void)
Fills in input map from DB.
uint64_t m_frequency
Definition: dtvmultiplex.h:94
QString m_device_id
Definition: hdhrchannel.h:52