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
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
33HDHRChannel::HDHRChannel(TVRec *parent, QString device)
34 : DTVChannel(parent),
35 m_deviceId(std::move(device))
36{
38}
39
41{
44}
45
46bool 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
75}
76
78{
79 LOG(VB_CHANNEL, LOG_INFO, LOC + "Closing HDHR channel");
80
82 return; // this caller didn't have it open in the first place..
83
85}
86
88{
89 Close();
90 return true;
91}
92
93bool HDHRChannel::IsOpen(void) const
94{
95 return m_streamHandler;
96}
97
99bool HDHRChannel::Tune(const QString &freqid, int /*finetune*/)
100{
101 return m_streamHandler->TuneVChannel(freqid);
102}
103
104static 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
122static 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
132static 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
148static 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
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 {
177 return true;
178 }
179
180 return false;
181}
182
183bool 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}
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:77
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:87
bool Open(void) override
Opens the channel changing hardware for use.
Definition: hdhrchannel.cpp:54
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:46
bool SetChannelByString(const QString &channum) override
HDHRChannel(TVRec *parent, QString device)
Definition: hdhrchannel.cpp:33
HDHRStreamHandler * m_streamHandler
Definition: hdhrchannel.h:53
~HDHRChannel(void) override
Definition: hdhrchannel.cpp:40
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: hdhrchannel.cpp:93
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:143
#define LOC
HDHRChannel Copyright (c) 2006-2009 by Silicondust Engineering Ltd.
Definition: hdhrchannel.cpp:31
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.