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  // need bandwidth to set modulation and symbol rate
138  if ((QChar('a') == b) && (mod != "auto") && (tuning.m_symbolrate > 0))
139  return QString("a8%1-%2")
140  .arg(mod).arg(tuning.m_symbolrate/1000);
141  if ((QChar('a') == b) || (mod == "auto"))
142  return "auto"; // uses bandwidth from channel map
143  if ((QChar('a') != b) && (tuning.m_symbolrate > 0))
144  return QString("a%1%2-%3")
145  .arg(b).arg(mod).arg(tuning.m_symbolrate/1000);
146  return QString("auto%1c").arg(b);
147 }
148 
149 static QString get_tune_spec(
150  const DTVTunerType &tunerType, const DTVMultiplex &tuning)
151 {
152  const QString mod = format_modulation(tuning);
153 
154  if (DTVTunerType::kTunerTypeATSC == tunerType)
155  // old atsc firmware does no recognize "auto"
156  return (mod == "auto") ? "qam" : mod;
157  if (DTVTunerType::kTunerTypeDVBC == tunerType)
158  return format_dvbc(tuning, mod);
159  if (DTVTunerType::kTunerTypeDVBT == tunerType)
160  return format_dvbt(tuning, mod);
161 
162  return "auto";
163 }
164 
165 bool HDHRChannel::Tune(const DTVMultiplex &tuning)
166 {
167  QString spec = get_tune_spec(m_tunerType, tuning);
168  QString chan = QString("%1:%2").arg(spec).arg(tuning.m_frequency);
169 
170  LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + chan);
171 
172  if (m_stream_handler->TuneChannel(chan))
173  {
174  SetSIStandard(tuning.m_sistandard);
175  return true;
176  }
177 
178  return false;
179 }
180 
181 bool HDHRChannel::SetChannelByString(const QString &channum)
182 {
183  bool ok = DTVChannel::SetChannelByString(channum);
184 
185  // HACK HACK HACK -- BEGIN
186  // if the DTVTunerType were specified in tuning we wouldn't
187  // need to try alternative tuning...
189  {
190  bool has_dvbc = false, has_dvbt = false;
191  vector<DTVTunerType>::const_iterator it = m_tuner_types.begin();
192  for (; it != m_tuner_types.end(); ++it)
193  {
194  has_dvbt |= (DTVTunerType::kTunerTypeDVBT == *it);
195  has_dvbc |= (DTVTunerType::kTunerTypeDVBC == *it);
196  }
197 
198  if (has_dvbt && has_dvbc)
199  {
201  ok = DTVChannel::SetChannelByString(channum);
202  if (!ok)
203  {
205  return false;
206  }
207  }
208  }
209  // HACK HACK HACK -- END
210 
211  return ok;
212 }
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