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(GetDevice())
32 
33 HDHRChannel::HDHRChannel(TVRec *parent, const QString &device)
34  : DTVChannel(parent),
35  _device_id(device),
36  _stream_handler(nullptr)
37 {
39 }
40 
42 {
43  Close();
45 }
46 
47 bool HDHRChannel::IsMaster(void) const
48 {
50  bool is_master = (master == static_cast<const DTVChannel*>(this));
52  return is_master;
53 }
54 
56 {
57  LOG(VB_CHANNEL, LOG_INFO, LOC + "Opening HDHR channel");
58 
59  if (IsOpen())
60  return true;
61 
63  GetMajorID());
64 
66  tunerType = (_tuner_types.empty()) ?
68 
69  if (!InitializeInput())
70  {
71  Close();
72  return false;
73  }
74 
75  return _stream_handler->IsConnected();
76 }
77 
79 {
80  LOG(VB_CHANNEL, LOG_INFO, LOC + "Closing HDHR channel");
81 
82  if (!IsOpen())
83  return; // this caller didn't have it open in the first place..
84 
86 }
87 
89 {
90  Close();
91  return true;
92 }
93 
94 bool HDHRChannel::IsOpen(void) const
95 {
96  return _stream_handler;
97 }
98 
100 bool HDHRChannel::Tune(const QString &freqid, int /*finetune*/)
101 {
102  return _stream_handler->TuneVChannel(freqid);
103 }
104 
105 static QString format_modulation(const DTVMultiplex &tuning)
106 {
108  return "qam256";
109  else if (DTVModulation::kModulationQAM128 == tuning.modulation)
110  return "qam128";
111  else if (DTVModulation::kModulationQAM64 == tuning.modulation)
112  return "qam64";
113  else if (DTVModulation::kModulationQAM16 == tuning.modulation)
114  return "qam16";
115  else if (DTVModulation::kModulationDQPSK == tuning.modulation)
116  return "qpsk";
117  else if (DTVModulation::kModulation8VSB == tuning.modulation)
118  return "8vsb";
119 
120  return "auto";
121 }
122 
123 static QString format_dvbt(const DTVMultiplex &tuning, const QString &mod)
124 {
125  const QChar b = tuning.bandwidth.toChar();
126 
127  if ((QChar('a') == b) || (mod == "auto"))
128  return "auto"; // uses bandwidth from channel map
129  else if (QChar('a') != b)
130  return QString("t%1%2").arg(b).arg(mod);
131 
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.bandwidth.toChar();
138 
139  if ((QChar('a') == b) || (mod == "auto"))
140  return "auto"; // uses bandwidth from channel map
141  else if ((QChar('a') != b) && (tuning.symbolrate > 0))
142  return QString("a%1%2-%3")
143  .arg(b).arg(mod).arg(tuning.symbolrate/1000);
144 
145  return QString("auto%1c").arg(b);
146 }
147 
148 static QString get_tune_spec(
149  const DTVTunerType &tunerType, const DTVMultiplex &tuning)
150 {
151  const QString mod = format_modulation(tuning);
152 
153  if (DTVTunerType::kTunerTypeATSC == tunerType)
154  // old atsc firmware does no recognize "auto"
155  return (mod == "auto") ? "qam" : mod;
156  else if (DTVTunerType::kTunerTypeDVBC == tunerType)
157  return format_dvbc(tuning, mod);
158  else if (DTVTunerType::kTunerTypeDVBT == tunerType)
159  return format_dvbt(tuning, mod);
160 
161  return "auto";
162 }
163 
164 bool HDHRChannel::Tune(const DTVMultiplex &tuning)
165 {
166  QString spec = get_tune_spec(tunerType, tuning);
167  QString chan = QString("%1:%2").arg(spec).arg(tuning.frequency);
168 
169  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + chan);
170 
171  if (_stream_handler->TuneChannel(chan))
172  {
173  SetSIStandard(tuning.sistandard);
174  return true;
175  }
176 
177  return false;
178 }
179 
180 bool HDHRChannel::SetChannelByString(const QString &channum)
181 {
182  bool ok = DTVChannel::SetChannelByString(channum);
183 
184  // HACK HACK HACK -- BEGIN
185  // if the DTVTunerType were specified in tuning we wouldn't
186  // need to try alternative tuning...
188  {
189  bool has_dvbc = false, has_dvbt = false;
190  vector<DTVTunerType>::const_iterator it = _tuner_types.begin();
191  for (; it != _tuner_types.end(); ++it)
192  {
193  has_dvbt |= (DTVTunerType::kTunerTypeDVBT == *it);
194  has_dvbc |= (DTVTunerType::kTunerTypeDVBC == *it);
195  }
196 
197  if (has_dvbt && has_dvbc)
198  {
200  ok = DTVChannel::SetChannelByString(channum);
201  if (!ok)
202  {
204  return false;
205  }
206  }
207  }
208  // HACK HACK HACK -- END
209 
210  return ok;
211 }
void Close(void) override
Closes the channel changing hardware to use.
Definition: hdhrchannel.cpp:78
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: hdhrchannel.cpp:94
static const int kTunerTypeDVBT
static const int kTunerTypeATSC
QString _device_id
Definition: hdhrchannel.h:52
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)
DTVModulation modulation
Definition: dtvmultiplex.h:90
static QString format_dvbt(const DTVMultiplex &tuning, const QString &mod)
bool SetChannelByString(const QString &channum) override
DTVTunerType tunerType
Definition: dtvchannel.h:163
static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
HDHRStreamHandler * _stream_handler
Definition: hdhrchannel.h:53
static void Return(HDHRStreamHandler *&ref, int inputid)
unsigned char b
Definition: ParseText.cpp:340
QString sistandard
Definition: dtvmultiplex.h:101
void RegisterForMaster(const QString &key)
Definition: dtvchannel.cpp:124
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: hdhrchannel.h:35
DTVBandwidth bandwidth
Definition: dtvmultiplex.h:87
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:34
static const int kTunerTypeDVBC
vector< DTVTunerType > _tuner_types
Definition: hdhrchannel.h:54
uint64_t frequency
Definition: dtvmultiplex.h:84
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:150
static DTVChannel * GetMasterLock(const QString &key)
Definition: dtvchannel.cpp:146
#define LOC
Definition: hdhrchannel.cpp:31
QChar toChar() const
bool IsConnected(void) const
static QString get_tune_spec(const DTVTunerType &tunerType, const DTVMultiplex &tuning)
uint64_t symbolrate
Definition: dtvmultiplex.h:85
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:61
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: hdhrchannel.cpp:88
static void ReturnMasterLock(DTVChannelP &)
Definition: dtvchannel.cpp:158
virtual int GetInputID(void) const
Definition: channelbase.h:67
bool SetChannelByString(const QString &chan) override
Definition: dtvchannel.cpp:167
static QString format_modulation(const DTVMultiplex &tuning)
static HDHRStreamHandler * Get(const QString &devicename, int inputid, int majorid)
void DeregisterForMaster(const QString &key)
Definition: dtvchannel.cpp:131
bool IsMaster(void) const override
Returns true if this is the first of a number of multi-rec devs.
Definition: hdhrchannel.cpp:47
~HDHRChannel(void)
Definition: hdhrchannel.cpp:41
HDHRChannel(TVRec *parent, const QString &device)
Definition: hdhrchannel.cpp:33
bool Open(void) override
Opens the channel changing hardware for use.
Definition: hdhrchannel.cpp:55
int GetMajorID(void)
virtual bool InitializeInput(void)
Fills in input map from DB.