MythTV  master
satiputils.cpp
Go to the documentation of this file.
1 // C++
2 #include <chrono>
3 #include <thread>
4 
5 // Qt
6 #include <QString>
7 #include <QStringList>
8 
9 // MythTV headers
10 #include "cardutil.h"
11 #include "mythlogging.h"
12 #include "mythtimer.h"
13 #include "satiputils.h"
14 #include "ssdp.h"
15 
16 #define LOC QString("SatIP: ")
17 
18 #define SEARCH_TIME_MS 3000
19 #define SATIP_URI "urn:ses-com:device:SatIPServer:1"
20 
21 QStringList SatIP::probeDevices(void)
22 {
23  const int milliSeconds = SEARCH_TIME_MS;
24 
25  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Using UPNP to search for Sat>IP servers (%1 secs)")
26  .arg(milliSeconds / 1000));
27 
28  SSDP::Instance()->PerformSearch(SATIP_URI, milliSeconds / 1000);
29 
30  MythTimer totalTime; totalTime.start();
31  MythTimer searchTime; searchTime.start();
32 
33  while (totalTime.elapsed() < milliSeconds)
34  {
35  std::this_thread::sleep_for(std::chrono::milliseconds(25));
36  int ttl = milliSeconds - totalTime.elapsed();
37  if (searchTime.elapsed() > 249 && ttl > 1000)
38  {
39  LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("UPNP search %1 ms").arg(ttl));
40  SSDP::Instance()->PerformSearch(SATIP_URI, ttl / 1000);
41  searchTime.start();
42  }
43  }
44 
45  return SatIP::doUPNPsearch();
46 };
47 
48 QStringList SatIP::doUPNPsearch(void)
49 {
50  QStringList result;
51 
52  SSDPCacheEntries *satipservers = SSDP::Find(SATIP_URI);
53 
54  if (!satipservers)
55  {
56  LOG(VB_GENERAL, LOG_INFO, LOC + "No UPnP Sat>IP servers found");
57  return QStringList();
58  }
59 
60  int count = satipservers->Count();
61  if (count)
62  {
63  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Found %1 possible Sat>IP servers").arg(count));
64  }
65  else
66  {
67  LOG(VB_GENERAL, LOG_ERR, LOC + "No UPnP Sat>IP servers found, but SSDP::Find() != NULL");
68  }
69 
70  EntryMap map;
71  satipservers->GetEntryMap(map);
72 
73  for (auto *BE : qAsConst(map))
74  {
75  QString friendlyName = BE->GetFriendlyName();
76  UPnpDeviceDesc *desc = BE->GetDeviceDesc();
77 
78  if (!desc)
79  {
80  LOG(VB_GENERAL, LOG_ERR, LOC + QString("GetDeviceDesc() failed for %1").arg(friendlyName));
81  continue;
82  }
83 
84  QString ip = desc->m_hostUrl.host();
85  QString id = desc->m_rootDevice.GetUDN();
86  QList<NameValue> extraAttribs = desc->m_rootDevice.m_lstExtra;
87 
88  for (const auto& attrib : extraAttribs)
89  {
90  if (attrib.m_sName == "satip:X_SATIPCAP")
91  {
92  QStringList caps = attrib.m_sValue.split(",");
93 
94  for (const auto& cap : caps)
95  {
96  QStringList tuner = cap.split("-");
97 
98  if (tuner.size() != 2)
99  continue;
100 
101  int num_tuners = tuner.at(1).toInt();
102  for (int i = 0; i < num_tuners; i++)
103  {
104  QString device = QString("%1 %2 %3 %4 %5")
105  .arg(id)
106  .arg(friendlyName.replace(" ", ""))
107  .arg(ip)
108  .arg(i)
109  .arg(tuner.at(0));
110  result << device;
111  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Found %1").arg(device));
112  }
113  }
114  }
115  }
116  BE->DecrRef();
117  }
118 
119  satipservers->DecrRef();
120  satipservers = nullptr;
121 
122  return result;
123 };
124 
125 QString SatIP::findDeviceIP(const QString& deviceuuid)
126 {
127  QStringList devs = SatIP::probeDevices();
128 
129  for (const auto& dev : devs)
130  {
131  QStringList devinfo = dev.split(" ");
132  const QString& id = devinfo.at(0);
133 
134  if (id.toUpper() == deviceuuid.toUpper())
135  {
136  return devinfo.at(2);
137  }
138  }
139  return nullptr;
140 }
141 
143 {
144  QStringList dev = deviceid.split(":");
145  if (dev.length() < 3)
146  {
148  }
149 
150  QString type = dev.at(2).toUpper();
151  if (type == "DVBC")
152  {
153  return CardUtil::DVBC;
154  }
155  if (type == "DVBC2")
156  {
157  return CardUtil::DVBC; // DVB-C2 is not supported yet.
158  }
159  if (type == "DVBT")
160  {
161  return CardUtil::DVBT;
162  }
163  if (type == "DVBT2")
164  {
165  return CardUtil::DVBT2;
166  }
167  if (type == "DVBS2")
168  {
169  return CardUtil::DVBS2;
170  }
172 }
173 
174 int SatIP::toTunerType(const QString& deviceid)
175 {
176  QStringList devinfo = deviceid.split(":");
177  if (devinfo.length() < 3)
178  {
180  }
181 
182  QString type = devinfo.at(2).toUpper();
183 
184  if (type.startsWith("DVBC")) // DVB-C2 is not supported yet.
185  {
187  }
188  if (type == "DVBT")
189  {
191  }
192  if (type == "DVBT2")
193  {
195  }
196  if (type == "DVBS")
197  {
199  }
200  if (type == "DVBS2")
201  {
203  }
204 
206 }
207 
209 {
211  {
212  return "5";
213  }
215  {
216  return "6";
217  }
219  {
220  return "7";
221  }
223  {
224  return "8";
225  }
227  {
228  return "10";
229  }
231  {
232  return "1.712";
233  }
235  {
236  return "auto";
237  }
238  return "auto";
239 }
240 
241 QString SatIP::freq(uint64_t freq)
242 {
243  return QString::number(freq / 1000000.0, 'f', 2);
244 }
245 
247 {
249  {
250  return "dvbs";
251  }
253  {
254  return "dvbs2";
255  }
257  {
258  return "dvbt";
259  }
261  {
262  return "dvbt2";
263  }
265  {
266  return "dvbc";
267  }
268  // Not supported yet: DVB-C2
269  return "auto";
270 }
271 
273 {
275  {
276  return "qpsk";
277  }
279  {
280  return "8psk";
281  }
283  {
284  return "16qam";
285  }
287  {
288  return "32qam";
289  }
291  {
292  return "64qam";
293  }
295  {
296  return "128qam";
297  }
299  {
300  return "256qam";
301  }
302  return "auto";
303 }
304 
306 {
308  {
309  return "2k";
310  }
312  {
313  return "4k";
314  }
316  {
317  return "8k";
318  }
320  {
321  return "1k";
322  }
324  {
325  return "16k";
326  }
328  {
329  return "32k";
330  }
331  return "auto";
332 }
333 
335 {
337  {
338  return "14";
339  }
341  {
342  return "18";
343  }
345  {
346  return "116";
347  }
349  {
350  return "132";
351  }
353  {
354  return "1128";
355  }
357  {
358  return "19128";
359  }
361  {
362  return "19256";
363  }
364  return "auto";
365 }
366 
368 {
369  if (fec == DTVCodeRate::kFEC_1_2)
370  {
371  return "12";
372  }
373  if (fec == DTVCodeRate::kFEC_2_3)
374  {
375  return "23";
376  }
377  if (fec == DTVCodeRate::kFEC_3_4)
378  {
379  return "34";
380  }
381  if (fec == DTVCodeRate::kFEC_3_5)
382  {
383  return "35";
384  }
385  if (fec == DTVCodeRate::kFEC_4_5)
386  {
387  return "45";
388  }
389  if (fec == DTVCodeRate::kFEC_5_6)
390  {
391  return "56";
392  }
393  if (fec == DTVCodeRate::kFEC_6_7)
394  {
395  return "67";
396  }
397  if (fec == DTVCodeRate::kFEC_7_8)
398  {
399  return "78";
400  }
401  if (fec == DTVCodeRate::kFEC_8_9)
402  {
403  return "89";
404  }
406  {
407  return "910";
408  }
409  return "auto";
410 }
411 
413 {
415  {
416  return "0.35";
417  }
419  {
420  return "0.20";
421  }
423  {
424  return "0.25";
425  }
427  {
428  return "auto";
429  }
430  return "auto";
431 }
432 
434 {
436  {
437  return "v";
438  }
440  {
441  return "h";
442  }
444  {
445  return "r";
446  }
448  {
449  return "l";
450  }
451  return "auto";
452 }
DTVBandwidth::kBandwidth6MHz
@ kBandwidth6MHz
Definition: dtvconfparserhelpers.h:228
DTVGuardInterval::kGuardInterval_1_4
@ kGuardInterval_1_4
Definition: dtvconfparserhelpers.h:499
DTVBandwidth
Definition: dtvconfparserhelpers.h:216
DTVCodeRate::kFEC_3_4
@ kFEC_3_4
Definition: dtvconfparserhelpers.h:292
DTVTunerType::kTunerTypeDVBC
static const int kTunerTypeDVBC
Definition: dtvconfparserhelpers.h:95
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
DTVTransmitMode::kTransmissionMode32K
@ kTransmissionMode32K
Definition: dtvconfparserhelpers.h:439
DTVTransmitMode::kTransmissionMode1K
@ kTransmissionMode1K
Definition: dtvconfparserhelpers.h:437
DTVModulationSystem::kModulationSystem_DVBS2
@ kModulationSystem_DVBS2
Definition: dtvconfparserhelpers.h:660
DTVCodeRate::kFEC_2_3
@ kFEC_2_3
Definition: dtvconfparserhelpers.h:291
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:14
SatIP::ro
static QString ro(DTVRollOff ro)
Definition: satiputils.cpp:412
CardUtil::ERROR_UNKNOWN
@ ERROR_UNKNOWN
Definition: cardutil.h:48
CardUtil::DVBT2
@ DVBT2
Definition: cardutil.h:67
SATIP_URI
#define SATIP_URI
Definition: satiputils.cpp:19
ssdp.h
DTVCodeRate::kFEC_5_6
@ kFEC_5_6
Definition: dtvconfparserhelpers.h:294
DTVTunerType::kTunerTypeDVBS1
static const int kTunerTypeDVBS1
Definition: dtvconfparserhelpers.h:93
SEARCH_TIME_MS
#define SEARCH_TIME_MS
Definition: satiputils.cpp:18
freq
static const std::array< const uint32_t, 4 > freq
Definition: element.cpp:45
DTVTransmitMode::kTransmissionMode4K
@ kTransmissionMode4K
Definition: dtvconfparserhelpers.h:436
SatIP::bw
static QString bw(DTVBandwidth bw)
Definition: satiputils.cpp:208
UPnpDeviceDesc
Definition: upnpdevice.h:149
arg
arg(title).arg(filename).arg(doDelete))
SSDP::Find
static SSDPCacheEntries * Find(const QString &sURI)
Definition: ssdp.h:126
DTVPolarity::kPolarityLeft
@ kPolarityLeft
Definition: dtvconfparserhelpers.h:615
MythTimer::start
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DTVRollOff::kRollOff_35
@ kRollOff_35
Definition: dtvconfparserhelpers.h:734
SatIP::tmode
static QString tmode(DTVTransmitMode tmode)
Definition: satiputils.cpp:305
SSDPCacheEntries::GetEntryMap
void GetEntryMap(EntryMap &map)
Returns a copy of the EntryMap.
Definition: ssdpcache.cpp:92
SatIP::doUPNPsearch
static QStringList doUPNPsearch(void)
Definition: satiputils.cpp:48
DTVModulation::kModulationQPSK
@ kModulationQPSK
Definition: dtvconfparserhelpers.h:356
DTVGuardInterval
Definition: dtvconfparserhelpers.h:486
SatIP::findDeviceIP
static QString findDeviceIP(const QString &deviceuuid)
Definition: satiputils.cpp:125
DTVCodeRate
Definition: dtvconfparserhelpers.h:279
satiputils.h
DTVModulation::kModulationQAM256
@ kModulationQAM256
Definition: dtvconfparserhelpers.h:361
SSDP::Instance
static SSDP * Instance()
Definition: ssdp.cpp:53
DTVGuardInterval::kGuardInterval_1_16
@ kGuardInterval_1_16
Definition: dtvconfparserhelpers.h:497
UPnpDeviceDesc::m_rootDevice
UPnpDevice m_rootDevice
Definition: upnpdevice.h:152
DTVModulation::kModulationQAM16
@ kModulationQAM16
Definition: dtvconfparserhelpers.h:357
CardUtil::DVBS2
@ DVBS2
Definition: cardutil.h:60
DTVCodeRate::kFEC_1_2
@ kFEC_1_2
Definition: dtvconfparserhelpers.h:290
mythlogging.h
SatIP::probeDevices
static QStringList probeDevices(void)
Definition: satiputils.cpp:21
DTVPolarity::kPolarityVertical
@ kPolarityVertical
Definition: dtvconfparserhelpers.h:612
UPnpDevice::m_lstExtra
NameValues m_lstExtra
Definition: upnpdevice.h:116
DTVTunerType::kTunerTypeUnknown
static const int kTunerTypeUnknown
Definition: dtvconfparserhelpers.h:103
LOC
#define LOC
Definition: satiputils.cpp:16
SatIP::toTunerType
static int toTunerType(const QString &deviceid)
Definition: satiputils.cpp:174
DTVCodeRate::kFEC_3_5
@ kFEC_3_5
Definition: dtvconfparserhelpers.h:299
DTVTransmitMode
Definition: dtvconfparserhelpers.h:423
DTVGuardInterval::kGuardInterval_19_256
@ kGuardInterval_19_256
Definition: dtvconfparserhelpers.h:503
DTVModulation::kModulationQAM128
@ kModulationQAM128
Definition: dtvconfparserhelpers.h:360
EntryMap
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
Definition: ssdpcache.h:28
SatIP::toDVBInputType
static CardUtil::INPUT_TYPES toDVBInputType(const QString &deviceid)
Definition: satiputils.cpp:142
DTVModulation::kModulationQAM32
@ kModulationQAM32
Definition: dtvconfparserhelpers.h:358
UPnpDeviceDesc::m_hostUrl
QUrl m_hostUrl
Definition: upnpdevice.h:154
SatIP::freq
static QString freq(uint64_t freq)
Definition: satiputils.cpp:241
SatIP::gi
static QString gi(DTVGuardInterval gi)
Definition: satiputils.cpp:334
SSDPCacheEntries
Definition: ssdpcache.h:35
SatIP::pol
static QString pol(DTVPolarity pol)
Definition: satiputils.cpp:433
DTVTransmitMode::kTransmissionMode16K
@ kTransmissionMode16K
Definition: dtvconfparserhelpers.h:438
CardUtil::DVBC
@ DVBC
Definition: cardutil.h:51
DTVBandwidth::kBandwidthAuto
@ kBandwidthAuto
Definition: dtvconfparserhelpers.h:229
DTVBandwidth::kBandwidth5MHz
@ kBandwidth5MHz
Definition: dtvconfparserhelpers.h:230
DTVRollOff::kRollOff_Auto
@ kRollOff_Auto
Definition: dtvconfparserhelpers.h:737
DTVTunerType::kTunerTypeDVBS2
static const int kTunerTypeDVBS2
Definition: dtvconfparserhelpers.h:94
MythTimer::elapsed
int elapsed(void)
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:90
DTVRollOff::kRollOff_20
@ kRollOff_20
Definition: dtvconfparserhelpers.h:735
DTVModulationSystem
Definition: dtvconfparserhelpers.h:643
cardutil.h
DTVTransmitMode::kTransmissionMode8K
@ kTransmissionMode8K
Definition: dtvconfparserhelpers.h:434
DTVPolarity::kPolarityRight
@ kPolarityRight
Definition: dtvconfparserhelpers.h:614
DTVBandwidth::kBandwidth1712kHz
@ kBandwidth1712kHz
Definition: dtvconfparserhelpers.h:232
DTVTransmitMode::kTransmissionMode2K
@ kTransmissionMode2K
Definition: dtvconfparserhelpers.h:433
SSDP::PerformSearch
void PerformSearch(const QString &sST, uint timeout_secs=2)
Definition: ssdp.cpp:200
DTVRollOff::kRollOff_25
@ kRollOff_25
Definition: dtvconfparserhelpers.h:736
SatIP::fec
static QString fec(DTVCodeRate fec)
Definition: satiputils.cpp:367
mythtimer.h
DTVGuardInterval::kGuardInterval_1_32
@ kGuardInterval_1_32
Definition: dtvconfparserhelpers.h:496
DTVBandwidth::kBandwidth8MHz
@ kBandwidth8MHz
Definition: dtvconfparserhelpers.h:226
DTVCodeRate::kFEC_7_8
@ kFEC_7_8
Definition: dtvconfparserhelpers.h:296
DTVModulationSystem::kModulationSystem_DVBT2
@ kModulationSystem_DVBT2
Definition: dtvconfparserhelpers.h:670
DTVTunerType::kTunerTypeDVBT
static const int kTunerTypeDVBT
Definition: dtvconfparserhelpers.h:96
DTVPolarity::kPolarityHorizontal
@ kPolarityHorizontal
Definition: dtvconfparserhelpers.h:613
DTVCodeRate::kFEC_9_10
@ kFEC_9_10
Definition: dtvconfparserhelpers.h:300
UPnpDevice::GetUDN
QString GetUDN(void) const
Definition: upnpdevice.cpp:766
SSDPCacheEntries::Count
uint Count(void) const
Definition: ssdpcache.h:44
SatIP::msys
static QString msys(DTVModulationSystem msys)
Definition: satiputils.cpp:246
DTVTunerType::kTunerTypeDVBT2
static const int kTunerTypeDVBT2
Definition: dtvconfparserhelpers.h:97
DTVCodeRate::kFEC_8_9
@ kFEC_8_9
Definition: dtvconfparserhelpers.h:297
SatIP::mtype
static QString mtype(DTVModulation mtype)
Definition: satiputils.cpp:272
DTVModulation::kModulationQAM64
@ kModulationQAM64
Definition: dtvconfparserhelpers.h:359
DTVBandwidth::kBandwidth10MHz
@ kBandwidth10MHz
Definition: dtvconfparserhelpers.h:231
DTVCodeRate::kFEC_6_7
@ kFEC_6_7
Definition: dtvconfparserhelpers.h:295
DTVBandwidth::kBandwidth7MHz
@ kBandwidth7MHz
Definition: dtvconfparserhelpers.h:227
DTVModulationSystem::kModulationSystem_DVBS
@ kModulationSystem_DVBS
Definition: dtvconfparserhelpers.h:659
DTVGuardInterval::kGuardInterval_1_8
@ kGuardInterval_1_8
Definition: dtvconfparserhelpers.h:498
DTVModulationSystem::kModulationSystem_DVBT
@ kModulationSystem_DVBT
Definition: dtvconfparserhelpers.h:657
DTVModulation::kModulation8PSK
@ kModulation8PSK
Definition: dtvconfparserhelpers.h:365
CardUtil::DVBT
@ DVBT
Definition: cardutil.h:52
DTVPolarity
Definition: dtvconfparserhelpers.h:604
DTVModulation
Definition: dtvconfparserhelpers.h:346
DTVGuardInterval::kGuardInterval_19_128
@ kGuardInterval_19_128
Definition: dtvconfparserhelpers.h:502
DTVModulationSystem::kModulationSystem_DVBC_ANNEX_A
@ kModulationSystem_DVBC_ANNEX_A
Definition: dtvconfparserhelpers.h:655
DTVCodeRate::kFEC_4_5
@ kFEC_4_5
Definition: dtvconfparserhelpers.h:293
CardUtil::INPUT_TYPES
INPUT_TYPES
all the different inputs
Definition: cardutil.h:46
DTVGuardInterval::kGuardInterval_1_128
@ kGuardInterval_1_128
Definition: dtvconfparserhelpers.h:501
DTVRollOff
Definition: dtvconfparserhelpers.h:724