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 // 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, QString device)
34  : DTVChannel(parent),
35  m_deviceId(std::move(device))
36 {
38 }
39 
41 {
44 }
45 
46 bool HDHRChannel::IsMaster(void) const
47 {
49  bool is_master = (master == 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_tunerTypes.empty()) ?
67 
68  if (!InitializeInput())
69  {
70  Close();
71  return false;
72  }
73 
74  return m_streamHandler->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_streamHandler;
96 }
97 
99 bool HDHRChannel::Tune(const QString &freqid, int /*finetune*/)
100 {
101  return m_streamHandler->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_streamHandler->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;
191  bool has_dvbt = false;
192  for (auto type : m_tunerTypes)
193  {
194  has_dvbt |= (DTVTunerType::kTunerTypeDVBT == type);
195  has_dvbc |= (DTVTunerType::kTunerTypeDVBC == type);
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 }
DTVMultiplex::m_frequency
uint64_t m_frequency
Definition: dtvmultiplex.h:94
DTVMultiplex
Definition: dtvmultiplex.h:25
HDHRChannel::m_tunerTypes
std::vector< DTVTunerType > m_tunerTypes
Definition: hdhrchannel.h:54
DTVChannel::RegisterForMaster
void RegisterForMaster(const QString &key)
Definition: dtvchannel.cpp:113
DTVChannel::ReturnMasterLock
static void ReturnMasterLock(DTVChannelP &chan)
Definition: dtvchannel.cpp:147
DTVTunerType::kTunerTypeDVBC
static const int kTunerTypeDVBC
Definition: dtvconfparserhelpers.h:95
HDHRChannel::Open
bool Open(void) override
Opens the channel changing hardware for use.
Definition: hdhrchannel.cpp:54
HDHRChannel::IsOpen
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: hdhrchannel.cpp:93
HDHRChannel::~HDHRChannel
~HDHRChannel(void) override
Definition: hdhrchannel.cpp:40
HDHRChannel::Close
void Close(void) override
Closes the channel changing hardware to use.
Definition: hdhrchannel.cpp:77
mythdbcon.h
DTVChannel::SetChannelByString
bool SetChannelByString(const QString &chan) override
Definition: dtvchannel.cpp:156
DTVChannel::DeregisterForMaster
void DeregisterForMaster(const QString &key)
Definition: dtvchannel.cpp:120
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DTVChannel::GetMasterLock
static DTVChannel * GetMasterLock(const QString &key)
Definition: dtvchannel.cpp:135
DTVMultiplex::m_bandwidth
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
HDHRStreamHandler::TuneVChannel
bool TuneVChannel(const QString &vchn)
Definition: hdhrstreamhandler.cpp:541
HDHRChannel::m_streamHandler
HDHRStreamHandler * m_streamHandler
Definition: hdhrchannel.h:53
DTVModulation::kModulationDQPSK
@ kModulationDQPSK
Definition: dtvconfparserhelpers.h:368
HDHRStreamHandler::GetTunerTypes
std::vector< DTVTunerType > GetTunerTypes(void) const
Definition: hdhrstreamhandler.h:62
DTVTunerType
Definition: dtvconfparserhelpers.h:77
DTVModulation::kModulationQAM256
@ kModulationQAM256
Definition: dtvconfparserhelpers.h:361
DTVModulation::kModulationQAM16
@ kModulationQAM16
Definition: dtvconfparserhelpers.h:357
format_dvbc
static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
Definition: hdhrchannel.cpp:133
mythlogging.h
HDHRStreamHandler::Return
static void Return(HDHRStreamHandler *&ref, int inputid)
Definition: hdhrstreamhandler.cpp:63
DTVTunerType::kTunerTypeUnknown
static const int kTunerTypeUnknown
Definition: dtvconfparserhelpers.h:103
DTVChannel::SetSIStandard
void SetSIStandard(const QString &si_std)
Sets PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:50
format_dvbt
static QString format_dvbt(const DTVMultiplex &tuning, const QString &mod)
Definition: hdhrchannel.cpp:122
HDHRChannel::SetChannelByString
bool SetChannelByString(const QString &channum) override
Definition: hdhrchannel.cpp:181
DTVModulation::kModulationQAM128
@ kModulationQAM128
Definition: dtvconfparserhelpers.h:360
HDHRStreamHandler::IsConnected
bool IsConnected(void) const
Definition: hdhrstreamhandler.cpp:502
HDHRChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: hdhrchannel.h:35
channelutil.h
DTVMultiplex::m_symbolRate
uint64_t m_symbolRate
Definition: dtvmultiplex.h:95
LOC
#define LOC
HDHRChannel Copyright (c) 2006-2009 by Silicondust Engineering Ltd.
Definition: hdhrchannel.cpp:31
DTVChannel::m_tunerType
DTVTunerType m_tunerType
Definition: dtvchannel.h:162
HDHRStreamHandler::TuneChannel
bool TuneChannel(const QString &chanid)
Definition: hdhrstreamhandler.cpp:507
DTVBandwidth::toChar
QChar toChar() const
Definition: dtvconfparserhelpers.h:267
HDHRChannel::IsMaster
bool IsMaster(void) const override
Returns true if this is the first of a number of multi-rec devs.
Definition: hdhrchannel.cpp:46
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
DTVMultiplex::m_sistandard
QString m_sistandard
Definition: dtvmultiplex.h:111
ChannelBase::GetInputID
virtual int GetInputID(void) const
Definition: channelbase.h:67
HDHRChannel::EnterPowerSavingMode
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: hdhrchannel.cpp:87
DTVModulation::kModulation8VSB
@ kModulation8VSB
Definition: dtvconfparserhelpers.h:363
DTVMultiplex::m_modulation
DTVModulation m_modulation
Definition: dtvmultiplex.h:100
DTVTunerType::kTunerTypeATSC
static const int kTunerTypeATSC
Definition: dtvconfparserhelpers.h:98
HDHRChannel::HDHRChannel
HDHRChannel(TVRec *parent, QString device)
Definition: hdhrchannel.cpp:33
get_tune_spec
static QString get_tune_spec(const DTVTunerType tunerType, const DTVMultiplex &tuning)
Definition: hdhrchannel.cpp:149
DTVChannel
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:34
HDHRStreamHandler::Get
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
Definition: hdhrstreamhandler.cpp:32
hdhrstreamhandler.h
DTVTunerType::kTunerTypeDVBT
static const int kTunerTypeDVBT
Definition: dtvconfparserhelpers.h:96
hdhrchannel.h
ChannelBase::GetMajorID
int GetMajorID(void)
Definition: channelbase.cpp:857
ChannelBase::InitializeInput
virtual bool InitializeInput(void)
Fills in input map from DB.
Definition: channelbase.cpp:547
format_modulation
static QString format_modulation(const DTVMultiplex &tuning)
Definition: hdhrchannel.cpp:104
DTVModulation::kModulationQAM64
@ kModulationQAM64
Definition: dtvconfparserhelpers.h:359
videosource.h
HDHRChannel::Tune
virtual bool Tune(const DTVMultiplex &tuning)=0
This performs the actual frequency tuning and in some cases input switching.
HDHRChannel::m_deviceId
QString m_deviceId
Definition: hdhrchannel.h:52