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 "libmythbase/mythdbcon.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)
123 {
124  const QChar b = tuning.m_bandwidth.toChar();
125  if ((QChar('8') == b) || (QChar('7') == b) || (QChar('6') == b))
126  {
127  return QString("auto%1t").arg(b);
128  }
129  return "auto";
130 }
131 
132 static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
133 {
134  const QChar b = tuning.m_bandwidth.toChar();
135 
136  // need bandwidth to set modulation and symbol rate
137  if ((QChar('a') == b) && (mod != "auto") && (tuning.m_symbolRate > 0))
138  return QString("a8%1-%2")
139  .arg(mod).arg(tuning.m_symbolRate/1000);
140  if ((QChar('a') == b) || (mod == "auto"))
141  return "auto"; // uses bandwidth from channel map
142  if ((QChar('a') != b) && (tuning.m_symbolRate > 0))
143  return QString("a%1%2-%3")
144  .arg(b).arg(mod).arg(tuning.m_symbolRate/1000);
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  if (DTVTunerType::kTunerTypeDVBC == tunerType)
157  return format_dvbc(tuning, mod);
158  if ((DTVTunerType::kTunerTypeDVBT == tunerType) ||
159  (DTVTunerType::kTunerTypeDVBT2 == tunerType))
160  {
161  return format_dvbt(tuning);
162  }
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 (const 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 }
DTVMultiplex::m_frequency
uint64_t m_frequency
Definition: dtvmultiplex.h:94
DTVMultiplex
Definition: dtvmultiplex.h:24
HDHRChannel::m_tunerTypes
std::vector< DTVTunerType > m_tunerTypes
Definition: hdhrchannel.h:54
DTVChannel::RegisterForMaster
void RegisterForMaster(const QString &key)
Definition: dtvchannel.cpp:114
DTVChannel::ReturnMasterLock
static void ReturnMasterLock(DTVChannelP &chan)
Definition: dtvchannel.cpp:148
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
HDHRChannel::Tune
bool Tune(const DTVMultiplex &tuning) override
This performs the actual frequency tuning and in some cases input switching.
Definition: hdhrchannel.cpp:167
DTVChannel::SetChannelByString
bool SetChannelByString(const QString &chan) override
Definition: dtvchannel.cpp:157
DTVChannel::DeregisterForMaster
void DeregisterForMaster(const QString &key)
Definition: dtvchannel.cpp:121
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
DTVChannel::GetMasterLock
static DTVChannel * GetMasterLock(const QString &key)
Definition: dtvchannel.cpp:136
DTVMultiplex::m_bandwidth
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
HDHRStreamHandler::TuneVChannel
bool TuneVChannel(const QString &vchn)
Definition: hdhrstreamhandler.cpp:542
HDHRChannel::m_streamHandler
HDHRStreamHandler * m_streamHandler
Definition: hdhrchannel.h:53
DTVModulation::kModulationDQPSK
@ kModulationDQPSK
Definition: dtvconfparserhelpers.h:370
HDHRStreamHandler::GetTunerTypes
std::vector< DTVTunerType > GetTunerTypes(void) const
Definition: hdhrstreamhandler.h:64
DTVTunerType
Definition: dtvconfparserhelpers.h:76
DTVModulation::kModulationQAM256
@ kModulationQAM256
Definition: dtvconfparserhelpers.h:363
DTVModulation::kModulationQAM16
@ kModulationQAM16
Definition: dtvconfparserhelpers.h:359
format_dvbc
static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
Definition: hdhrchannel.cpp:132
mythlogging.h
HDHRStreamHandler::Return
static void Return(HDHRStreamHandler *&ref, int inputid)
Definition: hdhrstreamhandler.cpp:60
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:51
format_dvbt
static QString format_dvbt(const DTVMultiplex &tuning)
Definition: hdhrchannel.cpp:122
HDHRChannel::SetChannelByString
bool SetChannelByString(const QString &channum) override
Definition: hdhrchannel.cpp:183
DTVModulation::kModulationQAM128
@ kModulationQAM128
Definition: dtvconfparserhelpers.h:362
HDHRStreamHandler::IsConnected
bool IsConnected(void) const
Definition: hdhrstreamhandler.cpp:503
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:161
HDHRStreamHandler::TuneChannel
bool TuneChannel(const QString &chanid)
Definition: hdhrstreamhandler.cpp:508
DTVBandwidth::toChar
QChar toChar() const
Definition: dtvconfparserhelpers.h:269
std
Definition: mythchrono.h:23
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:142
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:365
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:148
DTVChannel
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:33
HDHRStreamHandler::Get
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
Definition: hdhrstreamhandler.cpp:29
hdhrstreamhandler.h
DTVTunerType::kTunerTypeDVBT
static const int kTunerTypeDVBT
Definition: dtvconfparserhelpers.h:96
hdhrchannel.h
ChannelBase::GetMajorID
int GetMajorID(void)
Definition: channelbase.cpp:852
DTVTunerType::kTunerTypeDVBT2
static const int kTunerTypeDVBT2
Definition: dtvconfparserhelpers.h:97
ChannelBase::InitializeInput
virtual bool InitializeInput(void)
Fills in input map from DB.
Definition: channelbase.cpp:548
format_modulation
static QString format_modulation(const DTVMultiplex &tuning)
Definition: hdhrchannel.cpp:104
DTVModulation::kModulationQAM64
@ kModulationQAM64
Definition: dtvconfparserhelpers.h:361
videosource.h
HDHRChannel::m_deviceId
QString m_deviceId
Definition: hdhrchannel.h:52