MythTV master
hdhrchannel.cpp
Go to the documentation of this file.
1
7#include <QtGlobal>
8#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
9#include <QtSystemDetection>
10#endif
11
12// C includes
13#include <unistd.h>
14#include <sys/types.h>
15#ifndef Q_OS_WINDOWS
16#include <sys/socket.h>
17#include <netinet/in.h>
18#include <arpa/inet.h>
19#include <netdb.h>
20#endif
21#include <sys/time.h>
22#include <fcntl.h>
23
24// C++ includes
25#include <algorithm>
26#include <utility>
27
28// MythTV includes
31#include "hdhrchannel.h"
32#include "videosource.h"
33#include "channelutil.h"
34#include "hdhrstreamhandler.h"
35
36#define LOC QString("HDHRChan[%1](%2): ").arg(m_inputId).arg(HDHRChannel::GetDevice())
37
38HDHRChannel::HDHRChannel(TVRec *parent, QString device)
39 : DTVChannel(parent),
40 m_deviceId(std::move(device))
41{
43}
44
46{
49}
50
51bool HDHRChannel::IsMaster(void) const
52{
54 bool is_master = (master == this);
56 return is_master;
57}
58
60{
61 LOG(VB_CHANNEL, LOG_INFO, LOC + "Opening HDHR channel");
62
63 if (IsOpen())
64 return true;
65
67 GetMajorID());
68
70 m_tunerType = (m_tunerTypes.empty()) ?
72
73 if (!InitializeInput())
74 {
75 Close();
76 return false;
77 }
78
80}
81
83{
84 LOG(VB_CHANNEL, LOG_INFO, LOC + "Closing HDHR channel");
85
87 return; // this caller didn't have it open in the first place..
88
90}
91
93{
94 Close();
95 return true;
96}
97
98bool HDHRChannel::IsOpen(void) const
99{
100 return m_streamHandler;
101}
102
104bool HDHRChannel::Tune(const QString &freqid, int /*finetune*/)
105{
106 return m_streamHandler->TuneVChannel(freqid);
107}
108
109static QString format_modulation(const DTVMultiplex &tuning)
110{
112 return "qam256";
114 return "qam128";
116 return "qam64";
118 return "qam16";
120 return "qpsk";
122 return "8vsb";
123
124 return "auto";
125}
126
127static QString format_dvbt(const DTVMultiplex &tuning)
128{
129 const QChar b = tuning.m_bandwidth.toChar();
130 if ((QChar('8') == b) || (QChar('7') == b) || (QChar('6') == b))
131 {
132 return QString("auto%1t").arg(b);
133 }
134 return "auto";
135}
136
137static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
138{
139 const QChar b = tuning.m_bandwidth.toChar();
140
141 // need bandwidth to set modulation and symbol rate
142 if ((QChar('a') == b) && (mod != "auto") && (tuning.m_symbolRate > 0))
143 return QString("a8%1-%2")
144 .arg(mod).arg(tuning.m_symbolRate/1000);
145 if ((QChar('a') == b) || (mod == "auto"))
146 return "auto"; // uses bandwidth from channel map
147 if ((QChar('a') != b) && (tuning.m_symbolRate > 0))
148 return QString("a%1%2-%3")
149 .arg(b).arg(mod).arg(tuning.m_symbolRate/1000);
150 return QString("auto%1c").arg(b);
151}
152
153static QString get_tune_spec(
154 const DTVTunerType tunerType, const DTVMultiplex &tuning)
155{
156 const QString mod = format_modulation(tuning);
157
158 if (DTVTunerType::kTunerTypeATSC == tunerType)
159 // old atsc firmware does no recognize "auto"
160 return (mod == "auto") ? "qam" : mod;
161 if (DTVTunerType::kTunerTypeDVBC == tunerType)
162 return format_dvbc(tuning, mod);
163 if ((DTVTunerType::kTunerTypeDVBT == tunerType) ||
164 (DTVTunerType::kTunerTypeDVBT2 == tunerType))
165 {
166 return format_dvbt(tuning);
167 }
168
169 return "auto";
170}
171
173{
174 QString spec = get_tune_spec(m_tunerType, tuning);
175 QString chan = QString("%1:%2").arg(spec).arg(tuning.m_frequency);
176
177 LOG(VB_CHANNEL, LOG_INFO, LOC + "Tuning to " + chan);
178
179 if (m_streamHandler->TuneChannel(chan))
180 {
182 return true;
183 }
184
185 return false;
186}
187
188bool HDHRChannel::SetChannelByString(const QString &channum)
189{
190 bool ok = DTVChannel::SetChannelByString(channum);
191
192 // HACK HACK HACK -- BEGIN
193 // if the DTVTunerType were specified in tuning we wouldn't
194 // need to try alternative tuning...
196 {
197 bool has_dvbc = false;
198 bool has_dvbt = false;
199 for (const auto& type : m_tunerTypes)
200 {
201 has_dvbt |= (DTVTunerType::kTunerTypeDVBT == type);
202 has_dvbc |= (DTVTunerType::kTunerTypeDVBC == type);
203 }
204
205 if (has_dvbt && has_dvbc)
206 {
208 ok = DTVChannel::SetChannelByString(channum);
209 if (!ok)
210 {
212 return false;
213 }
214 }
215 }
216 // HACK HACK HACK -- END
217
218 return ok;
219}
virtual int GetInputID(void) const
Definition: channelbase.h:67
virtual bool InitializeInput(void)
Fills in input map from DB.
int GetMajorID(void)
QChar toChar() const
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:34
static void ReturnMasterLock(DTVChannelP &chan)
Definition: dtvchannel.cpp:148
void DeregisterForMaster(const QString &key)
Definition: dtvchannel.cpp:121
DTVTunerType m_tunerType
Definition: dtvchannel.h:161
bool SetChannelByString(const QString &chan) override
Definition: dtvchannel.cpp:157
void SetSIStandard(const QString &si_std)
Sets PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:51
static DTVChannel * GetMasterLock(const QString &key)
Definition: dtvchannel.cpp:136
void RegisterForMaster(const QString &key)
Definition: dtvchannel.cpp:114
uint64_t m_symbolRate
Definition: dtvmultiplex.h:95
DTVModulation m_modulation
Definition: dtvmultiplex.h:100
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
uint64_t m_frequency
Definition: dtvmultiplex.h:94
QString m_sistandard
Definition: dtvmultiplex.h:111
static const int kTunerTypeDVBT
static const int kTunerTypeUnknown
static const int kTunerTypeDVBC
static const int kTunerTypeDVBT2
static const int kTunerTypeATSC
void Close(void) override
Closes the channel changing hardware to use.
Definition: hdhrchannel.cpp:82
QString m_deviceId
Definition: hdhrchannel.h:52
bool Tune(const DTVMultiplex &tuning) override
This performs the actual frequency tuning and in some cases input switching.
std::vector< DTVTunerType > m_tunerTypes
Definition: hdhrchannel.h:54
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: hdhrchannel.cpp:92
bool Open(void) override
Opens the channel changing hardware for use.
Definition: hdhrchannel.cpp:59
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: hdhrchannel.h:35
bool IsMaster(void) const override
Returns true if this is the first of a number of multi-rec devs.
Definition: hdhrchannel.cpp:51
bool SetChannelByString(const QString &channum) override
HDHRChannel(TVRec *parent, QString device)
Definition: hdhrchannel.cpp:38
HDHRStreamHandler * m_streamHandler
Definition: hdhrchannel.h:53
~HDHRChannel(void) override
Definition: hdhrchannel.cpp:45
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: hdhrchannel.cpp:98
bool TuneVChannel(const QString &vchn)
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
std::vector< DTVTunerType > GetTunerTypes(void) const
bool TuneChannel(const QString &chanid)
bool IsConnected(void) const
static void Return(HDHRStreamHandler *&ref, int inputid)
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
#define LOC
HDHRChannel Copyright (c) 2006-2009 by Silicondust Engineering Ltd.
Definition: hdhrchannel.cpp:36
static QString format_dvbt(const DTVMultiplex &tuning)
static QString get_tune_spec(const DTVTunerType tunerType, const DTVMultiplex &tuning)
static QString format_dvbc(const DTVMultiplex &tuning, const QString &mod)
static QString format_modulation(const DTVMultiplex &tuning)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
STL namespace.